• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kdatewidget.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2001 Waldo Bastian (bastian@kde.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19
20#include <tqpopupmenu.h>
21#include <tqcombobox.h>
22#include <tqlayout.h>
23#include <tqlineedit.h>
24
25#include "knuminput.h"
26#include "tdeglobal.h"
27#include "tdelocale.h"
28#include "kcalendarsystem.h"
29//#include "kdatepicker.h"
30#include "kdialog.h"
31
32#include "kdatewidget.h"
33
34class KDateWidgetSpinBox : public TQSpinBox
35{
36public:
37 KDateWidgetSpinBox(int min, int max, TQWidget *parent)
38 : TQSpinBox(min, max, 1, parent)
39 {
40 editor()->setAlignment(TQt::AlignRight);
41 }
42};
43
44class KDateWidget::KDateWidgetPrivate
45{
46public:
47 KDateWidgetSpinBox *m_day;
48 TQComboBox *m_month;
49 KDateWidgetSpinBox *m_year;
50 TQDate m_dat;
51};
52
53
54KDateWidget::KDateWidget( TQWidget *parent, const char *name )
55 : TQWidget( parent, name )
56{
57 init(TQDate());
58 setDate(TQDate());
59}
60
61// ### HPB change TQDate to const TQDate & in KDE 4.0
62KDateWidget::KDateWidget( TQDate date, TQWidget *parent,
63 const char *name )
64 : TQWidget( parent, name )
65{
66 init(date);
67 setDate(date);
68}
69
70// ### CFM Repaced by init(const TQDate&). Can be safely removed
71// when no risk of BIC
72void KDateWidget::init()
73{
74 d = new KDateWidgetPrivate;
75 TDELocale *locale = TDEGlobal::locale();
76 TQHBoxLayout *layout = new TQHBoxLayout(this, 0, KDialog::spacingHint());
77 layout->setAutoAdd(true);
78 d->m_day = new KDateWidgetSpinBox(1, 1, this);
79 d->m_month = new TQComboBox(false, this);
80 for (int i = 1; ; ++i)
81 {
82 TQString str = locale->calendar()->monthName(i,
83 locale->calendar()->year(TQDate()));
84 if (str.isNull()) break;
85 d->m_month->insertItem(str);
86 }
87
88 d->m_year = new KDateWidgetSpinBox(locale->calendar()->minValidYear(),
89 locale->calendar()->maxValidYear(), this);
90
91 connect(d->m_day, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(slotDateChanged()));
92 connect(d->m_month, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotDateChanged()));
93 connect(d->m_year, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(slotDateChanged()));
94}
95
96void KDateWidget::init(const TQDate& date)
97{
98 d = new KDateWidgetPrivate;
99 TDELocale *locale = TDEGlobal::locale();
100 TQHBoxLayout *layout = new TQHBoxLayout(this, 0, KDialog::spacingHint());
101 layout->setAutoAdd(true);
102 d->m_day = new KDateWidgetSpinBox(1, 1, this);
103 d->m_month = new TQComboBox(false, this);
104 for (int i = 1; ; ++i)
105 {
106 TQString str = locale->calendar()->monthName(i,
107 locale->calendar()->year(date));
108 if (str.isNull()) break;
109 d->m_month->insertItem(str);
110 }
111
112 d->m_year = new KDateWidgetSpinBox(locale->calendar()->minValidYear(),
113 locale->calendar()->maxValidYear(), this);
114
115 connect(d->m_day, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(slotDateChanged()));
116 connect(d->m_month, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotDateChanged()));
117 connect(d->m_year, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(slotDateChanged()));
118}
119
120KDateWidget::~KDateWidget()
121{
122 delete d;
123}
124
125// ### HPB change TQDate to const TQDate & in KDE 4.0
126void KDateWidget::setDate( TQDate date )
127{
128 const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
129
130 d->m_day->blockSignals(true);
131 d->m_month->blockSignals(true);
132 d->m_year->blockSignals(true);
133
134 d->m_day->setMaxValue(calendar->daysInMonth(date));
135 d->m_day->setValue(calendar->day(date));
136 d->m_month->setCurrentItem(calendar->month(date)-1);
137 d->m_year->setValue(calendar->year(date));
138
139 d->m_day->blockSignals(false);
140 d->m_month->blockSignals(false);
141 d->m_year->blockSignals(false);
142
143 d->m_dat = date;
144 emit changed(d->m_dat);
145}
146
147TQDate KDateWidget::date() const
148{
149 return d->m_dat;
150}
151
152void KDateWidget::slotDateChanged( )
153{
154 const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
155
156 TQDate date;
157 int y,m,day;
158
159 y = d->m_year->value();
160 y = TQMIN(TQMAX(y, calendar->minValidYear()), calendar->maxValidYear());
161
162 calendar->setYMD(date, y, 1, 1);
163 m = d->m_month->currentItem()+1;
164 m = TQMIN(TQMAX(m,1), calendar->monthsInYear(date));
165
166 calendar->setYMD(date, y, m, 1);
167 day = d->m_day->value();
168 day = TQMIN(TQMAX(day,1), calendar->daysInMonth(date));
169
170 calendar->setYMD(date, y, m, day);
171 setDate(date);
172}
173
174void KDateWidget::virtual_hook( int, void* )
175{ /*BASE::virtual_hook( id, data );*/ }
176
177#include "kdatewidget.moc"
KCalendarSystem
KCalendarSystem::maxValidYear
virtual int maxValidYear() const=0
KCalendarSystem::monthsInYear
virtual int monthsInYear(const TQDate &date) const=0
KCalendarSystem::daysInMonth
virtual int daysInMonth(const TQDate &date) const=0
KCalendarSystem::day
virtual int day(const TQDate &date) const=0
KCalendarSystem::month
virtual int month(const TQDate &date) const=0
KCalendarSystem::minValidYear
virtual int minValidYear() const=0
KCalendarSystem::monthName
virtual TQString monthName(int month, int year, bool shortName=false) const=0
KCalendarSystem::setYMD
virtual bool setYMD(TQDate &date, int y, int m, int d) const=0
KCalendarSystem::year
virtual int year(const TQDate &date) const=0
KDateWidget::setDate
void setDate(TQDate date)
Changes the selected date to date.
Definition: kdatewidget.cpp:126
KDateWidget::date
TQDate date() const
Returns the currently selected date.
Definition: kdatewidget.cpp:147
KDateWidget::changed
void changed(TQDate)
Emitted whenever the date of the widget is changed, either with setDate() or via user selection.
KDateWidget::KDateWidget
KDateWidget(TQWidget *parent=0, const char *name=0)
Constructs a date selection widget.
Definition: kdatewidget.cpp:54
KDateWidget::~KDateWidget
virtual ~KDateWidget()
Destructs the date selection widget.
Definition: kdatewidget.cpp:120
KDialog::spacingHint
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
Definition: kdialog.cpp:110
TDEGlobal::locale
static TDELocale * locale()
TDELocale
TDELocale::calendar
const KCalendarSystem * calendar() const
tdelocale.h

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.