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