summaryrefslogtreecommitdiffabout
path: root/korganizer/ktimeedit.cpp
authorzautrix <zautrix>2005-01-16 08:49:00 (UTC)
committer zautrix <zautrix>2005-01-16 08:49:00 (UTC)
commit62ff81d5d292ddf3c6032b48f27a6daedf6a6cb0 (patch) (side-by-side diff)
treeef89d1577b47959c172e644701bf9dc7541c2987 /korganizer/ktimeedit.cpp
parent32795d059fa22cc9fd213db4b4d87e30866a7cb9 (diff)
downloadkdepimpi-62ff81d5d292ddf3c6032b48f27a6daedf6a6cb0.zip
kdepimpi-62ff81d5d292ddf3c6032b48f27a6daedf6a6cb0.tar.gz
kdepimpi-62ff81d5d292ddf3c6032b48f27a6daedf6a6cb0.tar.bz2
beter time edit
Diffstat (limited to 'korganizer/ktimeedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/ktimeedit.cpp106
1 files changed, 26 insertions, 80 deletions
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 @@
#include <qlineedit.h>
+#include <qlistbox.h>
#include <qapplication.h>
@@ -41,40 +42,2 @@
// Mostly locale aware. Author: David Faure <faure@kde.org>
-class KOTimeValidator : public QValidator
-{
-public:
- KOTimeValidator(QWidget* parent, const char* name=0) : QValidator(parent, name) {}
-
- virtual State validate(QString& str, int& /*cursorPos*/) const
- {
- return Acceptable;
- bool ok = false;
- // TODO use KLocale::WithoutSeconds in HEAD
- /*QTime time =*/ KGlobal::locale()->readTime(str, &ok);
- if ( ok )
- return Acceptable;
- // readTime doesn't help knowing when the string is "Intermediate".
- int length = str.length();
- if ( !str ) // empty string?
- return Invalid; // there should always be a ':' in it, right?
- // HACK. Not fully locale aware etc. (esp. the separator is '.' in sv_SE...)
- QChar sep = ':';
- // I want to allow "HH:", ":MM" and ":" to make editing easier
- if ( str[0] == sep )
- {
- if ( length == 1 ) // just ":"
- return Intermediate;
- QString minutes = str.mid(1);
- int m = minutes.toInt(&ok);
- if ( ok && m >= 0 && m < 60 )
- return Intermediate;
- } else if ( str.at(str.length()-1) == sep )
- {
- QString hours = str.left(length-1);
- int h = hours.toInt(&ok);
- if ( ok && h >= 0 && h < 24 )
- return Intermediate;
- }
- return Invalid;
- }
-};
@@ -87,3 +50,2 @@ KOTimeEdit::KOTimeEdit(QWidget *parent, QTime qt, const char *name)
setInsertionPolicy(NoInsertion);
- setValidator( new KOTimeValidator( this ) );
mFlagKeyPressed = false;
@@ -147,7 +109,3 @@ QTime KOTimeEdit::getTime() const
{
- //kdDebug(5850) << "KOTimeEdit::getTime(), currentText() = " << currentText() << endl;
- // TODO use KLocale::WithoutSeconds in HEAD
- QTime time = KGlobal::locale()->readTime(currentText());
- // kdDebug(5850) << "KOTimeEdit::getTime(): " << time.toString() << endl;
- return time;
+ return KGlobal::locale()->readTime(currentText());
}
@@ -167,4 +125,2 @@ void KOTimeEdit::setTime(QTime newTime)
{
- kdDebug(5850) << "KOTimeEdit::setTime(): " << newTime.toString() << endl;
-
mTime = newTime;
@@ -381,2 +337,3 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e)
case Key_Backspace:
+ qDebug("+++++++++++back ");
if ( cpos > 0) {
@@ -391,2 +348,3 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e)
changedText();
+ qDebug("---------back ");
}
@@ -487,29 +445,17 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e)
void KOTimeEdit::updateText()
-{
-// kdDebug(5850) << "KOTimeEdit::updateText() " << endl
- QString s = KGlobal::locale()->formatTime(mTime);
- // Set the text but without emitting signals, nor losing the cursor position
- QLineEdit *line = lineEdit();
- line->blockSignals(true);
- int pos = line->cursorPosition();
- // qDebug(" settext *%s* ", s.latin1());
- line->setText(s);
- // line->setCursorPosition(pos);
-// line->blockSignals(false);
-
-// kdDebug(5850) << "KOTimeEdit::updateText(): " << s << endl;
-
- if (!mTime.minute() % 15) {
+{
+ listBox()->blockSignals( true );
+ blockSignals( true );
+ QString s = KGlobal::locale()->formatTime(mTime);
+ // Set the text but without emitting signals, nor losing the cursor position
+ QLineEdit *line = lineEdit();
+ line->blockSignals(true);
+ int pos = line->cursorPosition();
setCurrentItem((mTime.hour()*4)+(mTime.minute()/15));
- }
- line->setCursorPosition(pos);
- line->blockSignals(false);
-
-}
+ line->setText(s);
+ line->setCursorPosition(pos);
+ line->blockSignals(false);
+ blockSignals( false );
+ listBox()->blockSignals( false );
-bool KOTimeEdit::inputIsValid() const
-{
- int cursorPos = lineEdit()->cursorPosition();
- QString str = currentText();
- return validator()->validate( str, cursorPos ) == QValidator::Acceptable;
}
@@ -518,11 +464,11 @@ void KOTimeEdit::changedText()
{
- //kdDebug(5850) << "KOTimeEdit::changedText()" << endl;
- if ( inputIsValid() )
- {
- int pos = lineEdit()->cursorPosition();
- mTime = getTime();
- // updateText();
- emit timeChanged(mTime);
- lineEdit()->setCursorPosition(pos);
- }
+ int pos = lineEdit()->cursorPosition();
+ mTime = getTime();
+ blockSignals( true );
+ QString text = lineEdit()->text();
+ setCurrentItem((mTime.hour()*4)+(mTime.minute()/15));
+ lineEdit()->setText(text);
+ blockSignals( false );
+ emit timeChanged(mTime);
+ lineEdit()->setCursorPosition(pos);
}