-rw-r--r-- | libkdepim/kdateedit.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp index 2c78ea3..946fc0d 100644 --- a/libkdepim/kdateedit.cpp +++ b/libkdepim/kdateedit.cpp | |||
@@ -37,132 +37,132 @@ | |||
37 | #include <knotifyclient.h> | 37 | #include <knotifyclient.h> |
38 | #include <qpalette.h> | 38 | #include <qpalette.h> |
39 | 39 | ||
40 | #include "kdateedit.h" | 40 | #include "kdateedit.h" |
41 | //#include "kdateedit.moc" | 41 | //#include "kdateedit.moc" |
42 | 42 | ||
43 | KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) | 43 | KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) |
44 | : QHBox(parent, name) | 44 | : QHBox(parent, name) |
45 | { | 45 | { |
46 | dateFormShort = true; | 46 | dateFormShort = true; |
47 | withoutDp = withoutDP; | 47 | withoutDp = withoutDP; |
48 | mDateEdit = new QLineEdit(this); | 48 | mDateEdit = new QLineEdit(this); |
49 | mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); | 49 | mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); |
50 | setFocusProxy(mDateEdit); | 50 | setFocusProxy(mDateEdit); |
51 | mDateEdit->installEventFilter(this); | 51 | mDateEdit->installEventFilter(this); |
52 | 52 | ||
53 | // Highlight Background and Textcolor | 53 | // Highlight Background and Textcolor |
54 | QPalette palette = QWidget::palette(); | 54 | QPalette palette = QWidget::palette(); |
55 | unsigned char red, green, blue; | 55 | unsigned char red, green, blue; |
56 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; | 56 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; |
57 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; | 57 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; |
58 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; | 58 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; |
59 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); | 59 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); |
60 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); | 60 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); |
61 | mDateEdit->setPalette( palette ); | 61 | mDateEdit->setPalette( palette ); |
62 | 62 | ||
63 | if ( withoutDP ) { | 63 | if ( withoutDP ) { |
64 | mDateFrame = 0; | 64 | mDateFrame = 0; |
65 | mDateButton = 0; | 65 | mDateButton = 0; |
66 | mDatePicker = 0; | 66 | mDatePicker = 0; |
67 | } else { | 67 | } else { |
68 | QPixmap pixmap = SmallIcon("smallcal"); | 68 | QPixmap pixmap = SmallIcon("smallcal"); |
69 | mDateButton = new QPushButton(this); | 69 | mDateButton = new QPushButton(this); |
70 | mDateButton->setPixmap(pixmap); | 70 | mDateButton->setPixmap(pixmap); |
71 | 71 | ||
72 | mDateFrame = new QVBox(0,0,WType_Popup); | 72 | mDateFrame = new QVBox(0,0,WType_Popup); |
73 | // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); | 73 | // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); |
74 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); | 74 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); |
75 | mDateFrame->setLineWidth(3); | 75 | mDateFrame->setLineWidth(3); |
76 | mDateFrame->hide(); | 76 | mDateFrame->hide(); |
77 | 77 | ||
78 | mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); | 78 | mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); |
79 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); | 79 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); |
80 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); | 80 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); |
81 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); | 81 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); |
82 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); | 82 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); |
83 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); | 83 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); |
84 | connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); | 84 | connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); |
85 | 85 | mDateButton->setFocusPolicy( QWidget::NoFocus ); | |
86 | //mDateFrame->resize( 400, 300 ); | 86 | //mDateFrame->resize( 400, 300 ); |
87 | 87 | ||
88 | } | 88 | } |
89 | connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); | 89 | connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); |
90 | connect(mDateEdit,SIGNAL(textChanged(const QString &)), | 90 | connect(mDateEdit,SIGNAL(textChanged(const QString &)), |
91 | SLOT(textChanged(const QString &))); | 91 | SLOT(textChanged(const QString &))); |
92 | 92 | ||
93 | // Create the keyword list. This will be used to match against when the user | 93 | // Create the keyword list. This will be used to match against when the user |
94 | // enters information. | 94 | // enters information. |
95 | mKeywordMap[i18n("tomorrow")] = 1; | 95 | mKeywordMap[i18n("tomorrow")] = 1; |
96 | mKeywordMap[i18n("today")] = 0; | 96 | mKeywordMap[i18n("today")] = 0; |
97 | mKeywordMap[i18n("yesterday")] = -1; | 97 | mKeywordMap[i18n("yesterday")] = -1; |
98 | 98 | ||
99 | /* | 99 | /* |
100 | * This loop uses some math tricks to figure out the offset in days | 100 | * This loop uses some math tricks to figure out the offset in days |
101 | * to the next date the given day of the week occurs. There | 101 | * to the next date the given day of the week occurs. There |
102 | * are two cases, that the new day is >= the current day, which means | 102 | * are two cases, that the new day is >= the current day, which means |
103 | * the new day has not occured yet or that the new day < the current day, | 103 | * the new day has not occured yet or that the new day < the current day, |
104 | * which means the new day is already passed (so we need to find the | 104 | * which means the new day is already passed (so we need to find the |
105 | * day in the next week). | 105 | * day in the next week). |
106 | */ | 106 | */ |
107 | QString dayName; | 107 | QString dayName; |
108 | int currentDay = QDate::currentDate().dayOfWeek(); | 108 | int currentDay = QDate::currentDate().dayOfWeek(); |
109 | for (int i = 1; i <= 7; ++i) | 109 | for (int i = 1; i <= 7; ++i) |
110 | { | 110 | { |
111 | dayName = KGlobal::locale()->weekDayName(i).lower(); | 111 | dayName = KGlobal::locale()->weekDayName(i).lower(); |
112 | if (i >= currentDay) | 112 | if (i >= currentDay) |
113 | mKeywordMap[dayName] = i - currentDay; | 113 | mKeywordMap[dayName] = i - currentDay; |
114 | else | 114 | else |
115 | mKeywordMap[dayName] = 7 - currentDay + i; | 115 | mKeywordMap[dayName] = 7 - currentDay + i; |
116 | } | 116 | } |
117 | 117 | ||
118 | mTextChanged = false; | 118 | mTextChanged = false; |
119 | mHandleInvalid = false; | 119 | mHandleInvalid = false; |
120 | QWidget::setTabOrder( mDateEdit, mDateButton ); | 120 | // QWidget::setTabOrder( mDateEdit, mDateButton ); |
121 | } | 121 | } |
122 | 122 | ||
123 | KDateEdit::~KDateEdit() | 123 | KDateEdit::~KDateEdit() |
124 | { | 124 | { |
125 | delete mDateFrame; | 125 | delete mDateFrame; |
126 | } | 126 | } |
127 | void KDateEdit::clear() | 127 | void KDateEdit::clear() |
128 | { | 128 | { |
129 | bool b = mDateEdit->signalsBlocked(); | 129 | bool b = mDateEdit->signalsBlocked(); |
130 | mDateEdit->blockSignals(true); | 130 | mDateEdit->blockSignals(true); |
131 | mDateEdit->setText(""); | 131 | mDateEdit->setText(""); |
132 | mDateEdit->blockSignals(b); | 132 | mDateEdit->blockSignals(b); |
133 | } | 133 | } |
134 | void KDateEdit::setDate(QDate newDate) | 134 | void KDateEdit::setDate(QDate newDate) |
135 | { | 135 | { |
136 | if (!newDate.isValid() && !mHandleInvalid) | 136 | if (!newDate.isValid() && !mHandleInvalid) |
137 | return; | 137 | return; |
138 | if ( readDate() == newDate ) | 138 | if ( readDate() == newDate ) |
139 | return; | 139 | return; |
140 | QString dateString = ""; | 140 | QString dateString = ""; |
141 | if(newDate.isValid()) | 141 | if(newDate.isValid()) |
142 | dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); | 142 | dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); |
143 | 143 | ||
144 | mTextChanged = false; | 144 | mTextChanged = false; |
145 | 145 | ||
146 | // We do not want to generate a signal here, since we explicity setting | 146 | // We do not want to generate a signal here, since we explicity setting |
147 | // the date | 147 | // the date |
148 | bool b = mDateEdit->signalsBlocked(); | 148 | bool b = mDateEdit->signalsBlocked(); |
149 | mDateEdit->blockSignals(true); | 149 | mDateEdit->blockSignals(true); |
150 | mDateEdit->setText(dateString); | 150 | mDateEdit->setText(dateString); |
151 | mDateEdit->blockSignals(b); | 151 | mDateEdit->blockSignals(b); |
152 | } | 152 | } |
153 | 153 | ||
154 | void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) | 154 | void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) |
155 | { | 155 | { |
156 | QString dateForm = dateFormShort ? | 156 | QString dateForm = dateFormShort ? |
157 | KGlobal::locale()->dateFormatShort() : | 157 | KGlobal::locale()->dateFormatShort() : |
158 | KGlobal::locale()->dateFormat(); | 158 | KGlobal::locale()->dateFormat(); |
159 | 159 | ||
160 | int begin = dateForm.find("%"); | 160 | int begin = dateForm.find("%"); |
161 | int space = 0; | 161 | int space = 0; |
162 | int allStrLength = 0; | 162 | int allStrLength = 0; |
163 | int strLength = 0; | 163 | int strLength = 0; |
164 | int repeat = 0; | 164 | int repeat = 0; |
165 | 165 | ||
166 | // witch? Day, Month or Year switch? | 166 | // witch? Day, Month or Year switch? |
167 | while(1){ | 167 | while(1){ |
168 | switch ( dateForm.at(begin + 1).latin1() ) | 168 | switch ( dateForm.at(begin + 1).latin1() ) |
@@ -417,82 +417,84 @@ void KDateEdit::lineEnterPressed() | |||
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 ( isVisible() ) | 429 | if ( isVisible() ) |
430 | if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) { | 430 | if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) { |
431 | setDate( QDate::currentDate() ); | 431 | setDate( QDate::currentDate() ); |
432 | emit dateChanged( QDate::currentDate() ); | 432 | emit dateChanged( QDate::currentDate() ); |
433 | } | 433 | } |
434 | } | 434 | } |
435 | } | 435 | } |
436 | } | 436 | } |
437 | } | 437 | } |
438 | 438 | ||
439 | bool KDateEdit::inputIsValid() | 439 | bool KDateEdit::inputIsValid() |
440 | { | 440 | { |
441 | return readDate().isValid(); | 441 | return readDate().isValid(); |
442 | } | 442 | } |
443 | 443 | ||
444 | QDate KDateEdit::readDate() const | 444 | QDate KDateEdit::readDate() const |
445 | { | 445 | { |
446 | QString text = mDateEdit->text(); | 446 | QString text = mDateEdit->text(); |
447 | QDate date; | 447 | QDate date; |
448 | 448 | ||
449 | if (mKeywordMap.contains(text.lower())) | 449 | if (mKeywordMap.contains(text.lower())) |
450 | { | 450 | { |
451 | date = QDate::currentDate().addDays(mKeywordMap[text.lower()]); | 451 | date = QDate::currentDate().addDays(mKeywordMap[text.lower()]); |
452 | } | 452 | } |
453 | else | 453 | else |
454 | { | 454 | { |
455 | date = KGlobal::locale()->readDate(text); | 455 | date = KGlobal::locale()->readDate(text); |
456 | } | 456 | } |
457 | 457 | ||
458 | return date; | 458 | return date; |
459 | } | 459 | } |
460 | 460 | ||
461 | bool KDateEdit::eventFilter(QObject *, QEvent *e) | 461 | bool KDateEdit::eventFilter(QObject *, QEvent *e) |
462 | { | 462 | { |
463 | // 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 |
464 | // since we got focus | 464 | // since we got focus |
465 | if ((e->type() == QEvent::FocusOut) && mTextChanged) | 465 | if ((e->type() == QEvent::FocusOut) ) |
466 | { | 466 | { |
467 | lineEnterPressed(); | 467 | if ( mTextChanged ) { |
468 | mTextChanged = false; | 468 | lineEnterPressed(); |
469 | mTextChanged = false; | ||
470 | } | ||
469 | } | 471 | } |
470 | // switch dateFormShort by double klick with mouse | 472 | // switch dateFormShort by double klick with mouse |
471 | else if (e->type() == QEvent::MouseButtonDblClick) | 473 | else if (e->type() == QEvent::MouseButtonDblClick) |
472 | { | 474 | { |
473 | toggleDateFormat(); | 475 | toggleDateFormat(); |
474 | } | 476 | } |
475 | else if (e->type() == QEvent::FocusIn) | 477 | else if (e->type() == QEvent::FocusIn) |
476 | { | 478 | { |
477 | maxDay = readDate().day(); | 479 | maxDay = readDate().day(); |
478 | } | 480 | } |
479 | 481 | ||
480 | return false; | 482 | return false; |
481 | } | 483 | } |
482 | void KDateEdit::toggleDateFormat() | 484 | void KDateEdit::toggleDateFormat() |
483 | { | 485 | { |
484 | dateFormShort = ! dateFormShort; | 486 | dateFormShort = ! dateFormShort; |
485 | mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort)); | 487 | mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort)); |
486 | 488 | ||
487 | } | 489 | } |
488 | 490 | ||
489 | void KDateEdit::textChanged(const QString &) | 491 | void KDateEdit::textChanged(const QString &) |
490 | { | 492 | { |
491 | if(mHandleInvalid && mDateEdit->text().stripWhiteSpace().isEmpty()) { | 493 | if(mHandleInvalid && mDateEdit->text().stripWhiteSpace().isEmpty()) { |
492 | QDate date; //invalid date | 494 | QDate date; //invalid date |
493 | emit(dateChanged(date)); | 495 | emit(dateChanged(date)); |
494 | } else { | 496 | } else { |
495 | mTextChanged = true; | 497 | mTextChanged = true; |
496 | } | 498 | } |
497 | maxDay = readDate().day(); | 499 | maxDay = readDate().day(); |
498 | } | 500 | } |