summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdateedit.cpp
authorzautrix <zautrix>2005-02-09 13:22:06 (UTC)
committer zautrix <zautrix>2005-02-09 13:22:06 (UTC)
commitc3dd5bfd446b893a8b39ddec425a6cf8deff2261 (patch) (unidiff)
treed0dd74c17fd6101da1d6c403c85924c58bc1ac9b /libkdepim/kdateedit.cpp
parent940cdd0fd1349e7f8e53adff0595c1d946322ef1 (diff)
downloadkdepimpi-c3dd5bfd446b893a8b39ddec425a6cf8deff2261.zip
kdepimpi-c3dd5bfd446b893a8b39ddec425a6cf8deff2261.tar.gz
kdepimpi-c3dd5bfd446b893a8b39ddec425a6cf8deff2261.tar.bz2
fixes
Diffstat (limited to 'libkdepim/kdateedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdateedit.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp
index c4c0081..2c78ea3 100644
--- a/libkdepim/kdateedit.cpp
+++ b/libkdepim/kdateedit.cpp
@@ -365,132 +365,133 @@ void KDateEdit::keyPressEvent(QKeyEvent *e)
365 } 365 }
366 setDate(date, &cpos, Key_Down, dateFormShort); 366 setDate(date, &cpos, Key_Down, dateFormShort);
367 break; 367 break;
368 default: 368 default:
369 QHBox::keyPressEvent(e); 369 QHBox::keyPressEvent(e);
370 break; 370 break;
371 } // switch 371 } // switch
372 mDateEdit->setCursorPosition(cpos); 372 mDateEdit->setCursorPosition(cpos);
373} 373}
374 374
375void KDateEdit::setSelect( int from, int to ) 375void KDateEdit::setSelect( int from, int to )
376{ 376{
377// return; 377// return;
378 mDateEdit->setSelection( from , to ); 378 mDateEdit->setSelection( from , to );
379} 379}
380 380
381void KDateEdit::toggleDatePicker() 381void KDateEdit::toggleDatePicker()
382{ 382{
383 if( mDateFrame->isVisible() ) { 383 if( mDateFrame->isVisible() ) {
384 mDateFrame->hide(); 384 mDateFrame->hide();
385 } else { 385 } else {
386 QPoint tmpPoint = mapToGlobal(mDateButton->geometry().bottomRight()); 386 QPoint tmpPoint = mapToGlobal(mDateButton->geometry().bottomRight());
387 QSize datepickersize = mDatePicker->sizeHint(); 387 QSize datepickersize = mDatePicker->sizeHint();
388 388
389 if ( tmpPoint.x() < 7+datepickersize.width() ) tmpPoint.setX( 7+datepickersize.width() ); 389 if ( tmpPoint.x() < 7+datepickersize.width() ) tmpPoint.setX( 7+datepickersize.width() );
390 390
391 int h = QApplication::desktop()->height(); 391 int h = QApplication::desktop()->height();
392 392
393 if ( tmpPoint.y() + datepickersize.height() > h ) tmpPoint.setY( h - datepickersize.height() ); 393 if ( tmpPoint.y() + datepickersize.height() > h ) tmpPoint.setY( h - datepickersize.height() );
394 394
395 mDateFrame->setGeometry(tmpPoint.x()-datepickersize.width()-7, tmpPoint.y(), 395 mDateFrame->setGeometry(tmpPoint.x()-datepickersize.width()-7, tmpPoint.y(),
396 datepickersize.width()+2*mDateFrame->lineWidth(), datepickersize.height()+2*mDateFrame->lineWidth()); 396 datepickersize.width()+2*mDateFrame->lineWidth(), datepickersize.height()+2*mDateFrame->lineWidth());
397 397
398 QDate date = readDate(); 398 QDate date = readDate();
399 if(date.isValid()) { 399 if(date.isValid()) {
400 mDatePicker->setDate(date); 400 mDatePicker->setDate(date);
401 } else { 401 } else {
402 mDatePicker->setDate(QDate::currentDate()); 402 mDatePicker->setDate(QDate::currentDate());
403 } 403 }
404 mDateFrame->show(); 404 mDateFrame->show();
405 } 405 }
406} 406}
407 407
408 408
409void KDateEdit::lineEnterPressed() 409void KDateEdit::lineEnterPressed()
410{ 410{
411 QDate date = readDate(); 411 QDate date = readDate();
412 412
413 if(date.isValid()) 413 if(date.isValid())
414 { 414 {
415 // Update the edit. This is needed if the user has entered a 415 // Update the edit. This is needed if the user has entered a
416 // word rather than the actual date. 416 // word rather than the actual date.
417 setDate(date); 417 setDate(date);
418 emit(dateChanged(date)); 418 emit(dateChanged(date));
419 emit returnPressed(); 419 emit returnPressed();
420 } 420 }
421 else 421 else
422 { 422 {
423 if ( withoutDp ) { 423 if ( withoutDp ) {
424 KNotifyClient::beep(); 424 KNotifyClient::beep();
425 } else { 425 } else {
426 if ( !mDateEdit->text().isEmpty() ) { 426 if ( !mDateEdit->text().isEmpty() ) {
427 mTextChanged = false; 427 mTextChanged = false;
428 QString text = i18n( "You entered an invalid date!\n Will use current date instead." ); 428 QString text = i18n( "You entered an invalid date!\n Will use current date instead." );
429 if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) { 429 if ( isVisible() )
430 setDate( QDate::currentDate() ); 430 if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) {
431 emit dateChanged( QDate::currentDate() ); 431 setDate( QDate::currentDate() );
432 } 432 emit dateChanged( QDate::currentDate() );
433 }
433 } 434 }
434 } 435 }
435 } 436 }
436} 437}
437 438
438bool KDateEdit::inputIsValid() 439bool KDateEdit::inputIsValid()
439{ 440{
440 return readDate().isValid(); 441 return readDate().isValid();
441} 442}
442 443
443QDate KDateEdit::readDate() const 444QDate KDateEdit::readDate() const
444{ 445{
445 QString text = mDateEdit->text(); 446 QString text = mDateEdit->text();
446 QDate date; 447 QDate date;
447 448
448 if (mKeywordMap.contains(text.lower())) 449 if (mKeywordMap.contains(text.lower()))
449 { 450 {
450 date = QDate::currentDate().addDays(mKeywordMap[text.lower()]); 451 date = QDate::currentDate().addDays(mKeywordMap[text.lower()]);
451 } 452 }
452 else 453 else
453 { 454 {
454 date = KGlobal::locale()->readDate(text); 455 date = KGlobal::locale()->readDate(text);
455 } 456 }
456 457
457 return date; 458 return date;
458} 459}
459 460
460bool KDateEdit::eventFilter(QObject *, QEvent *e) 461bool KDateEdit::eventFilter(QObject *, QEvent *e)
461{ 462{
462 // We only process the focus out event if the text has changed 463 // We only process the focus out event if the text has changed
463 // since we got focus 464 // since we got focus
464 if ((e->type() == QEvent::FocusOut) && mTextChanged) 465 if ((e->type() == QEvent::FocusOut) && mTextChanged)
465 { 466 {
466 lineEnterPressed(); 467 lineEnterPressed();
467 mTextChanged = false; 468 mTextChanged = false;
468 } 469 }
469 // switch dateFormShort by double klick with mouse 470 // switch dateFormShort by double klick with mouse
470 else if (e->type() == QEvent::MouseButtonDblClick) 471 else if (e->type() == QEvent::MouseButtonDblClick)
471 { 472 {
472 toggleDateFormat(); 473 toggleDateFormat();
473 } 474 }
474 else if (e->type() == QEvent::FocusIn) 475 else if (e->type() == QEvent::FocusIn)
475 { 476 {
476 maxDay = readDate().day(); 477 maxDay = readDate().day();
477 } 478 }
478 479
479 return false; 480 return false;
480} 481}
481void KDateEdit::toggleDateFormat() 482void KDateEdit::toggleDateFormat()
482{ 483{
483 dateFormShort = ! dateFormShort; 484 dateFormShort = ! dateFormShort;
484 mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort)); 485 mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort));
485 486
486} 487}
487 488
488void KDateEdit::textChanged(const QString &) 489void KDateEdit::textChanged(const QString &)
489{ 490{
490 if(mHandleInvalid && mDateEdit->text().stripWhiteSpace().isEmpty()) { 491 if(mHandleInvalid && mDateEdit->text().stripWhiteSpace().isEmpty()) {
491 QDate date; //invalid date 492 QDate date; //invalid date
492 emit(dateChanged(date)); 493 emit(dateChanged(date));
493 } else { 494 } else {
494 mTextChanged = true; 495 mTextChanged = true;
495 } 496 }
496 maxDay = readDate().day(); 497 maxDay = readDate().day();