summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdatepicker.cpp
Unidiff
Diffstat (limited to 'libkdepim/kdatepicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdatepicker.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp
index 7f352d6..25b4e81 100644
--- a/libkdepim/kdatepicker.cpp
+++ b/libkdepim/kdatepicker.cpp
@@ -224,266 +224,267 @@ KDatePicker::monthForwardClicked()
224 int day=temp.day(); 224 int day=temp.day();
225 // ----- 225 // -----
226 if(temp.month()==12) { 226 if(temp.month()==12) {
227 temp.setYMD(temp.year()+1, 1, 1); 227 temp.setYMD(temp.year()+1, 1, 1);
228 } else { 228 } else {
229 temp.setYMD(temp.year(), temp.month()+1, 1); 229 temp.setYMD(temp.year(), temp.month()+1, 1);
230 } 230 }
231 if(temp.daysInMonth()<day) { 231 if(temp.daysInMonth()<day) {
232 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 232 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
233 } else { 233 } else {
234 temp.setYMD(temp.year(), temp.month(), day); 234 temp.setYMD(temp.year(), temp.month(), day);
235 } 235 }
236 // assert(temp.isValid()); 236 // assert(temp.isValid());
237 setDate(temp); 237 setDate(temp);
238} 238}
239 239
240void 240void
241KDatePicker::monthBackwardClicked() 241KDatePicker::monthBackwardClicked()
242{ 242{
243 QDate temp=table->getDate(); 243 QDate temp=table->getDate();
244 int day=temp.day(); 244 int day=temp.day();
245 // ----- 245 // -----
246 if(temp.month()==1) 246 if(temp.month()==1)
247 { 247 {
248 temp.setYMD(temp.year()-1, 12, 1); 248 temp.setYMD(temp.year()-1, 12, 1);
249 } else { 249 } else {
250 temp.setYMD(temp.year(), temp.month()-1, 1); 250 temp.setYMD(temp.year(), temp.month()-1, 1);
251 } 251 }
252 if(temp.daysInMonth()<day) 252 if(temp.daysInMonth()<day)
253 { 253 {
254 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 254 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
255 } else { 255 } else {
256 temp.setYMD(temp.year(), temp.month(), day); 256 temp.setYMD(temp.year(), temp.month(), day);
257 } 257 }
258 // assert(temp.isValid()); 258 // assert(temp.isValid());
259 setDate(temp); 259 setDate(temp);
260} 260}
261 261
262void 262void
263KDatePicker::yearForwardClicked() 263KDatePicker::yearForwardClicked()
264{ 264{
265 QDate temp=table->getDate(); 265 QDate temp=table->getDate();
266 int day=temp.day(); 266 int day=temp.day();
267 // ----- 267 // -----
268 temp.setYMD(temp.year()+1, temp.month(), 1); 268 temp.setYMD(temp.year()+1, temp.month(), 1);
269 if(temp.daysInMonth()<day) 269 if(temp.daysInMonth()<day)
270 { 270 {
271 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 271 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
272 } else { 272 } else {
273 temp.setYMD(temp.year(), temp.month(), day); 273 temp.setYMD(temp.year(), temp.month(), day);
274 } 274 }
275 // assert(temp.isValid()); 275 // assert(temp.isValid());
276 setDate(temp); 276 setDate(temp);
277} 277}
278 278
279void 279void
280KDatePicker::yearBackwardClicked() 280KDatePicker::yearBackwardClicked()
281{ 281{
282 QDate temp=table->getDate(); 282 QDate temp=table->getDate();
283 int day=temp.day(); 283 int day=temp.day();
284 // ----- 284 // -----
285 temp.setYMD(temp.year()-1, temp.month(), 1); 285 temp.setYMD(temp.year()-1, temp.month(), 1);
286 if(temp.daysInMonth()<day) 286 if(temp.daysInMonth()<day)
287 { 287 {
288 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 288 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
289 } else { 289 } else {
290 temp.setYMD(temp.year(), temp.month(), day); 290 temp.setYMD(temp.year(), temp.month(), day);
291 } 291 }
292 // assert(temp.isValid()); 292 // assert(temp.isValid());
293 setDate(temp); 293 setDate(temp);
294} 294}
295 295
296void 296void
297KDatePicker::selectMonthClicked() 297KDatePicker::selectMonthClicked()
298{ 298{
299 int month; 299 int month;
300 KPopupFrame* popup = new KPopupFrame(this); 300 KPopupFrame* popup = new KPopupFrame(this);
301 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); 301 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup);
302 // ----- 302 // -----
303 picker->resize(picker->sizeHint()); 303 picker->resize(picker->sizeHint());
304 popup->setMainWidget(picker); 304 popup->setMainWidget(picker);
305 picker->setFocus(); 305 picker->setFocus();
306 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 306 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
307 if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height())))) 307 if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height()))))
308 { 308 {
309 QDate date; 309 QDate date;
310 int day; 310 int day;
311 // ----- 311 // -----
312 month=picker->getResult(); 312 month=picker->getResult();
313 date=table->getDate(); 313 date=table->getDate();
314 day=date.day(); 314 day=date.day();
315 // ----- construct a valid date in this month: 315 // ----- construct a valid date in this month:
316 date.setYMD(date.year(), month, 1); 316 date.setYMD(date.year(), month, 1);
317 date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); 317 date.setYMD(date.year(), month, QMIN(day, date.daysInMonth()));
318 // ----- set this month 318 // ----- set this month
319 setDate(date); 319 setDate(date);
320 } else { 320 } else {
321 KNotifyClient::beep(); 321 KNotifyClient::beep();
322 } 322 }
323 delete popup; 323 delete popup;
324} 324}
325 325
326void 326void
327KDatePicker::selectYearClicked() 327KDatePicker::selectYearClicked()
328{ 328{
329 int year; 329 int year;
330 KPopupFrame* popup = new KPopupFrame(this); 330 KPopupFrame* popup = new KPopupFrame(this);
331 KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup); 331 KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup);
332 // ----- 332 // -----
333 picker->resize(picker->sizeHint()); 333 picker->resize(picker->sizeHint());
334 popup->setMainWidget(picker); 334 popup->setMainWidget(picker);
335 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 335 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
336 picker->setFocus(); 336 picker->setFocus();
337 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) 337 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
338 { 338 {
339 QDate date; 339 QDate date;
340 int day; 340 int day;
341 // ----- 341 // -----
342 year=picker->getYear(); 342 year=picker->getYear();
343 date=table->getDate(); 343 date=table->getDate();
344 day=date.day(); 344 day=date.day();
345 // ----- construct a valid date in this month: 345 // ----- construct a valid date in this month:
346 date.setYMD(year, date.month(), 1); 346 date.setYMD(year, date.month(), 1);
347 date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); 347 date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
348 // ----- set this month 348 // ----- set this month
349 setDate(date); 349 setDate(date);
350 } else { 350 } else {
351 KNotifyClient::beep(); 351 KNotifyClient::beep();
352 } 352 }
353 delete popup; 353 delete popup;
354} 354}
355 355
356void 356void
357KDatePicker::setEnabled(bool enable) 357KDatePicker::setEnabled(bool enable)
358{ 358{
359 QWidget *widgets[]= { 359 QWidget *widgets[]= {
360 yearForward, yearBackward, monthForward, monthBackward, 360 yearForward, yearBackward, monthForward, monthBackward,
361 selectMonth, selectYear, 361 selectMonth, selectYear,
362 lineDate, table }; 362 lineDate, table };
363 const int Size=sizeof(widgets)/sizeof(widgets[0]); 363 const int Size=sizeof(widgets)/sizeof(widgets[0]);
364 int count; 364 int count;
365 // ----- 365 // -----
366 for(count=0; count<Size; ++count) 366 for(count=0; count<Size; ++count)
367 { 367 {
368 widgets[count]->setEnabled(enable); 368 widgets[count]->setEnabled(enable);
369 } 369 }
370} 370}
371 371
372void 372void
373KDatePicker::lineEnterPressed() 373KDatePicker::lineEnterPressed()
374{ 374{
375 QDate temp; 375 QDate temp;
376 // ----- 376 // -----
377 temp = lineDate->date(); 377 temp = lineDate->date();
378 //if(val->date(line->text(), temp)==QValidator::Acceptable) 378 //if(val->date(line->text(), temp)==QValidator::Acceptable)
379 //{ 379 //{
380 emit(dateEntered(temp)); 380 emit(dateEntered(temp));
381 setDate(temp); 381 setDate(temp);
382 // } else { 382 // } else {
383// KNotifyClient::beep(); 383// KNotifyClient::beep();
384// } 384// }
385} 385}
386 386
387QSize 387QSize
388KDatePicker::sizeHint() const 388KDatePicker::sizeHint() const
389{ 389{
390 QSize tableSize=table->sizeHint(); 390 QSize tableSize=table->sizeHint();
391 QWidget *buttons[]={ 391 QWidget *buttons[]={
392 yearBackward, 392 yearBackward,
393 monthBackward, 393 monthBackward,
394 selectMonth, 394 selectMonth,
395 selectYear, 395 selectYear,
396 monthForward, 396 monthForward,
397 yearForward }; 397 yearForward };
398 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 398 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
399 QSize sizes[NoOfButtons]; 399 QSize sizes[NoOfButtons];
400 int cx=0, cy=0, count; 400 int cx=0, cy=0, count;
401 // ----- store the size hints: 401 // ----- store the size hints:
402 for(count=0; count<NoOfButtons; ++count) 402 for(count=0; count<NoOfButtons; ++count)
403 { 403 {
404 sizes[count]=buttons[count]->sizeHint(); 404 sizes[count]=buttons[count]->sizeHint();
405 if(buttons[count]==selectMonth) 405 if(buttons[count]==selectMonth)
406 { 406 {
407 cx+=maxMonthRect.width()+15; 407 cx+=maxMonthRect.width()+15;
408 } else { 408 } else {
409 cx+=sizes[count].width()+15; 409 cx+=sizes[count].width()+15;
410 } 410 }
411 cy=QMAX(sizes[count].height(), cy); 411 cy=QMAX(sizes[count].height(), cy);
412 } 412 }
413 // ----- calculate width hint: 413 // ----- calculate width hint:
414 cx=QMAX(cx, tableSize.width()); // line edit ignored 414 cx=QMAX(cx, tableSize.width()); // line edit ignored
415 if ( cx > QApplication::desktop()->width() -5 ) 415 if ( cx > QApplication::desktop()->width() -5 )
416 cx = QApplication::desktop()->width() -5; 416 cx = QApplication::desktop()->width() -5;
417 // ----- calculate height hint: 417 // ----- calculate height hint:
418 cy+=tableSize.height()+lineDate->sizeHint().height(); 418 cy+=tableSize.height()+lineDate->sizeHint().height();
419 419
420 return QSize(cx, cy); 420 return QSize(cx, cy);
421} 421}
422 422
423void 423void
424KDatePicker::setFontSize(int s) 424KDatePicker::setFontSize(int s)
425{ 425{
426 QWidget *buttons[]= { 426 QWidget *buttons[]= {
427 // yearBackward, 427 // yearBackward,
428 // monthBackward, 428 // monthBackward,
429 selectMonth, 429 selectMonth,
430 selectYear, 430 selectYear,
431 // monthForward, 431 // monthForward,
432 // yearForward 432 // yearForward
433 }; 433 };
434 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 434 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
435 int count; 435 int count;
436 QFont font; 436 QFont font;
437 QRect r; 437 QRect r;
438 // ----- 438 // -----
439 fontsize=s; 439 fontsize=s;
440 for(count=0; count<NoOfButtons; ++count) 440 for(count=0; count<NoOfButtons; ++count)
441 { 441 {
442 font=buttons[count]->font(); 442 font=buttons[count]->font();
443 font.setPointSize(s); 443 font.setPointSize(s);
444 buttons[count]->setFont(font); 444 buttons[count]->setFont(font);
445 } 445 }
446 QFontMetrics metrics(selectMonth->fontMetrics()); 446 QFontMetrics metrics(selectMonth->fontMetrics());
447 for(int i=1; i <= 12; ++i) 447 for(int i=1; i <= 12; ++i)
448 { // maxMonthRect is used by sizeHint() 448 { // maxMonthRect is used by sizeHint()
449 r=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); 449 r=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
450 maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); 450 maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width()));
451 maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); 451 maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height()));
452 } 452 }
453 table->setFontSize(s); 453 table->setFontSize(s);
454} 454}
455 455
456void KDatePicker::virtual_hook( int id, void* data ) 456void KDatePicker::virtual_hook( int id, void* data )
457{ /*BASE::virtual_hook( id, data );*/ } 457{ /*BASE::virtual_hook( id, data );*/ }
458 458
459void KDatePicker::keyPressEvent ( QKeyEvent * e ) 459void KDatePicker::keyPressEvent ( QKeyEvent * e )
460{ 460{
461 switch ( e->key() ) { 461 switch ( e->key() ) {
462 case Qt::Key_Right: 462 case Qt::Key_Right:
463 monthForwardClicked(); 463 monthForwardClicked();
464 break; 464 break;
465 case Qt::Key_Left: 465 case Qt::Key_Left:
466 monthBackwardClicked(); 466 monthBackwardClicked();
467 break; 467 break;
468 468
469 case Qt::Key_Down: 469 case Qt::Key_Down:
470 yearForwardClicked(); 470 yearForwardClicked();
471 471
472 break; 472 break;
473 473
474 case Qt::Key_Up: 474 case Qt::Key_Up:
475 yearBackwardClicked(); 475 yearBackwardClicked();
476 break; 476 break;
477 477
478 case Qt::Key_Return: 478 case Qt::Key_Return:
479 case Qt::Key_Enter: 479 case Qt::Key_Enter:
480 case Qt::Key_Space:
480 tableClickedSlot(); 481 tableClickedSlot();
481 break; 482 break;
482 case Qt::Key_Escape: 483 case Qt::Key_Escape:
483 e->ignore(); 484 e->ignore();
484 break; 485 break;
485 default: 486 default:
486 break; 487 break;
487 } 488 }
488 489
489} 490}