-rw-r--r-- | korganizer/ktimeedit.cpp | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/korganizer/ktimeedit.cpp b/korganizer/ktimeedit.cpp index df9b2fc..e2ae4a6 100644 --- a/korganizer/ktimeedit.cpp +++ b/korganizer/ktimeedit.cpp @@ -1,96 +1,99 @@ /* 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 <qnamespace.h> #include <qcombobox.h> #include <qdatetime.h> #include <qlineedit.h> -#include <qlistbox.h> +#include <q3listbox.h> #include <qapplication.h> +#include <QDesktopWidget> +//Added by qt3to4: +#include <QKeyEvent> #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> // 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) + : Q3ComboBox(TRUE, parent, name) { setInsertionPolicy(NoInsertion); mFlagKeyPressed = false; if ( QApplication::desktop()->height() <= 480 ) { setSizeLimit ( 6 ); } else { setSizeLimit ( 12 ); } 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()); + } while ( !( timeEntry.hour() || timeEntry.minute() ) ); // Add end of day. insertItem( KGlobal::locale()->formatTime( QTime( 23, 59, 59 ) ) ); updateText(); - setFocusPolicy(QWidget::StrongFocus); + setFocusPolicy(Qt::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 ); } @@ -187,272 +190,272 @@ void KOTimeEdit::keyReleaseEvent(QKeyEvent *e) } void KOTimeEdit::setSelect( int from, int to ) { if ( KOPrefs::instance()->mHightlightDateTimeEdit) lineEdit()->setSelection( from , to ); } void KOTimeEdit::keyPressEvent(QKeyEvent *e) { qApp->processEvents(); bool hour12Format = ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ); int maxpos = hour12Format?7:5; if ( e->isAutoRepeat() && !mFlagKeyPressed ) { e->ignore(); // qDebug(" ignore %d",e->isAutoRepeat() ); return; } if (! e->isAutoRepeat() ) { mFlagKeyPressed = true; } // Tap -> Focus Next Widget - if ( e->key() == Key_Tab ) { - QComboBox::keyPressEvent(e); + if ( e->key() == Qt::Key_Tab ) { + Q3ComboBox::keyPressEvent(e); return; } // save Text from QLineEdit and CursorPosition QString text = lineEdit()->text(); int cpos = lineEdit()->cursorPosition(); // qDebug("cpos %d ", cpos); // Switch for arrows, backspace and escape switch(e->key()) { - case Key_Escape: + case Qt::Key_Escape: lineEdit()->deselect(); - case Key_Tab: - QComboBox::keyPressEvent(e); + case Qt::Key_Tab: + Q3ComboBox::keyPressEvent(e); break; - case Key_Up: + case Qt::Key_Up: if ( e->state () == Qt::ControlButton ) { addTime(QTime(0,15,0), false ); lineEdit()->setCursorPosition(3); setSelect( 3 , 2 ); } else if ( e->state () == Qt::ShiftButton ) { addTime(QTime(1,0,0), false ); lineEdit()->setCursorPosition(0); setSelect( 0 , 2 ); } else // switch time up, cursor location depend switch (cpos) { case 7: case 6: case 5: if(!hour12Format) { lineEdit()->setCursorPosition(cpos = 4); } else { addTime(QTime(12,0,0), false ); setSelect ( 5 , 2 ); break; } case 4: addTime(QTime(0,1,0), false ); setSelect ( cpos , 1 ); break; case 3: addTime(QTime(0,10,0), false ); setSelect ( cpos , 1 ); break; case 2: lineEdit()->setCursorPosition(--cpos); case 1: case 0: addTime(QTime(1,0,0), false ); setSelect ( 0, 2 ); break; } break; - case Key_Down: + case Qt::Key_Down: if ( e->state () == Qt::ControlButton ) { subTime(QTime(0,15,0), false ); lineEdit()->setCursorPosition(3); setSelect( 3 , 2 ); } else if ( e->state () == Qt::ShiftButton ) { subTime(QTime(1,0,0), false ); lineEdit()->setCursorPosition(0); setSelect( 0 , 2 ); } else // switch time down, cursor location depend switch (cpos) { case 7: case 6: case 5: if(!hour12Format) { lineEdit()->setCursorPosition(cpos = 4); } else { subTime(QTime(12,0,0), false ); setSelect ( 5 , 2 ); break; } case 4: subTime(QTime(0,1,0), false ); setSelect ( cpos , 1 ); break; case 3: subTime(QTime(0,10,0), false ); setSelect ( cpos , 1 ); break; case 2: lineEdit()->setCursorPosition(--cpos); case 1: case 0: subTime(QTime(1,0,0), false ); setSelect ( 0 , 2 ); break; } break; // set cursor to correct place - case Key_Left: + case Qt::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: + case Qt::Key_Right: if ( cpos == 1 ) ++cpos; if ( cpos < maxpos ) { lineEdit()->setCursorPosition(++cpos); setSelect ( cpos , 1 ); } break; // rest - case Key_Prior: + case Qt::Key_Prior: subTime(QTime(1,0,0)); break; - case Key_Next: + case Qt::Key_Next: addTime(QTime(1,0,0)); break; - case Key_Backspace: + case Qt::Key_Backspace: if ( cpos > 0) { if ( cpos == 3 ) --cpos; if ( cpos > 5) cpos = 5; - text.at( cpos-1 ) = '0'; + text[ cpos-1 ] = '0'; lineEdit()->setText( text ); lineEdit()->setCursorPosition(--cpos); setSelect ( cpos , 1 ); changedText(); } 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 ) { + if( cpos > 4 && lineEdit()->markedText().length() == 5 && e->key() != Qt::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'; + case Qt::Key_Delete: + text[ 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: + case Qt::Key_9: + case Qt::Key_8: + case Qt::Key_7: + case Qt::Key_6: if ( !(cpos == 1 || cpos == 4) ) return; if ( cpos == 1 && text.at( 0 ) > '1') - text.at( 0 ) = '1'; - case Key_5: - case Key_4: - case Key_3: + text[ 0 ] = '1'; + case Qt::Key_5: + case Qt::Key_4: + case Qt::Key_3: if ( cpos < 1 ) return; if ( hour12Format && cpos == 1 ) return; - case Key_2: + case Qt::Key_2: if ( hour12Format && cpos == 0 ) return; if ( cpos == 0 && text.at( 1 ) > '3') - text.at( 1 ) = '3'; - case Key_1: - case Key_0: + text[ 1 ] = '3'; + case Qt::Key_1: + case Qt::Key_0: if ( hour12Format ) { - if ( e->key() == Key_0 && cpos == 1 && text.at( 0 ) == '0' ) + if ( e->key() == Qt::Key_0 && cpos == 1 && text.at( 0 ) == '0' ) return; - if ( e->key() == Key_0 && cpos == 0 && text.at( 1 ) == '0' ) - text.at( 1 ) = '1'; + if ( e->key() == Qt::Key_0 && cpos == 0 && text.at( 1 ) == '0' ) + text[ 1 ] = '1'; } - text.at( cpos ) = QChar ( e->key() ); + text[ cpos ] = QChar ( e->key() ); lineEdit()->setText( text ); if ( cpos == 1 ) ++cpos; if ( cpos < 5) lineEdit()->setCursorPosition(++cpos); setSelect( cpos , 1 ); changedText(); break; - case Key_Home: + case Qt::Key_Home: lineEdit()->setCursorPosition(0); setSelect( cpos , 1 ); break; - case Key_End: + case Qt::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'; + if ( e->key() == Qt::Key_A ) { + text[ 5 ] = 'a'; lineEdit()->setText( text ); lineEdit()->setCursorPosition(5); - } else if ( e->key() == Key_P ) { - text.at( 5 ) = 'p'; + } else if ( e->key() == Qt::Key_P ) { + text[ 5 ] = 'p'; lineEdit()->setText( text ); lineEdit()->setCursorPosition(5); } } } } void KOTimeEdit::updateText() { 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->setText(s); line->setCursorPosition(pos); line->blockSignals(false); blockSignals( false ); |