summaryrefslogtreecommitdiffabout
path: root/microkde/kdatepickernew.cpp
Unidiff
Diffstat (limited to 'microkde/kdatepickernew.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatepickernew.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/microkde/kdatepickernew.cpp b/microkde/kdatepickernew.cpp
index f60a422..8f8001e 100644
--- a/microkde/kdatepickernew.cpp
+++ b/microkde/kdatepickernew.cpp
@@ -1,485 +1,485 @@
1/* -*- C++ -*- 1/* -*- C++ -*-
2 This file is part of the KDE libraries 2 This file is part of the KDE libraries
3 Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) 3 Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
4 (C) 1998-2001 Mirko Boehm (mirko@kde.org) 4 (C) 1998-2001 Mirko Boehm (mirko@kde.org)
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qframe.h> 22#include <qframe.h>
23#include <qpainter.h> 23#include <qpainter.h>
24#include <qdialog.h> 24#include <qdialog.h>
25#include <qstyle.h> 25#include <qstyle.h>
26#include <qtoolbutton.h> 26#include <qtoolbutton.h>
27#include <qcombobox.h> 27#include <qcombobox.h>
28#include <qtooltip.h> 28#include <qtooltip.h>
29#include <qfont.h> 29#include <qfont.h>
30#include <qvalidator.h> 30#include <qvalidator.h>
31#include <qpopupmenu.h> 31#include <qpopupmenu.h>
32 32
33#include "kdatepicker.h" 33#include "kdatepicker.h"
34#include <kglobal.h> 34#include <kglobal.h>
35#include <kapplication.h> 35#include <kapplication.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kiconloader.h> 37#include <kiconloader.h>
38#include <ktoolbar.h> 38#include <ktoolbar.h>
39#include <klineedit.h> 39#include <klineedit.h>
40#include <kdebug.h> 40#include <kdebug.h>
41#include <knotifyclient.h> 41#include <knotifyclient.h>
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#include "kdatetbl.h" 44#include "kdatetbl.h"
45#include "kdatepicker.moc" 45#include "kdatepicker.moc"
46 46
47class KDatePicker::KDatePickerPrivate 47class KDatePicker::KDatePickerPrivate
48{ 48{
49public: 49public:
50 KDatePickerPrivate() : closeButton(0L), selectWeek(0L), todayButton(0), navigationLayout(0) {} 50 KDatePickerPrivate() : closeButton(0L), selectWeek(0L), todayButton(0), navigationLayout(0) {}
51 51
52 void fillWeeksCombo(const QDate &date); 52 void fillWeeksCombo(const QDate &date);
53 53
54 KToolBar *tb; 54 KToolBar *tb;
55 QToolButton *closeButton; 55 QToolButton *closeButton;
56 QComboBox *selectWeek; 56 QComboBox *selectWeek;
57 QToolButton *todayButton; 57 QToolButton *todayButton;
58 QBoxLayout *navigationLayout; 58 QBoxLayout *navigationLayout;
59}; 59};
60 60
61void KDatePicker::fillWeeksCombo(const QDate &date) 61void KDatePicker::fillWeeksCombo(const QDate &date)
62{ 62{
63 // every year can have a different number of weeks 63 // every year can have a different number of weeks
64 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 64 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
65 int i, weeks = calendar->weeksInYear(calendar->year(date)); 65 int i, weeks = calendar->weeksInYear(calendar->year(date));
66 66
67 if ( d->selectWeek->count() == weeks ) return; // we already have the correct number 67 if ( d->selectWeek->count() == weeks ) return; // we already have the correct number
68 68
69 d->selectWeek->clear(); 69 d->selectWeek->clear();
70 70
71 for (i = 1; i <= weeks; i++) 71 for (i = 1; i <= weeks; i++)
72 d->selectWeek->insertItem(i18n("Week %1").arg(i)); 72 d->selectWeek->insertItem(i18n("Week %1").arg(i));
73} 73}
74 74
75KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) 75KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name)
76 : QFrame(parent,name) 76 : QFrame(parent,name)
77{ 77{
78 init( dt ); 78 init( dt );
79} 79}
80 80
81KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name, WFlags f) 81KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name, WFlags f)
82 : QFrame(parent,name, f) 82 : QFrame(parent,name, f)
83{ 83{
84 init( dt ); 84 init( dt );
85} 85}
86 86
87KDatePicker::KDatePicker( QWidget *parent, const char *name ) 87KDatePicker::KDatePicker( QWidget *parent, const char *name )
88 : QFrame(parent,name) 88 : QFrame(parent,name)
89{ 89{
90 init( QDate::currentDate() ); 90 init( QDate::currentDate() );
91} 91}
92 92
93void KDatePicker::init( const QDate &dt ) 93void KDatePicker::init( const QDate &dt )
94{ 94{
95 d = new KDatePickerPrivate(); 95 d = new KDatePickerPrivate();
96 96
97 d->tb = new KToolBar(this); 97 d->tb = new KToolBar(this);
98 98
99 yearBackward = new QToolButton(d->tb); 99 yearBackward = new QToolButton(d->tb);
100 monthBackward = new QToolButton(d->tb); 100 monthBackward = new QToolButton(d->tb);
101 selectMonth = new QToolButton(d->tb); 101 selectMonth = new QToolButton(d->tb);
102 selectYear = new QToolButton(d->tb); 102 selectYear = new QToolButton(d->tb);
103 monthForward = new QToolButton(d->tb); 103 monthForward = new QToolButton(d->tb);
104 yearForward = new QToolButton(d->tb); 104 yearForward = new QToolButton(d->tb);
105 line = new KLineEdit(this); 105 line = new KLineEdit(this);
106 val = new KDateValidator(this); 106 val = new KDateValidator(this);
107 table = new KDateTable(this); 107 table = new KDateTable(this);
108 fontsize = 12;//KGlobalSettings::generalFont().pointSize(); 108 fontsize = 12;//KGlobalSettings::generalFont().pointSize();
109 109
110 110
111 fontsize++; // Make a little bigger 111 fontsize++; // Make a little bigger
112 112
113 d->selectWeek = new QComboBox(false, this); // read only week selection 113 d->selectWeek = new QComboBox(false, this); // read only week selection
114 d->todayButton = new QToolButton(this); 114 d->todayButton = new QToolButton(this);
115 d->todayButton->setIconSet(SmallIconSet("today")); 115 d->todayButton->setIconSet(SmallIconSet("today"));
116 116
117 QToolTip::add(yearForward, i18n("Next year")); 117 QToolTip::add(yearForward, i18n("Next year"));
118 QToolTip::add(yearBackward, i18n("Previous year")); 118 QToolTip::add(yearBackward, i18n("Previous year"));
119 QToolTip::add(monthForward, i18n("Next month")); 119 QToolTip::add(monthForward, i18n("Next month"));
120 QToolTip::add(monthBackward, i18n("Previous month")); 120 QToolTip::add(monthBackward, i18n("Previous month"));
121 QToolTip::add(d->selectWeek, i18n("Select a week")); 121 QToolTip::add(d->selectWeek, i18n("Select a week"));
122 QToolTip::add(selectMonth, i18n("Select a month")); 122 QToolTip::add(selectMonth, i18n("Select a month"));
123 QToolTip::add(selectYear, i18n("Select a year")); 123 QToolTip::add(selectYear, i18n("Select a year"));
124 QToolTip::add(d->todayButton, i18n("Select the current day")); 124 QToolTip::add(d->todayButton, i18n("Select the current day"));
125 125
126 // ----- 126 // -----
127 setFontSize(fontsize); 127 setFontSize(fontsize);
128 line->setValidator(val); 128 line->setValidator(val);
129 line->installEventFilter( this ); 129 line->installEventFilter( this );
130// yearForward->setIconSet(BarIconSet(QString::fromLatin1("2rightarrow"))); 130// yearForward->setIconSet(BarIconSet(QString::fromLatin1("2rightarrow")));
131// yearBackward->setIconSet(BarIconSet(QString::fromLatin1("2leftarrow"))); 131// yearBackward->setIconSet(BarIconSet(QString::fromLatin1("2leftarrow")));
132// monthForward->setIconSet(BarIconSet(QString::fromLatin1("1rightarrow"))); 132// monthForward->setIconSet(BarIconSet(QString::fromLatin1("1rightarrow")));
133// monthBackward->setIconSet(BarIconSet(QString::fromLatin1("1leftarrow"))); 133// monthBackward->setIconSet(BarIconSet(QString::fromLatin1("1leftarrow")));
134 setDate(dt); // set button texts 134 setDate(dt); // set button texts
135 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); 135 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)));
136 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); 136 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
137 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); 137 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
138 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); 138 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
139 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); 139 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
140 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); 140 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
141 connect(d->selectWeek, SIGNAL(activated(int)), SLOT(weekSelected(int))); 141 connect(d->selectWeek, SIGNAL(activated(int)), SLOT(weekSelected(int)));
142 connect(d->todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked())); 142 connect(d->todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked()));
143 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); 143 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
144 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); 144 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
145 connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 145 connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
146 table->setFocus(); 146 table->setFocus();
147 147
148 QBoxLayout * topLayout = new QVBoxLayout(this); 148 QBoxLayout * topLayout = new QVBoxLayout(this);
149 149
150 d->navigationLayout = new QHBoxLayout(topLayout); 150 d->navigationLayout = new QHBoxLayout(topLayout);
151 d->navigationLayout->addWidget(d->tb); 151 d->navigationLayout->addWidget(d->tb);
152 152
153 topLayout->addWidget(table); 153 topLayout->addWidget(table);
154 154
155 QBoxLayout * bottomLayout = new QHBoxLayout(topLayout); 155 QBoxLayout * bottomLayout = new QHBoxLayout(topLayout);
156 bottomLayout->addWidget(d->todayButton); 156 bottomLayout->addWidget(d->todayButton);
157 bottomLayout->addWidget(line); 157 bottomLayout->addWidget(line);
158 bottomLayout->addWidget(d->selectWeek); 158 bottomLayout->addWidget(d->selectWeek);
159} 159}
160 160
161KDatePicker::~KDatePicker() 161KDatePicker::~KDatePicker()
162{ 162{
163 delete d; 163 delete d;
164} 164}
165 165
166bool 166bool
167KDatePicker::eventFilter(QObject *o, QEvent *e ) 167KDatePicker::eventFilter(QObject *o, QEvent *e )
168{ 168{
169 if ( e->type() == QEvent::KeyPress ) { 169 if ( e->type() == QEvent::KeyPress ) {
170 QKeyEvent *k = (QKeyEvent *)e; 170 QKeyEvent *k = (QKeyEvent *)e;
171 171
172 if ( (k->key() == Qt::Key_Prior) || 172 if ( (k->key() == Qt::Key_Prior) ||
173 (k->key() == Qt::Key_Next) || 173 (k->key() == Qt::Key_Next) ||
174 (k->key() == Qt::Key_Up) || 174 (k->key() == Qt::Key_Up) ||
175 (k->key() == Qt::Key_Down) ) 175 (k->key() == Qt::Key_Down) )
176 { 176 {
177 QApplication::sendEvent( table, e ); 177 QApplication::sendEvent( table, e );
178 table->setFocus(); 178 table->setFocus();
179 return true; // eat event 179 return true; // eat event
180 } 180 }
181 } 181 }
182 return QFrame::eventFilter( o, e ); 182 return QFrame::eventFilter( o, e );
183} 183}
184 184
185void 185void
186KDatePicker::resizeEvent(QResizeEvent* e) 186KDatePicker::resizeEvent(QResizeEvent* e)
187{ 187{
188 QWidget::resizeEvent(e); 188 QWidget::resizeEvent(e);
189} 189}
190 190
191void 191void
192KDatePicker::dateChangedSlot(QDate date) 192KDatePicker::dateChangedSlot(QDate date)
193{ 193{
194 kdDebug(298) << "KDatePicker::dateChangedSlot: date changed (" << date.year() << "/" << date.month() << "/" << date.day() << ")." << endl; 194 kdDebug(298) << "KDatePicker::dateChangedSlot: date changed (" << date.year() << "/" << date.month() << "/" << date.day() << ")." << endl;
195 195
196 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 196 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
197 197
198 line->setText(KGlobal::locale()->formatDate(date, true)); 198 line->setText(KGlobal::locale()->formatDate(date, true));
199 selectMonth->setText(calendar->monthName(date, false)); 199 selectMonth->setText(calendar->monthName(date, false));
200 fillWeeksCombo(date); 200 fillWeeksCombo(date);
201 d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1); 201 d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1);
202 selectYear->setText(calendar->yearString(date, false)); 202 selectYear->setText(calendar->yearString(date, false));
203 203
204 emit(dateChanged(date)); 204 emit(dateChanged(date));
205} 205}
206 206
207void 207void
208KDatePicker::tableClickedSlot() 208KDatePicker::tableClickedSlot()
209{ 209{
210 kdDebug(298) << "KDatePicker::tableClickedSlot: table clicked." << endl; 210 kdDebug(298) << "KDatePicker::tableClickedSlot: table clicked." << endl;
211 emit(dateSelected(table->getDate())); 211 emit(dateSelected(table->getDate()));
212 emit(tableClicked()); 212 emit(tableClicked());
213} 213}
214 214
215const QDate& 215const QDate&
216KDatePicker::getDate() const 216KDatePicker::getDate() const
217{ 217{
218 return table->getDate(); 218 return table->getDate();
219} 219}
220 220
221const QDate & 221const QDate &
222KDatePicker::date() const 222KDatePicker::date() const
223{ 223{
224 return table->getDate(); 224 return table->getDate();
225} 225}
226 226
227bool 227bool
228KDatePicker::setDate(const QDate& date) 228KDatePicker::setDate(const QDate& date)
229{ 229{
230 if(date.isValid()) 230 if(date.isValid())
231 { 231 {
232 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 232 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
233 233
234 table->setDate(date); 234 table->setDate(date);
235 fillWeeksCombo(date); 235 fillWeeksCombo(date);
236 d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1); 236 d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1);
237 selectMonth->setText(calendar->monthName(date, false)); 237 selectMonth->setText(calendar->monthName(date, false));
238 selectYear->setText(calendar->yearString(date, true)); 238 selectYear->setText(calendar->yearString(date, true));
239 line->setText(KGlobal::locale()->formatDate(date, true)); 239 line->setText(KGlobal::locale()->formatDate(date, true));
240 return true; 240 return true;
241 } 241 }
242 else 242 else
243 { 243 {
244 kdDebug(298) << "KDatePicker::setDate: refusing to set invalid date." << endl; 244 kdDebug(298) << "KDatePicker::setDate: refusing to set invalid date." << endl;
245 return false; 245 return false;
246 } 246 }
247} 247}
248 248
249void 249void
250KDatePicker::monthForwardClicked() 250KDatePicker::monthForwardClicked()
251{ 251{
252 QDate temp; 252 QDate temp;
253 temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), 1 ); 253 temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), 1 );
254 254
255 setDate( temp ); 255 setDate( temp );
256} 256}
257 257
258void 258void
259KDatePicker::monthBackwardClicked() 259KDatePicker::monthBackwardClicked()
260{ 260{
261 QDate temp; 261 QDate temp;
262 temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), -1 ); 262 temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), -1 );
263 263
264 setDate( temp ); 264 setDate( temp );
265} 265}
266 266
267void 267void
268KDatePicker::yearForwardClicked() 268KDatePicker::yearForwardClicked()
269{ 269{
270 QDate temp; 270 QDate temp;
271 temp = KGlobal::locale()->calendar()->addYears( table->getDate(), 1 ); 271 temp = KGlobal::locale()->calendar()->addYears( table->getDate(), 1 );
272 272
273 setDate( temp ); 273 setDate( temp );
274} 274}
275 275
276void 276void
277KDatePicker::yearBackwardClicked() 277KDatePicker::yearBackwardClicked()
278{ 278{
279 QDate temp; 279 QDate temp;
280 temp = KGlobal::locale()->calendar()->addYears( table->getDate(), -1 ); 280 temp = KGlobal::locale()->calendar()->addYears( table->getDate(), -1 );
281 281
282 setDate( temp ); 282 setDate( temp );
283} 283}
284 284
285void KDatePicker::selectWeekClicked() {} // ### in 3.2 obsolete; kept for binary compatibility 285void KDatePicker::selectWeekClicked() {} // ### in 3.2 obsolete; kept for binary compatibility
286 286
287void 287void
288KDatePicker::weekSelected(int week) 288KDatePicker::weekSelected(int week)
289{ 289{
290 week++; // week number starts with 1 290 week++; // week number starts with 1
291 291
292 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 292 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
293 293
294 QDate date = table->getDate(); 294 QDate date = table->getDate();
295 int year = calendar->year(date); 295 int year = calendar->year(date);
296 296
297 calendar->setYMD(date, year, 1, 1); 297 calendar->setYMD(date, year, 1, 1);
298 date = calendar->addDays(date, -7); 298 date = calendar->addDays(date, -7);
299 while (calendar->weekNumber(date) != 1) 299 while (calendar->weekNumber(date) != 1)
300 date = calendar->addDays(date, 1); 300 date = calendar->addDays(date, 1);
301 301
302 // date is now first day in week 1 some day in week 1 302 // date is now first day in week 1 some day in week 1
303 date = calendar->addDays(date, (week - calendar->weekNumber(date)) * 7); 303 date = calendar->addDays(date, (week - calendar->weekNumber(date)) * 7);
304 304
305 setDate(date); 305 setDate(date);
306} 306}
307 307
308void 308void
309KDatePicker::selectMonthClicked() 309KDatePicker::selectMonthClicked()
310{ 310{
311 // every year can have different month names (in some calendar systems) 311 // every year can have different month names (in some calendar systems)
312 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 312 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
313 QDate date = table->getDate(); 313 QDate date = table->getDate();
314 int i, month, months = calendar->monthsInYear(date); 314 int i, month, months = calendar->monthsInYear(date);
315 315
316 QPopupMenu popup(selectMonth); 316 Q3PopupMenu popup(selectMonth);
317 317
318 for (i = 1; i <= months; i++) 318 for (i = 1; i <= months; i++)
319 popup.insertItem(calendar->monthName(i, calendar->year(date)), i); 319 popup.insertItem(calendar->monthName(i, calendar->year(date)), i);
320 320
321 popup.setActiveItem(calendar->month(date) - 1); 321 popup.setActiveItem(calendar->month(date) - 1);
322 322
323 if ( (month = popup.exec(selectMonth->mapToGlobal(QPoint(0, 0)), calendar->month(date) - 1)) == -1 ) return; // canceled 323 if ( (month = popup.exec(selectMonth->mapToGlobal(QPoint(0, 0)), calendar->month(date) - 1)) == -1 ) return; // canceled
324 324
325 int day = calendar->day(date); 325 int day = calendar->day(date);
326 // ----- construct a valid date in this month: 326 // ----- construct a valid date in this month:
327 //date.setYMD(date.year(), month, 1); 327 //date.setYMD(date.year(), month, 1);
328 //date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); 328 //date.setYMD(date.year(), month, QMIN(day, date.daysInMonth()));
329 calendar->setYMD(date, calendar->year(date), month, 329 calendar->setYMD(date, calendar->year(date), month,
330 QMIN(day, calendar->daysInMonth(date))); 330 QMIN(day, calendar->daysInMonth(date)));
331 // ----- set this month 331 // ----- set this month
332 setDate(date); 332 setDate(date);
333} 333}
334 334
335void 335void
336KDatePicker::selectYearClicked() 336KDatePicker::selectYearClicked()
337{ 337{
338 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 338 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
339 339
340 int year; 340 int year;
341 KPopupFrame* popup = new KPopupFrame(this); 341 KPopupFrame* popup = new KPopupFrame(this);
342 KDateInternalYearSelector* picker = new KDateInternalYearSelector(popup); 342 KDateInternalYearSelector* picker = new KDateInternalYearSelector(popup);
343 // ----- 343 // -----
344 picker->resize(picker->sizeHint()); 344 picker->resize(picker->sizeHint());
345 popup->setMainWidget(picker); 345 popup->setMainWidget(picker);
346 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 346 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
347 picker->setFocus(); 347 picker->setFocus();
348 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) 348 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
349 { 349 {
350 QDate date; 350 QDate date;
351 int day; 351 int day;
352 // ----- 352 // -----
353 year=picker->getYear(); 353 year=picker->getYear();
354 date=table->getDate(); 354 date=table->getDate();
355 day=calendar->day(date); 355 day=calendar->day(date);
356 // ----- construct a valid date in this month: 356 // ----- construct a valid date in this month:
357 //date.setYMD(year, date.month(), 1); 357 //date.setYMD(year, date.month(), 1);
358 //date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); 358 //date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
359 calendar->setYMD(date, year, calendar->month(date), 359 calendar->setYMD(date, year, calendar->month(date),
360 QMIN(day, calendar->daysInMonth(date))); 360 QMIN(day, calendar->daysInMonth(date)));
361 // ----- set this month 361 // ----- set this month
362 setDate(date); 362 setDate(date);
363 } else { 363 } else {
364 KNotifyClient::beep(); 364 KNotifyClient::beep();
365 } 365 }
366 delete popup; 366 delete popup;
367} 367}
368 368
369void 369void
370KDatePicker::setEnabled(bool enable) 370KDatePicker::setEnabled(bool enable)
371{ 371{
372 QWidget *widgets[]= { 372 QWidget *widgets[]= {
373 yearForward, yearBackward, monthForward, monthBackward, 373 yearForward, yearBackward, monthForward, monthBackward,
374 selectMonth, selectYear, 374 selectMonth, selectYear,
375 line, table, d->selectWeek, d->todayButton }; 375 line, table, d->selectWeek, d->todayButton };
376 const int Size=sizeof(widgets)/sizeof(widgets[0]); 376 const int Size=sizeof(widgets)/sizeof(widgets[0]);
377 int count; 377 int count;
378 // ----- 378 // -----
379 for(count=0; count<Size; ++count) 379 for(count=0; count<Size; ++count)
380 { 380 {
381 widgets[count]->setEnabled(enable); 381 widgets[count]->setEnabled(enable);
382 } 382 }
383} 383}
384 384
385void 385void
386KDatePicker::lineEnterPressed() 386KDatePicker::lineEnterPressed()
387{ 387{
388 QDate temp; 388 QDate temp;
389 // ----- 389 // -----
390 if(val->date(line->text(), temp)==QValidator::Acceptable) 390 if(val->date(line->text(), temp)==QValidator::Acceptable)
391 { 391 {
392 kdDebug(298) << "KDatePicker::lineEnterPressed: valid date entered." << endl; 392 kdDebug(298) << "KDatePicker::lineEnterPressed: valid date entered." << endl;
393 emit(dateEntered(temp)); 393 emit(dateEntered(temp));
394 setDate(temp); 394 setDate(temp);
395 } else { 395 } else {
396 KNotifyClient::beep(); 396 KNotifyClient::beep();
397 kdDebug(298) << "KDatePicker::lineEnterPressed: invalid date entered." << endl; 397 kdDebug(298) << "KDatePicker::lineEnterPressed: invalid date entered." << endl;
398 } 398 }
399} 399}
400 400
401void 401void
402KDatePicker::todayButtonClicked() 402KDatePicker::todayButtonClicked()
403{ 403{
404 setDate(QDate::currentDate()); 404 setDate(QDate::currentDate());
405} 405}
406 406
407QSize 407QSize
408KDatePicker::sizeHint() const 408KDatePicker::sizeHint() const
409{ 409{
410 return QWidget::sizeHint(); 410 return QWidget::sizeHint();
411} 411}
412 412
413void 413void
414KDatePicker::setFontSize(int s) 414KDatePicker::setFontSize(int s)
415{ 415{
416 QWidget *buttons[]= { 416 QWidget *buttons[]= {
417 // yearBackward, 417 // yearBackward,
418 // monthBackward, 418 // monthBackward,
419 selectMonth, 419 selectMonth,
420 selectYear, 420 selectYear,
421 // monthForward, 421 // monthForward,
422 // yearForward 422 // yearForward
423 }; 423 };
424 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 424 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
425 int count; 425 int count;
426 QFont font; 426 QFont font;
427 QRect r; 427 QRect r;
428 // ----- 428 // -----
429 fontsize=s; 429 fontsize=s;
430 for(count=0; count<NoOfButtons; ++count) 430 for(count=0; count<NoOfButtons; ++count)
431 { 431 {
432 font=buttons[count]->font(); 432 font=buttons[count]->font();
433 font.setPointSize(s); 433 font.setPointSize(s);
434 buttons[count]->setFont(font); 434 buttons[count]->setFont(font);
435 } 435 }
436 QFontMetrics metrics(selectMonth->fontMetrics()); 436 QFontMetrics metrics(selectMonth->fontMetrics());
437 437
438 for (int i = 1; ; ++i) 438 for (int i = 1; ; ++i)
439 { 439 {
440 QString str = KGlobal::locale()->calendar()->monthName(i, 440 QString str = KGlobal::locale()->calendar()->monthName(i,
441 KGlobal::locale()->calendar()->year(table->getDate()), false); 441 KGlobal::locale()->calendar()->year(table->getDate()), false);
442 if (str.isNull()) break; 442 if (str.isNull()) break;
443 r=metrics.boundingRect(str); 443 r=metrics.boundingRect(str);
444 maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); 444 maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width()));
445 maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); 445 maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height()));
446 } 446 }
447 447
448 QSize metricBound = style().sizeFromContents(QStyle::CT_ToolButton, 448 QSize metricBound = style().sizeFromContents(QStyle::CT_ToolButton,
449 selectMonth, 449 selectMonth,
450 maxMonthRect); 450 maxMonthRect);
451 selectMonth->setMinimumSize(metricBound); 451 selectMonth->setMinimumSize(metricBound);
452 452
453 table->setFontSize(s); 453 table->setFontSize(s);
454} 454}
455 455
456void 456void
457KDatePicker::setCloseButton( bool enable ) 457KDatePicker::setCloseButton( bool enable )
458{ 458{
459 if ( enable == (d->closeButton != 0L) ) 459 if ( enable == (d->closeButton != 0L) )
460 return; 460 return;
461 461
462 if ( enable ) { 462 if ( enable ) {
463 d->closeButton = new QToolButton( d->tb ); 463 d->closeButton = new QToolButton( d->tb );
464 d->navigationLayout->addWidget(d->closeButton); 464 d->navigationLayout->addWidget(d->closeButton);
465 QToolTip::add(d->closeButton, i18n("Close")); 465 QToolTip::add(d->closeButton, i18n("Close"));
466 d->closeButton->setPixmap( SmallIcon("remove") ); 466 d->closeButton->setPixmap( SmallIcon("remove") );
467 connect( d->closeButton, SIGNAL( clicked() ), 467 connect( d->closeButton, SIGNAL( clicked() ),
468 topLevelWidget(), SLOT( close() ) ); 468 topLevelWidget(), SLOT( close() ) );
469 } 469 }
470 else { 470 else {
471 delete d->closeButton; 471 delete d->closeButton;
472 d->closeButton = 0L; 472 d->closeButton = 0L;
473 } 473 }
474 474
475 updateGeometry(); 475 updateGeometry();
476} 476}
477 477
478bool KDatePicker::hasCloseButton() const 478bool KDatePicker::hasCloseButton() const
479{ 479{
480 return (d->closeButton != 0L); 480 return (d->closeButton != 0L);
481} 481}
482 482
483void KDatePicker::virtual_hook( int /*id*/, void* /*data*/ ) 483void KDatePicker::virtual_hook( int /*id*/, void* /*data*/ )
484{ /*BASE::virtual_hook( id, data );*/ } 484{ /*BASE::virtual_hook( id, data );*/ }
485 485