summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdatepicker.cpp
Unidiff
Diffstat (limited to 'libkdepim/kdatepicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdatepicker.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp
index 68ef943..28b65cf 100644
--- a/libkdepim/kdatepicker.cpp
+++ b/libkdepim/kdatepicker.cpp
@@ -1,498 +1,502 @@
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 "kdatepicker.h" 21#include "kdatepicker.h"
22#include <kglobal.h> 22#include <kglobal.h>
23#include <kapplication.h> 23#include <kapplication.h>
24#include <klocale.h> 24#include <klocale.h>
25#include <kiconloader.h> 25#include <kiconloader.h>
26#include <qframe.h> 26#include <q3frame.h>
27#include <qpainter.h> 27#include <qpainter.h>
28#include <qdialog.h> 28#include <qdialog.h>
29#include <qtoolbutton.h> 29#include <qtoolbutton.h>
30#include <qfont.h> 30#include <qfont.h>
31#include <qapplication.h> 31#include <qapplication.h>
32#include <qlineedit.h> 32#include <qlineedit.h>
33#include <qvalidator.h> 33#include <qvalidator.h>
34//Added by qt3to4:
35#include <QResizeEvent>
36#include <QKeyEvent>
37#include <QDesktopWidget>
34#include <kdebug.h> 38#include <kdebug.h>
35#include <knotifyclient.h> 39#include <knotifyclient.h>
36#include <kglobalsettings.h> 40#include <kglobalsettings.h>
37#include "kdatetbl.h" 41#include "kdatetbl.h"
38#include "kdateedit.h" 42#include "kdateedit.h"
39//#include "kdatepicker.moc" 43//#include "kdatepicker.moc"
40 44
41 45
42KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) 46KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name)
43 : QFrame(parent,name), 47 : Q3Frame(parent,name),
44 yearForward(new QToolButton(this)), 48 yearForward(new QToolButton(this)),
45 yearBackward(new QToolButton(this)), 49 yearBackward(new QToolButton(this)),
46 monthForward(new QToolButton(this)), 50 monthForward(new QToolButton(this)),
47 monthBackward(new QToolButton(this)), 51 monthBackward(new QToolButton(this)),
48 selectMonth(new QToolButton(this)), 52 selectMonth(new QToolButton(this)),
49 selectYear(new QToolButton(this)), 53 selectYear(new QToolButton(this)),
50 todayBut(new QToolButton(this)), 54 todayBut(new QToolButton(this)),
51 //line(new QLineEdit(this)), 55 //line(new QLineEdit(this)),
52 val(new KDateValidator(this)) 56 val(new KDateValidator(this))
53 //table(new KDateTable(this)), 57 //table(new KDateTable(this)),
54 //fontsize(1) 58 //fontsize(1)
55{ 59{
56 QFont fo = KGlobalSettings::generalFont(); 60 QFont fo = KGlobalSettings::generalFont();
57 int add = 2; 61 int add = 2;
58 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) 62 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
59 add += 4; 63 add += 4;
60 fo.setPointSize(fo.pointSize()+add ); 64 fo.setPointSize(fo.pointSize()+add );
61 setFont( fo ); 65 setFont( fo );
62 table = new KDateTable(this); 66 table = new KDateTable(this);
63 setFontSize(font().pointSize()); 67 setFontSize(font().pointSize());
64 //line->setValidator(val); 68 //line->setValidator(val);
65 lineDate = new KDateEdit( this, "dateediipicker", true ); 69 lineDate = new KDateEdit( this, "dateediipicker", true );
66 yearForward->setPixmap(SmallIcon("3rightarrowB")); 70 yearForward->setPixmap(SmallIcon("3rightarrowB"));
67 yearBackward->setPixmap(SmallIcon("3leftarrowB")); 71 yearBackward->setPixmap(SmallIcon("3leftarrowB"));
68 monthForward->setPixmap(SmallIcon("2rightarrowB")); 72 monthForward->setPixmap(SmallIcon("2rightarrowB"));
69 monthBackward->setPixmap(SmallIcon("2leftarrowB")); 73 monthBackward->setPixmap(SmallIcon("2leftarrowB"));
70 todayBut->setPixmap(SmallIcon("today")); 74 todayBut->setPixmap(SmallIcon("today"));
71 setDate(dt); // set button texts 75 setDate(dt); // set button texts
72 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); 76 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)));
73 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); 77 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
74 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); 78 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
75 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); 79 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
76 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); 80 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
77 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); 81 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
78 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); 82 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
79 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); 83 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
80 connect(todayBut, SIGNAL(clicked()), SLOT(goToday())); 84 connect(todayBut, SIGNAL(clicked()), SLOT(goToday()));
81 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 85 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
82 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); 86 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate)));
83 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 87 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
84 table->setFocus(); 88 table->setFocus();
85 89
86} 90}
87 91
88KDatePicker::~KDatePicker() 92KDatePicker::~KDatePicker()
89{ 93{
90} 94}
91 95
92void 96void
93KDatePicker::resizeEvent(QResizeEvent*) 97KDatePicker::resizeEvent(QResizeEvent*)
94{ 98{
95 QWidget *buttons[] = { 99 QWidget *buttons[] = {
96 yearBackward, 100 yearBackward,
97 monthBackward, 101 monthBackward,
98 selectMonth, 102 selectMonth,
99 selectYear, 103 selectYear,
100 monthForward, 104 monthForward,
101 yearForward }; 105 yearForward };
102 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 106 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
103 QSize sizes[NoOfButtons]; 107 QSize sizes[NoOfButtons];
104 int buttonHeight=0; 108 int buttonHeight=0;
105 int count; 109 int count;
106 int w; 110 int w;
107 int x=0; 111 int x=0;
108 // ----- calculate button row height: 112 // ----- calculate button row height:
109 for(count=0; count<NoOfButtons; ++count) { 113 for(count=0; count<NoOfButtons; ++count) {
110 int xS = buttons[count]->sizeHint().width(); 114 int xS = buttons[count]->sizeHint().width();
111 int yS = buttons[count]->sizeHint().height(); 115 int yS = buttons[count]->sizeHint().height();
112 if ( QApplication::desktop()->width() < 320 ) 116 if ( QApplication::desktop()->width() < 320 )
113 sizes[count]=QSize ( xS+4, yS ); 117 sizes[count]=QSize ( xS+4, yS );
114 else 118 else
115 sizes[count]=QSize ( xS+10, yS ); 119 sizes[count]=QSize ( xS+10, yS );
116 120
117 buttonHeight=QMAX(buttonHeight, sizes[count].height()); 121 buttonHeight=QMAX(buttonHeight, sizes[count].height());
118 } 122 }
119 buttonHeight += 10; 123 buttonHeight += 10;
120 // ----- calculate size of the month button: 124 // ----- calculate size of the month button:
121 w=0; 125 w=0;
122 for(count=0; count<NoOfButtons; ++count) { 126 for(count=0; count<NoOfButtons; ++count) {
123 if(buttons[count]!=selectMonth) 127 if(buttons[count]!=selectMonth)
124 { 128 {
125 w+=sizes[count].width(); 129 w+=sizes[count].width();
126 } else { 130 } else {
127 x=count; 131 x=count;
128 } 132 }
129 } 133 }
130 sizes[x].setWidth(width()-w); // stretch the month button 134 sizes[x].setWidth(width()-w); // stretch the month button
131 // ----- place the buttons: 135 // ----- place the buttons:
132 x=0; 136 x=0;
133 for(count=0; count<NoOfButtons; ++count) 137 for(count=0; count<NoOfButtons; ++count)
134 { 138 {
135 w=sizes[count].width(); 139 w=sizes[count].width();
136 buttons[count]->setGeometry(x, 0, w, buttonHeight); 140 buttons[count]->setGeometry(x, 0, w, buttonHeight);
137 x+=w; 141 x+=w;
138 } 142 }
139 // ----- place the line edit for direct input: 143 // ----- place the line edit for direct input:
140 sizes[0]=lineDate->sizeHint(); 144 sizes[0]=lineDate->sizeHint();
141 //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); 145 //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height());
142 int todaywid = todayBut->sizeHint().width(); 146 int todaywid = todayBut->sizeHint().width();
143todayBut->setGeometry(0, height()-sizes[0].height(),todaywid, sizes[0].height()); 147todayBut->setGeometry(0, height()-sizes[0].height(),todaywid, sizes[0].height());
144 lineDate->setGeometry(0+todaywid, height()-sizes[0].height(), width()-todaywid, sizes[0].height()); 148 lineDate->setGeometry(0+todaywid, height()-sizes[0].height(), width()-todaywid, sizes[0].height());
145 // ----- adjust the table: 149 // ----- adjust the table:
146 table->setGeometry(0, buttonHeight, width(), 150 table->setGeometry(0, buttonHeight, width(),
147 height()-buttonHeight-sizes[0].height()); 151 height()-buttonHeight-sizes[0].height());
148} 152}
149 153
150void 154void
151KDatePicker::dateChangedSlot(QDate date) 155KDatePicker::dateChangedSlot(QDate date)
152{ 156{
153 lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); 157 lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true));
154 //line->setText(KGlobal::locale()->formatDate(date, true)); 158 //line->setText(KGlobal::locale()->formatDate(date, true));
155 QString temp; 159 QString temp;
156 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); 160 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false));
157 temp.setNum(date.year()); 161 temp.setNum(date.year());
158 selectYear->setText(temp); 162 selectYear->setText(temp);
159 emit(dateChanged(date)); 163 emit(dateChanged(date));
160} 164}
161 165
162void 166void
163KDatePicker::tableClickedSlot() 167KDatePicker::tableClickedSlot()
164{ 168{
165 169
166 emit(dateSelected(table->getDate())); 170 emit(dateSelected(table->getDate()));
167 emit(tableClicked()); 171 emit(tableClicked());
168} 172}
169 173
170const QDate& 174const QDate&
171KDatePicker::getDate() const 175KDatePicker::getDate() const
172{ 176{
173 return table->getDate(); 177 return table->getDate();
174} 178}
175 179
176const QDate & 180const QDate &
177KDatePicker::date() const 181KDatePicker::date() const
178{ 182{
179 return table->getDate(); 183 return table->getDate();
180} 184}
181 185
182void KDatePicker::goToday() 186void KDatePicker::goToday()
183{ 187{
184 slotSetDate( QDate::currentDate() ); 188 slotSetDate( QDate::currentDate() );
185 189
186} 190}
187void KDatePicker::slotSetDate( QDate date ) 191void KDatePicker::slotSetDate( QDate date )
188{ 192{
189 193
190 if(date.isValid()) { 194 if(date.isValid()) {
191 QString temp; 195 QString temp;
192 // ----- 196 // -----
193 table->setDate(date); 197 table->setDate(date);
194 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); 198 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false));
195 temp.setNum(date.year()); 199 temp.setNum(date.year());
196 selectYear->setText(temp); 200 selectYear->setText(temp);
197 //line->setText(KGlobal::locale()->formatDate(date, true)); 201 //line->setText(KGlobal::locale()->formatDate(date, true));
198 lineDate->setDate( date ); 202 lineDate->setDate( date );
199 } 203 }
200 204
201} 205}
202bool 206bool
203KDatePicker::setDate(const QDate& date) 207KDatePicker::setDate(const QDate& date)
204{ 208{
205 table->setFocus(); 209 table->setFocus();
206 if(date.isValid()) { 210 if(date.isValid()) {
207 QString temp; 211 QString temp;
208 // ----- 212 // -----
209 table->setDate(date); 213 table->setDate(date);
210 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); 214 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false));
211 temp.setNum(date.year()); 215 temp.setNum(date.year());
212 selectYear->setText(temp); 216 selectYear->setText(temp);
213 //line->setText(KGlobal::locale()->formatDate(date, true)); 217 //line->setText(KGlobal::locale()->formatDate(date, true));
214 lineDate->setDate( date ); 218 lineDate->setDate( date );
215 return true; 219 return true;
216 } else { 220 } else {
217 221
218 return false; 222 return false;
219 } 223 }
220 224
221 225
222} 226}
223 227
224void 228void
225KDatePicker::monthForwardClicked() 229KDatePicker::monthForwardClicked()
226{ 230{
227 QDate temp=table->getDate(); 231 QDate temp=table->getDate();
228 int day=temp.day(); 232 int day=temp.day();
229 // ----- 233 // -----
230 if(temp.month()==12) { 234 if(temp.month()==12) {
231 temp.setYMD(temp.year()+1, 1, 1); 235 temp.setYMD(temp.year()+1, 1, 1);
232 } else { 236 } else {
233 temp.setYMD(temp.year(), temp.month()+1, 1); 237 temp.setYMD(temp.year(), temp.month()+1, 1);
234 } 238 }
235 if(temp.daysInMonth()<day) { 239 if(temp.daysInMonth()<day) {
236 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 240 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
237 } else { 241 } else {
238 temp.setYMD(temp.year(), temp.month(), day); 242 temp.setYMD(temp.year(), temp.month(), day);
239 } 243 }
240 // assert(temp.isValid()); 244 // assert(temp.isValid());
241 setDate(temp); 245 setDate(temp);
242} 246}
243 247
244void 248void
245KDatePicker::monthBackwardClicked() 249KDatePicker::monthBackwardClicked()
246{ 250{
247 QDate temp=table->getDate(); 251 QDate temp=table->getDate();
248 int day=temp.day(); 252 int day=temp.day();
249 // ----- 253 // -----
250 if(temp.month()==1) 254 if(temp.month()==1)
251 { 255 {
252 temp.setYMD(temp.year()-1, 12, 1); 256 temp.setYMD(temp.year()-1, 12, 1);
253 } else { 257 } else {
254 temp.setYMD(temp.year(), temp.month()-1, 1); 258 temp.setYMD(temp.year(), temp.month()-1, 1);
255 } 259 }
256 if(temp.daysInMonth()<day) 260 if(temp.daysInMonth()<day)
257 { 261 {
258 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 262 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
259 } else { 263 } else {
260 temp.setYMD(temp.year(), temp.month(), day); 264 temp.setYMD(temp.year(), temp.month(), day);
261 } 265 }
262 // assert(temp.isValid()); 266 // assert(temp.isValid());
263 setDate(temp); 267 setDate(temp);
264} 268}
265 269
266void 270void
267KDatePicker::yearForwardClicked() 271KDatePicker::yearForwardClicked()
268{ 272{
269 QDate temp=table->getDate(); 273 QDate temp=table->getDate();
270 int day=temp.day(); 274 int day=temp.day();
271 // ----- 275 // -----
272 temp.setYMD(temp.year()+1, temp.month(), 1); 276 temp.setYMD(temp.year()+1, temp.month(), 1);
273 if(temp.daysInMonth()<day) 277 if(temp.daysInMonth()<day)
274 { 278 {
275 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 279 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
276 } else { 280 } else {
277 temp.setYMD(temp.year(), temp.month(), day); 281 temp.setYMD(temp.year(), temp.month(), day);
278 } 282 }
279 // assert(temp.isValid()); 283 // assert(temp.isValid());
280 setDate(temp); 284 setDate(temp);
281} 285}
282 286
283void 287void
284KDatePicker::yearBackwardClicked() 288KDatePicker::yearBackwardClicked()
285{ 289{
286 QDate temp=table->getDate(); 290 QDate temp=table->getDate();
287 int day=temp.day(); 291 int day=temp.day();
288 // ----- 292 // -----
289 temp.setYMD(temp.year()-1, temp.month(), 1); 293 temp.setYMD(temp.year()-1, temp.month(), 1);
290 if(temp.daysInMonth()<day) 294 if(temp.daysInMonth()<day)
291 { 295 {
292 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 296 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
293 } else { 297 } else {
294 temp.setYMD(temp.year(), temp.month(), day); 298 temp.setYMD(temp.year(), temp.month(), day);
295 } 299 }
296 // assert(temp.isValid()); 300 // assert(temp.isValid());
297 setDate(temp); 301 setDate(temp);
298} 302}
299 303
300void 304void
301KDatePicker::selectMonthClicked() 305KDatePicker::selectMonthClicked()
302{ 306{
303 int month; 307 int month;
304 KPopupFrame* popup = new KPopupFrame(this); 308 KPopupFrame* popup = new KPopupFrame(this);
305 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); 309 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup);
306 // ----- 310 // -----
307 picker->resize(picker->sizeHint()); 311 picker->resize(picker->sizeHint());
308 popup->setMainWidget(picker); 312 popup->setMainWidget(picker);
309 picker->setFocus(); 313 picker->setFocus();
310 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 314 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
311 if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height())))) 315 if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height()))))
312 { 316 {
313 QDate date; 317 QDate date;
314 int day; 318 int day;
315 // ----- 319 // -----
316 month=picker->getResult(); 320 month=picker->getResult();
317 date=table->getDate(); 321 date=table->getDate();
318 day=date.day(); 322 day=date.day();
319 // ----- construct a valid date in this month: 323 // ----- construct a valid date in this month:
320 date.setYMD(date.year(), month, 1); 324 date.setYMD(date.year(), month, 1);
321 date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); 325 date.setYMD(date.year(), month, QMIN(day, date.daysInMonth()));
322 // ----- set this month 326 // ----- set this month
323 setDate(date); 327 setDate(date);
324 } else { 328 } else {
325 KNotifyClient::beep(); 329 KNotifyClient::beep();
326 } 330 }
327 delete popup; 331 delete popup;
328} 332}
329 333
330void 334void
331KDatePicker::selectYearClicked() 335KDatePicker::selectYearClicked()
332{ 336{
333 int year; 337 int year;
334 KPopupFrame* popup = new KPopupFrame(this); 338 KPopupFrame* popup = new KPopupFrame(this);
335 KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup); 339 KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup);
336 // ----- 340 // -----
337 picker->resize(picker->sizeHint()); 341 picker->resize(picker->sizeHint());
338 popup->setMainWidget(picker); 342 popup->setMainWidget(picker);
339 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 343 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
340 picker->setFocus(); 344 picker->setFocus();
341 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) 345 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
342 { 346 {
343 QDate date; 347 QDate date;
344 int day; 348 int day;
345 // ----- 349 // -----
346 year=picker->getYear(); 350 year=picker->getYear();
347 date=table->getDate(); 351 date=table->getDate();
348 day=date.day(); 352 day=date.day();
349 // ----- construct a valid date in this month: 353 // ----- construct a valid date in this month:
350 date.setYMD(year, date.month(), 1); 354 date.setYMD(year, date.month(), 1);
351 date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); 355 date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
352 // ----- set this month 356 // ----- set this month
353 setDate(date); 357 setDate(date);
354 } else { 358 } else {
355 KNotifyClient::beep(); 359 KNotifyClient::beep();
356 } 360 }
357 delete popup; 361 delete popup;
358} 362}
359 363
360void 364void
361KDatePicker::setEnabled(bool enable) 365KDatePicker::setEnabled(bool enable)
362{ 366{
363 QWidget *widgets[]= { 367 QWidget *widgets[]= {
364 yearForward, yearBackward, monthForward, monthBackward, 368 yearForward, yearBackward, monthForward, monthBackward,
365 selectMonth, selectYear, 369 selectMonth, selectYear,
366 lineDate, table }; 370 lineDate, table };
367 const int Size=sizeof(widgets)/sizeof(widgets[0]); 371 const int Size=sizeof(widgets)/sizeof(widgets[0]);
368 int count; 372 int count;
369 // ----- 373 // -----
370 for(count=0; count<Size; ++count) 374 for(count=0; count<Size; ++count)
371 { 375 {
372 widgets[count]->setEnabled(enable); 376 widgets[count]->setEnabled(enable);
373 } 377 }
374} 378}
375 379
376void 380void
377KDatePicker::lineEnterPressed() 381KDatePicker::lineEnterPressed()
378{ 382{
379 QDate temp; 383 QDate temp;
380 // ----- 384 // -----
381 temp = lineDate->date(); 385 temp = lineDate->date();
382 //if(val->date(line->text(), temp)==QValidator::Acceptable) 386 //if(val->date(line->text(), temp)==QValidator::Acceptable)
383 //{ 387 //{
384 emit(dateEntered(temp)); 388 emit(dateEntered(temp));
385 setDate(temp); 389 setDate(temp);
386 // } else { 390 // } else {
387// KNotifyClient::beep(); 391// KNotifyClient::beep();
388// } 392// }
389} 393}
390 394
391QSize 395QSize
392KDatePicker::sizeHint() const 396KDatePicker::sizeHint() const
393{ 397{
394 QSize tableSize=table->sizeHint(); 398 QSize tableSize=table->sizeHint();
395 QWidget *buttons[]={ 399 QWidget *buttons[]={
396 yearBackward, 400 yearBackward,
397 monthBackward, 401 monthBackward,
398 selectMonth, 402 selectMonth,
399 selectYear, 403 selectYear,
400 monthForward, 404 monthForward,
401 yearForward }; 405 yearForward };
402 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 406 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
403 QSize sizes[NoOfButtons]; 407 QSize sizes[NoOfButtons];
404 int cx=0, cy=0, count; 408 int cx=0, cy=0, count;
405 // ----- store the size hints: 409 // ----- store the size hints:
406 for(count=0; count<NoOfButtons; ++count) 410 for(count=0; count<NoOfButtons; ++count)
407 { 411 {
408 sizes[count]=buttons[count]->sizeHint(); 412 sizes[count]=buttons[count]->sizeHint();
409 if(buttons[count]==selectMonth) 413 if(buttons[count]==selectMonth)
410 { 414 {
411 cx+=maxMonthRect.width()+15; 415 cx+=maxMonthRect.width()+15;
412 } else { 416 } else {
413 cx+=sizes[count].width()+15; 417 cx+=sizes[count].width()+15;
414 } 418 }
415 cy=QMAX(sizes[count].height(), cy); 419 cy=QMAX(sizes[count].height(), cy);
416 } 420 }
417 // ----- calculate width hint: 421 // ----- calculate width hint:
418 cx=QMAX(cx, tableSize.width()); // line edit ignored 422 cx=QMAX(cx, tableSize.width()); // line edit ignored
419 if ( cx > QApplication::desktop()->width() -5 ) 423 if ( cx > QApplication::desktop()->width() -5 )
420 cx = QApplication::desktop()->width() -5; 424 cx = QApplication::desktop()->width() -5;
421 // ----- calculate height hint: 425 // ----- calculate height hint:
422 cy+=tableSize.height()+lineDate->sizeHint().height(); 426 cy+=tableSize.height()+lineDate->sizeHint().height();
423 427
424 return QSize(cx, cy); 428 return QSize(cx, cy);
425} 429}
426 430
427void 431void
428KDatePicker::setFontSize(int s) 432KDatePicker::setFontSize(int s)
429{ 433{
430 QWidget *buttons[]= { 434 QWidget *buttons[]= {
431 // yearBackward, 435 // yearBackward,
432 // monthBackward, 436 // monthBackward,
433 selectMonth, 437 selectMonth,
434 selectYear, 438 selectYear,
435 // monthForward, 439 // monthForward,
436 // yearForward 440 // yearForward
437 }; 441 };
438 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 442 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
439 int count; 443 int count;
440 QFont font; 444 QFont font;
441 QRect r; 445 QRect r;
442 // ----- 446 // -----
443 fontsize=s; 447 fontsize=s;
444 for(count=0; count<NoOfButtons; ++count) 448 for(count=0; count<NoOfButtons; ++count)
445 { 449 {
446 font=buttons[count]->font(); 450 font=buttons[count]->font();
447 font.setPointSize(s); 451 font.setPointSize(s);
448 buttons[count]->setFont(font); 452 buttons[count]->setFont(font);
449 } 453 }
450 QFontMetrics metrics(selectMonth->fontMetrics()); 454 QFontMetrics metrics(selectMonth->fontMetrics());
451 for(int i=1; i <= 12; ++i) 455 for(int i=1; i <= 12; ++i)
452 { // maxMonthRect is used by sizeHint() 456 { // maxMonthRect is used by sizeHint()
453 r=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); 457 r=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
454 maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); 458 maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width()));
455 maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); 459 maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height()));
456 } 460 }
457 table->setFontSize(s); 461 table->setFontSize(s);
458} 462}
459 463
460void KDatePicker::virtual_hook( int id, void* data ) 464void KDatePicker::virtual_hook( int id, void* data )
461{ /*BASE::virtual_hook( id, data );*/ } 465{ /*BASE::virtual_hook( id, data );*/ }
462 466
463void KDatePicker::keyPressEvent ( QKeyEvent * e ) 467void KDatePicker::keyPressEvent ( QKeyEvent * e )
464{ 468{
465 switch ( e->key() ) { 469 switch ( e->key() ) {
466 case Qt::Key_Right: 470 case Qt::Key_Right:
467 monthForwardClicked(); 471 monthForwardClicked();
468 break; 472 break;
469 case Qt::Key_Left: 473 case Qt::Key_Left:
470 monthBackwardClicked(); 474 monthBackwardClicked();
471 break; 475 break;
472 476
473 case Qt::Key_Down: 477 case Qt::Key_Down:
474 yearForwardClicked(); 478 yearForwardClicked();
475 479
476 break; 480 break;
477 481
478 case Qt::Key_Up: 482 case Qt::Key_Up:
479 yearBackwardClicked(); 483 yearBackwardClicked();
480 break; 484 break;
481 485
482 case Qt::Key_T: 486 case Qt::Key_T:
483 goToday(); 487 goToday();
484 break; 488 break;
485 489
486 case Qt::Key_Return: 490 case Qt::Key_Return:
487 case Qt::Key_Enter: 491 case Qt::Key_Enter:
488 case Qt::Key_Space: 492 case Qt::Key_Space:
489 tableClickedSlot(); 493 tableClickedSlot();
490 break; 494 break;
491 case Qt::Key_Escape: 495 case Qt::Key_Escape:
492 e->ignore(); 496 e->ignore();
493 break; 497 break;
494 default: 498 default:
495 break; 499 break;
496 } 500 }
497 501
498} 502}