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