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