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