-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 |
4 files changed, 26 insertions, 112 deletions
diff --git a/korganizer/koeditorgeneralevent.cpp b/korganizer/koeditorgeneralevent.cpp index fc5be71..30b792b 100644 --- a/korganizer/koeditorgeneralevent.cpp +++ b/korganizer/koeditorgeneralevent.cpp @@ -365,80 +365,63 @@ void KOEditorGeneralEvent::setDuration() } if (minutediff){ catStr = i18n("1 min","%n min",minutediff); tmpStr += catStr; } } else tmpStr = ""; } } mDurationLabel->setText(tmpStr); } void KOEditorGeneralEvent::emitDateTimeStr() { KLocale *l = KGlobal::locale(); QString from,to; if (mNoTimeButton->isChecked()) { from = l->formatDate(mCurrStartDateTime.date()); to = l->formatDate(mCurrEndDateTime.date()); } else { from = l->formatDateTime(mCurrStartDateTime); to = l->formatDateTime(mCurrEndDateTime); } QString str = i18n("From: %1 To: %2 %3").arg(from).arg(to) .arg(mDurationLabel->text()); emit dateTimeStrChanged(str); } bool KOEditorGeneralEvent::validateInput() { -// kdDebug() << "KOEditorGeneralEvent::validateInput()" << endl; - - if (!mNoTimeButton->isChecked()) { - if (!mStartTimeEdit->inputIsValid()) { - KMessageBox::sorry( 0, - i18n("Please specify a valid start time, for example '%1'.") - .arg( KGlobal::locale()->formatTime( QTime::currentTime() ) ) ); - return false; - } - - if (!mEndTimeEdit->inputIsValid()) { - KMessageBox::sorry( 0, - i18n("Please specify a valid end time, for example '%1'.") - .arg( KGlobal::locale()->formatTime( QTime::currentTime() ) ) ); - return false; - } - } if (!mStartDateEdit->inputIsValid()) { KMessageBox::sorry( 0, i18n("Please specify a valid start date, for example '%1'.") .arg( KGlobal::locale()->formatDate( QDate::currentDate() ) ) ); return false; } if (!mEndDateEdit->inputIsValid()) { KMessageBox::sorry( 0, i18n("Please specify a valid end date, for example '%1'.") .arg( KGlobal::locale()->formatDate( QDate::currentDate() ) ) ); return false; } QDateTime startDt,endDt; startDt.setDate(mStartDateEdit->date()); endDt.setDate(mEndDateEdit->date()); if (!mNoTimeButton->isChecked()) { startDt.setTime(mStartTimeEdit->getTime()); endDt.setTime(mEndTimeEdit->getTime()); } if (startDt > endDt) { KMessageBox::sorry(0,i18n("The event ends before it starts.\n" "Please correct dates and times.")); return false; } return KOEditorGeneral::validateInput(); } diff --git a/korganizer/koeditorgeneraltodo.cpp b/korganizer/koeditorgeneraltodo.cpp index 7db7da0..158a7d3 100644 --- a/korganizer/koeditorgeneraltodo.cpp +++ b/korganizer/koeditorgeneraltodo.cpp @@ -355,83 +355,71 @@ void KOEditorGeneralTodo::enableStartEdit( bool enable ) } else { mStartTimeEdit->setEnabled( false ); } } void KOEditorGeneralTodo::enableTimeEdits(bool enable) { if(mStartCheck->isChecked()) { mStartTimeEdit->setEnabled( enable ); } if(mDueCheck->isChecked()) { mDueTimeEdit->setEnabled( enable ); } } void KOEditorGeneralTodo::showAlarm() { if ( mDueCheck->isChecked() ) { alarmDisable(false); } else { alarmDisable(true); } } bool KOEditorGeneralTodo::validateInput() { if (mDueCheck->isChecked()) { if (!mDueDateEdit->inputIsValid()) { KMessageBox::sorry(0,i18n("Please specify a valid due date.")); return false; } - if (mTimeButton->isChecked()) { - if (!mDueTimeEdit->inputIsValid()) { - KMessageBox::sorry(0,i18n("Please specify a valid due time.")); - return false; - } - } } if (mStartCheck->isChecked()) { if (!mStartDateEdit->inputIsValid()) { KMessageBox::sorry(0,i18n("Please specify a valid start date.")); return false; } - if (mTimeButton->isChecked()) { - if (!mStartTimeEdit->inputIsValid()) { - KMessageBox::sorry(0,i18n("Please specify a valid start time.")); - return false; - } - } } if (mStartCheck->isChecked() && mDueCheck->isChecked()) { QDateTime startDate; QDateTime dueDate; startDate.setDate(mStartDateEdit->date()); dueDate.setDate(mDueDateEdit->date()); if (mTimeButton->isChecked()) { startDate.setTime(mStartTimeEdit->getTime()); dueDate.setTime(mDueTimeEdit->getTime()); } if (startDate > dueDate) { KMessageBox::sorry(0, i18n("The start date cannot be after the due date.")); return false; } } return KOEditorGeneral::validateInput(); } void KOEditorGeneralTodo::completedChanged(int index) { if (index == 5) { mCompleted = QDateTime::currentDateTime(); } setCompletedDate(); } void KOEditorGeneralTodo::setCompletedDate() { if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) { diff --git a/korganizer/ktimeedit.cpp b/korganizer/ktimeedit.cpp index f5a1c50..5222ac9 100644 --- a/korganizer/ktimeedit.cpp +++ b/korganizer/ktimeedit.cpp @@ -1,201 +1,157 @@ /* This file is part of KOrganizer. Copyright (c) 1999 Preston Brown, Ian Dawes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qkeycode.h> #include <qcombobox.h> #include <qdatetime.h> #include <qlineedit.h> +#include <qlistbox.h> #include <qapplication.h> #include <kmessagebox.h> #include <kglobal.h> #include <kdebug.h> #include <klocale.h> #include <kpimglobalprefs.h> #include "ktimeedit.h" #include "koprefs.h" #include <qvalidator.h> // Validator for a time value with only hours and minutes (no seconds) // 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; - } -}; // KTimeWidget/QTimeEdit provide nicer editing, but don't provide a combobox. // Difficult to get all in one... // But Qt-3.2 will offer QLineEdit::setMask, so a "99:99" mask would help. KOTimeEdit::KOTimeEdit(QWidget *parent, QTime qt, const char *name) : QComboBox(TRUE, parent, name) { setInsertionPolicy(NoInsertion); - setValidator( new KOTimeValidator( this ) ); mFlagKeyPressed = false; if ( QApplication::desktop()->width() < 650 ) setSizeLimit ( 6 ); mTime = qt; // mNoTimeString = i18n("No Time"); // insertItem( mNoTimeString ); // Fill combo box with selection of times in localized format. QTime timeEntry(0,0,0); do { insertItem(KGlobal::locale()->formatTime(timeEntry)); timeEntry = timeEntry.addSecs(60*15); } while (!timeEntry.isNull()); // Add end of day. insertItem( KGlobal::locale()->formatTime( QTime( 23, 59, 59 ) ) ); updateText(); setFocusPolicy(QWidget::StrongFocus); connect(this, SIGNAL(activated(int)), this, SLOT(activ(int))); connect(this, SIGNAL(highlighted(int)), this, SLOT(hilit(int))); connect(this,SIGNAL(textChanged(const QString&)),this,SLOT(changedText())); QFontMetrics fm ( font() ); QString timeString = "24:00"; if ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ) timeString = "02:00pm"; int addSpace = 32; if ( QApplication::desktop()->width() > 320 ) timeString += ":00"; setFixedWidth(fm.width( timeString ) + 32 ); // Highlight Background and Textcolor change from default QPalette palette = QWidget::palette(); unsigned char red, green, blue; red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); setPalette( palette ); } KOTimeEdit::~KOTimeEdit() { } bool KOTimeEdit::hasTime() const { // Can't happen if ( currentText().isEmpty() ) return false; //if ( currentText() == mNoTimeString ) return false; return true; // always } 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()); } /* QSizePolicy KOTimeEdit::sizePolicy() const { // Set size policy to Fixed, because edit cannot contain more text than the // string representing the time. It doesn't make sense to provide more space. QSizePolicy sizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); return sizePolicy; } */ void KOTimeEdit::setTime(QTime newTime) { if ( mTime != newTime ) { - kdDebug(5850) << "KOTimeEdit::setTime(): " << newTime.toString() << endl; - mTime = newTime; updateText(); } } void KOTimeEdit::activ(int i) { // The last entry, 23:59, is a special case if( i == count() - 1 ) mTime = QTime( 23, 59, 0 ); else mTime = QTime(0,0,0).addSecs(i*15*60); emit timeChanged(mTime); } void KOTimeEdit::hilit(int ) { // we don't currently need to do anything here. } void KOTimeEdit::addTime(QTime qt, bool update) { // Calculate the new time. //qDebug("add h %d min %d ", qt.hour(),qt.minute() ); mTime = mTime.addSecs(qt.minute()*60+qt.hour()*3600); // if ( update ) updateText(); emit timeChanged(mTime); } void KOTimeEdit::subTime(QTime qt, bool update) @@ -350,74 +306,76 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e) setSelect ( 0 , 2 ); break; } break; // set cursor to correct place case Key_Left: if ( cpos == 3 ) --cpos; if ( cpos > 0) { lineEdit()->setCursorPosition(--cpos); setSelect ( cpos , 1 ); } else setSelect ( 0 , 1 ); break; // set cursor to correct place case Key_Right: if ( cpos == 1 ) ++cpos; if ( cpos < maxpos ) { lineEdit()->setCursorPosition(++cpos); setSelect ( cpos , 1 ); } break; // rest case Key_Prior: subTime(QTime(1,0,0)); break; case Key_Next: addTime(QTime(1,0,0)); break; case Key_Backspace: + qDebug("+++++++++++back "); if ( cpos > 0) { if ( cpos == 3 ) --cpos; if ( cpos > 5) cpos = 5; text.at( cpos-1 ) = '0'; lineEdit()->setText( text ); lineEdit()->setCursorPosition(--cpos); setSelect ( cpos , 1 ); changedText(); + qDebug("---------back "); } break; } // switch arrows // if cursor at string end, alltext market and keyEvent don't ArrowLeft -> deselect and cpos if( cpos > 4 && lineEdit()->markedText().length() == 5 && e->key() != Key_Left ) { lineEdit()->deselect(); cpos = 0; lineEdit()->setCursorPosition(cpos); setSelect(cpos , 1); } if ( cpos == 2 ) { lineEdit()->setCursorPosition(++cpos); } // num keys when cursorPos preEnd if ( cpos < 5 ) { // switch another keys switch(e->key()) { case Key_Delete: text.at( cpos ) = '0'; lineEdit()->setText( text ); lineEdit()->setCursorPosition(cpos); setSelect ( cpos , 1 ); changedText(); break; case Key_9: case Key_8: case Key_7: case Key_6: if ( !(cpos == 1 || cpos == 4) ) @@ -456,73 +414,61 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e) case Key_Home: lineEdit()->setCursorPosition(0); setSelect( cpos , 1 ); break; case Key_End: lineEdit()->setCursorPosition(5); lineEdit()->deselect(); break; default: // QComboBox::keyPressEvent(e); break; } // switch num keys } else if ( cpos == 5 ) {// if cpos < 5 if ( hour12Format ) { if ( e->key() == Key_A ) { text.at( 5 ) = 'a'; lineEdit()->setText( text ); lineEdit()->setCursorPosition(5); } else if ( e->key() == Key_P ) { text.at( 5 ) = 'p'; lineEdit()->setText( text ); lineEdit()->setCursorPosition(5); } } } } 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; } 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); } diff --git a/korganizer/ktimeedit.h b/korganizer/ktimeedit.h index 7923070..b3d842d 100644 --- a/korganizer/ktimeedit.h +++ b/korganizer/ktimeedit.h @@ -29,67 +29,64 @@ #include <qdatetime.h> #include <qcombobox.h> #include <kapplication.h> /** This is a class that provides an easy, user friendly way to edit times. up/down/ increase or decrease time, respectively. @short Provides a way to edit times in a user-friendly manner. @author Preston Brown, Ian Dawes */ class KOTimeEdit : public QComboBox { Q_OBJECT public: /** constructs a new time edit. */ KOTimeEdit(QWidget *parent=0, QTime qt=QTime(12,0), const char *name=0); virtual ~KOTimeEdit(); /** Returns, if a time is selected. Can not return false anymore.... */ bool hasTime() const; /** returns the time that is currently set in the timeLineEdit. */ QTime getTime() const; /** returns the prefered size policy of the KOTimeEdit */ //QSizePolicy sizePolicy() const; - /** return true if input is a valid time and false if not */ - bool inputIsValid() const; - signals: /** Emitted every time the time displayed changes. "newt" is the new time. */ void timeChanged(QTime newt); public slots: /** used to set the time which is displayed to a specific value. */ void setTime(QTime qt); protected slots: void activ(int); void hilit(int); void changedText(); protected: void keyPressEvent(QKeyEvent *qke); void keyReleaseEvent(QKeyEvent *qke); void setSelect ( int, int ); bool mFlagKeyPressed; void addTime(QTime qt, bool update = true ); void subTime(QTime qt, bool update = true ); // Update the lineedit text from mTime void updateText(); // void mouseReleaseEvent ( QMouseEvent * ) ; //void focusInEvent ( QFocusEvent * ) ; private: QTime mTime; // the widget's displayed time. //QString mNoTimeString; }; |