author | zautrix <zautrix> | 2005-01-16 08:49:00 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-16 08:49:00 (UTC) |
commit | 62ff81d5d292ddf3c6032b48f27a6daedf6a6cb0 (patch) (unidiff) | |
tree | ef89d1577b47959c172e644701bf9dc7541c2987 | |
parent | 32795d059fa22cc9fd213db4b4d87e30866a7cb9 (diff) | |
download | kdepimpi-62ff81d5d292ddf3c6032b48f27a6daedf6a6cb0.zip kdepimpi-62ff81d5d292ddf3c6032b48f27a6daedf6a6cb0.tar.gz kdepimpi-62ff81d5d292ddf3c6032b48f27a6daedf6a6cb0.tar.bz2 |
beter time edit
-rw-r--r-- | bin/kdepim/WhatsNew.txt | 5 | ||||
-rw-r--r-- | korganizer/koeditorgeneralevent.cpp | 17 | ||||
-rw-r--r-- | korganizer/koeditorgeneraltodo.cpp | 12 | ||||
-rw-r--r-- | korganizer/ktimeedit.cpp | 106 | ||||
-rw-r--r-- | korganizer/ktimeedit.h | 3 | ||||
-rw-r--r-- | microkde/kdecore/klocale.cpp | 4 |
6 files changed, 33 insertions, 114 deletions
diff --git a/bin/kdepim/WhatsNew.txt b/bin/kdepim/WhatsNew.txt index c8293b2..5d8ef41 100644 --- a/bin/kdepim/WhatsNew.txt +++ b/bin/kdepim/WhatsNew.txt | |||
@@ -18,2 +18,7 @@ the incoming filter settings can be used. | |||
18 | An example can be found in the SyncHowTo. | 18 | An example can be found in the SyncHowTo. |
19 | |||
20 | KO/Pi: | ||
21 | The timeedit input has a pulldown list for times. | ||
22 | If opened, this pulldown list should now has the right time highlighted. | ||
23 | |||
19 | 24 | ||
diff --git a/korganizer/koeditorgeneralevent.cpp b/korganizer/koeditorgeneralevent.cpp index fc5be71..30b792b 100644 --- a/korganizer/koeditorgeneralevent.cpp +++ b/korganizer/koeditorgeneralevent.cpp | |||
@@ -396,19 +396,2 @@ bool KOEditorGeneralEvent::validateInput() | |||
396 | { | 396 | { |
397 | // kdDebug() << "KOEditorGeneralEvent::validateInput()" << endl; | ||
398 | |||
399 | if (!mNoTimeButton->isChecked()) { | ||
400 | if (!mStartTimeEdit->inputIsValid()) { | ||
401 | KMessageBox::sorry( 0, | ||
402 | i18n("Please specify a valid start time, for example '%1'.") | ||
403 | .arg( KGlobal::locale()->formatTime( QTime::currentTime() ) ) ); | ||
404 | return false; | ||
405 | } | ||
406 | |||
407 | if (!mEndTimeEdit->inputIsValid()) { | ||
408 | KMessageBox::sorry( 0, | ||
409 | i18n("Please specify a valid end time, for example '%1'.") | ||
410 | .arg( KGlobal::locale()->formatTime( QTime::currentTime() ) ) ); | ||
411 | return false; | ||
412 | } | ||
413 | } | ||
414 | 397 | ||
diff --git a/korganizer/koeditorgeneraltodo.cpp b/korganizer/koeditorgeneraltodo.cpp index 7db7da0..158a7d3 100644 --- a/korganizer/koeditorgeneraltodo.cpp +++ b/korganizer/koeditorgeneraltodo.cpp | |||
@@ -386,8 +386,2 @@ bool KOEditorGeneralTodo::validateInput() | |||
386 | } | 386 | } |
387 | if (mTimeButton->isChecked()) { | ||
388 | if (!mDueTimeEdit->inputIsValid()) { | ||
389 | KMessageBox::sorry(0,i18n("Please specify a valid due time.")); | ||
390 | return false; | ||
391 | } | ||
392 | } | ||
393 | } | 387 | } |
@@ -399,8 +393,2 @@ bool KOEditorGeneralTodo::validateInput() | |||
399 | } | 393 | } |
400 | if (mTimeButton->isChecked()) { | ||
401 | if (!mStartTimeEdit->inputIsValid()) { | ||
402 | KMessageBox::sorry(0,i18n("Please specify a valid start time.")); | ||
403 | return false; | ||
404 | } | ||
405 | } | ||
406 | } | 394 | } |
diff --git a/korganizer/ktimeedit.cpp b/korganizer/ktimeedit.cpp index f5a1c50..5222ac9 100644 --- a/korganizer/ktimeedit.cpp +++ b/korganizer/ktimeedit.cpp | |||
@@ -27,2 +27,3 @@ | |||
27 | #include <qlineedit.h> | 27 | #include <qlineedit.h> |
28 | #include <qlistbox.h> | ||
28 | #include <qapplication.h> | 29 | #include <qapplication.h> |
@@ -41,40 +42,2 @@ | |||
41 | // Mostly locale aware. Author: David Faure <faure@kde.org> | 42 | // Mostly locale aware. Author: David Faure <faure@kde.org> |
42 | class KOTimeValidator : public QValidator | ||
43 | { | ||
44 | public: | ||
45 | KOTimeValidator(QWidget* parent, const char* name=0) : QValidator(parent, name) {} | ||
46 | |||
47 | virtual State validate(QString& str, int& /*cursorPos*/) const | ||
48 | { | ||
49 | return Acceptable; | ||
50 | bool ok = false; | ||
51 | // TODO use KLocale::WithoutSeconds in HEAD | ||
52 | /*QTime time =*/ KGlobal::locale()->readTime(str, &ok); | ||
53 | if ( ok ) | ||
54 | return Acceptable; | ||
55 | // readTime doesn't help knowing when the string is "Intermediate". | ||
56 | int length = str.length(); | ||
57 | if ( !str ) // empty string? | ||
58 | return Invalid; // there should always be a ':' in it, right? | ||
59 | // HACK. Not fully locale aware etc. (esp. the separator is '.' in sv_SE...) | ||
60 | QChar sep = ':'; | ||
61 | // I want to allow "HH:", ":MM" and ":" to make editing easier | ||
62 | if ( str[0] == sep ) | ||
63 | { | ||
64 | if ( length == 1 ) // just ":" | ||
65 | return Intermediate; | ||
66 | QString minutes = str.mid(1); | ||
67 | int m = minutes.toInt(&ok); | ||
68 | if ( ok && m >= 0 && m < 60 ) | ||
69 | return Intermediate; | ||
70 | } else if ( str.at(str.length()-1) == sep ) | ||
71 | { | ||
72 | QString hours = str.left(length-1); | ||
73 | int h = hours.toInt(&ok); | ||
74 | if ( ok && h >= 0 && h < 24 ) | ||
75 | return Intermediate; | ||
76 | } | ||
77 | return Invalid; | ||
78 | } | ||
79 | }; | ||
80 | 43 | ||
@@ -87,3 +50,2 @@ KOTimeEdit::KOTimeEdit(QWidget *parent, QTime qt, const char *name) | |||
87 | setInsertionPolicy(NoInsertion); | 50 | setInsertionPolicy(NoInsertion); |
88 | setValidator( new KOTimeValidator( this ) ); | ||
89 | mFlagKeyPressed = false; | 51 | mFlagKeyPressed = false; |
@@ -147,7 +109,3 @@ QTime KOTimeEdit::getTime() const | |||
147 | { | 109 | { |
148 | //kdDebug(5850) << "KOTimeEdit::getTime(), currentText() = " << currentText() << endl; | 110 | return KGlobal::locale()->readTime(currentText()); |
149 | // TODO use KLocale::WithoutSeconds in HEAD | ||
150 | QTime time = KGlobal::locale()->readTime(currentText()); | ||
151 | // kdDebug(5850) << "KOTimeEdit::getTime(): " << time.toString() << endl; | ||
152 | return time; | ||
153 | } | 111 | } |
@@ -167,4 +125,2 @@ void KOTimeEdit::setTime(QTime newTime) | |||
167 | { | 125 | { |
168 | kdDebug(5850) << "KOTimeEdit::setTime(): " << newTime.toString() << endl; | ||
169 | |||
170 | mTime = newTime; | 126 | mTime = newTime; |
@@ -381,2 +337,3 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e) | |||
381 | case Key_Backspace: | 337 | case Key_Backspace: |
338 | qDebug("+++++++++++back "); | ||
382 | if ( cpos > 0) { | 339 | if ( cpos > 0) { |
@@ -391,2 +348,3 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e) | |||
391 | changedText(); | 348 | changedText(); |
349 | qDebug("---------back "); | ||
392 | } | 350 | } |
@@ -487,29 +445,17 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e) | |||
487 | void KOTimeEdit::updateText() | 445 | void KOTimeEdit::updateText() |
488 | { | 446 | { |
489 | // kdDebug(5850) << "KOTimeEdit::updateText() " << endl | 447 | listBox()->blockSignals( true ); |
490 | QString s = KGlobal::locale()->formatTime(mTime); | 448 | blockSignals( true ); |
491 | // Set the text but without emitting signals, nor losing the cursor position | 449 | QString s = KGlobal::locale()->formatTime(mTime); |
492 | QLineEdit *line = lineEdit(); | 450 | // Set the text but without emitting signals, nor losing the cursor position |
493 | line->blockSignals(true); | 451 | QLineEdit *line = lineEdit(); |
494 | int pos = line->cursorPosition(); | 452 | line->blockSignals(true); |
495 | // qDebug(" settext *%s* ", s.latin1()); | 453 | int pos = line->cursorPosition(); |
496 | line->setText(s); | ||
497 | // line->setCursorPosition(pos); | ||
498 | // line->blockSignals(false); | ||
499 | |||
500 | // kdDebug(5850) << "KOTimeEdit::updateText(): " << s << endl; | ||
501 | |||
502 | if (!mTime.minute() % 15) { | ||
503 | setCurrentItem((mTime.hour()*4)+(mTime.minute()/15)); | 454 | setCurrentItem((mTime.hour()*4)+(mTime.minute()/15)); |
504 | } | 455 | line->setText(s); |
505 | line->setCursorPosition(pos); | 456 | line->setCursorPosition(pos); |
506 | line->blockSignals(false); | 457 | line->blockSignals(false); |
507 | 458 | blockSignals( false ); | |
508 | } | 459 | listBox()->blockSignals( false ); |
509 | 460 | ||
510 | bool KOTimeEdit::inputIsValid() const | ||
511 | { | ||
512 | int cursorPos = lineEdit()->cursorPosition(); | ||
513 | QString str = currentText(); | ||
514 | return validator()->validate( str, cursorPos ) == QValidator::Acceptable; | ||
515 | } | 461 | } |
@@ -518,11 +464,11 @@ void KOTimeEdit::changedText() | |||
518 | { | 464 | { |
519 | //kdDebug(5850) << "KOTimeEdit::changedText()" << endl; | 465 | int pos = lineEdit()->cursorPosition(); |
520 | if ( inputIsValid() ) | 466 | mTime = getTime(); |
521 | { | 467 | blockSignals( true ); |
522 | int pos = lineEdit()->cursorPosition(); | 468 | QString text = lineEdit()->text(); |
523 | mTime = getTime(); | 469 | setCurrentItem((mTime.hour()*4)+(mTime.minute()/15)); |
524 | // updateText(); | 470 | lineEdit()->setText(text); |
525 | emit timeChanged(mTime); | 471 | blockSignals( false ); |
526 | lineEdit()->setCursorPosition(pos); | 472 | emit timeChanged(mTime); |
527 | } | 473 | lineEdit()->setCursorPosition(pos); |
528 | } | 474 | } |
diff --git a/korganizer/ktimeedit.h b/korganizer/ktimeedit.h index 7923070..b3d842d 100644 --- a/korganizer/ktimeedit.h +++ b/korganizer/ktimeedit.h | |||
@@ -60,5 +60,2 @@ class KOTimeEdit : public QComboBox | |||
60 | 60 | ||
61 | /** return true if input is a valid time and false if not */ | ||
62 | bool inputIsValid() const; | ||
63 | |||
64 | signals: | 61 | signals: |
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp index d7e384c..7f31ab1 100644 --- a/microkde/kdecore/klocale.cpp +++ b/microkde/kdecore/klocale.cpp | |||
@@ -564,5 +564,5 @@ QTime KLocale::readTime(const QString &intstr, bool *ok) const | |||
564 | QTime _time; | 564 | QTime _time; |
565 | _time = readTime(intstr, true, ok); | 565 | _time = readTime(intstr, false, ok); |
566 | if (_time.isValid()) return _time; | 566 | if (_time.isValid()) return _time; |
567 | return readTime(intstr, false, ok); | 567 | return readTime(intstr, true, ok); |
568 | } | 568 | } |