-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 | |||
@@ -12,73 +12,76 @@ | |||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qkeycode.h> | 24 | #include <qnamespace.h> |
25 | #include <qcombobox.h> | 25 | #include <qcombobox.h> |
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qlineedit.h> | 27 | #include <qlineedit.h> |
28 | #include <qlistbox.h> | 28 | #include <q3listbox.h> |
29 | #include <qapplication.h> | 29 | #include <qapplication.h> |
30 | #include <QDesktopWidget> | ||
31 | //Added by qt3to4: | ||
32 | #include <QKeyEvent> | ||
30 | 33 | ||
31 | #include <kmessagebox.h> | 34 | #include <kmessagebox.h> |
32 | #include <kglobal.h> | 35 | #include <kglobal.h> |
33 | #include <kdebug.h> | 36 | #include <kdebug.h> |
34 | #include <klocale.h> | 37 | #include <klocale.h> |
35 | #include <kpimglobalprefs.h> | 38 | #include <kpimglobalprefs.h> |
36 | 39 | ||
37 | #include "ktimeedit.h" | 40 | #include "ktimeedit.h" |
38 | #include "koprefs.h" | 41 | #include "koprefs.h" |
39 | #include <qvalidator.h> | 42 | #include <qvalidator.h> |
40 | 43 | ||
41 | // Validator for a time value with only hours and minutes (no seconds) | 44 | // Validator for a time value with only hours and minutes (no seconds) |
42 | // Mostly locale aware. Author: David Faure <faure@kde.org> | 45 | // Mostly locale aware. Author: David Faure <faure@kde.org> |
43 | 46 | ||
44 | // KTimeWidget/QTimeEdit provide nicer editing, but don't provide a combobox. | 47 | // KTimeWidget/QTimeEdit provide nicer editing, but don't provide a combobox. |
45 | // Difficult to get all in one... | 48 | // Difficult to get all in one... |
46 | // But Qt-3.2 will offer QLineEdit::setMask, so a "99:99" mask would help. | 49 | // But Qt-3.2 will offer QLineEdit::setMask, so a "99:99" mask would help. |
47 | KOTimeEdit::KOTimeEdit(QWidget *parent, QTime qt, const char *name) | 50 | KOTimeEdit::KOTimeEdit(QWidget *parent, QTime qt, const char *name) |
48 | : QComboBox(TRUE, parent, name) | 51 | : Q3ComboBox(TRUE, parent, name) |
49 | { | 52 | { |
50 | setInsertionPolicy(NoInsertion); | 53 | setInsertionPolicy(NoInsertion); |
51 | mFlagKeyPressed = false; | 54 | mFlagKeyPressed = false; |
52 | if ( QApplication::desktop()->height() <= 480 ) { | 55 | if ( QApplication::desktop()->height() <= 480 ) { |
53 | setSizeLimit ( 6 ); | 56 | setSizeLimit ( 6 ); |
54 | } else { | 57 | } else { |
55 | setSizeLimit ( 12 ); | 58 | setSizeLimit ( 12 ); |
56 | } | 59 | } |
57 | mTime = qt; | 60 | mTime = qt; |
58 | 61 | ||
59 | // mNoTimeString = i18n("No Time"); | 62 | // mNoTimeString = i18n("No Time"); |
60 | // insertItem( mNoTimeString ); | 63 | // insertItem( mNoTimeString ); |
61 | 64 | ||
62 | // Fill combo box with selection of times in localized format. | 65 | // Fill combo box with selection of times in localized format. |
63 | QTime timeEntry(0,0,0); | 66 | QTime timeEntry(0,0,0); |
64 | do { | 67 | do { |
65 | insertItem(KGlobal::locale()->formatTime(timeEntry)); | 68 | insertItem(KGlobal::locale()->formatTime(timeEntry)); |
66 | timeEntry = timeEntry.addSecs(60*15); | 69 | timeEntry = timeEntry.addSecs(60*15); |
67 | } while (!timeEntry.isNull()); | 70 | } while ( !( timeEntry.hour() || timeEntry.minute() ) ); |
68 | // Add end of day. | 71 | // Add end of day. |
69 | insertItem( KGlobal::locale()->formatTime( QTime( 23, 59, 59 ) ) ); | 72 | insertItem( KGlobal::locale()->formatTime( QTime( 23, 59, 59 ) ) ); |
70 | 73 | ||
71 | updateText(); | 74 | updateText(); |
72 | setFocusPolicy(QWidget::StrongFocus); | 75 | setFocusPolicy(Qt::StrongFocus); |
73 | 76 | ||
74 | connect(this, SIGNAL(activated(int)), this, SLOT(activ(int))); | 77 | connect(this, SIGNAL(activated(int)), this, SLOT(activ(int))); |
75 | connect(this, SIGNAL(highlighted(int)), this, SLOT(hilit(int))); | 78 | connect(this, SIGNAL(highlighted(int)), this, SLOT(hilit(int))); |
76 | connect(this,SIGNAL(textChanged(const QString&)),this,SLOT(changedText())); | 79 | connect(this,SIGNAL(textChanged(const QString&)),this,SLOT(changedText())); |
77 | QFontMetrics fm ( font() ); | 80 | QFontMetrics fm ( font() ); |
78 | QString timeString = "24:00"; | 81 | QString timeString = "24:00"; |
79 | if ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ) | 82 | if ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ) |
80 | timeString = "02:00pm"; | 83 | timeString = "02:00pm"; |
81 | int addSpace = 32; | 84 | int addSpace = 32; |
82 | if ( QApplication::desktop()->width() > 320 ) | 85 | if ( QApplication::desktop()->width() > 320 ) |
83 | timeString += ":00"; | 86 | timeString += ":00"; |
84 | setFixedWidth(fm.width( timeString ) + 32 ); | 87 | setFixedWidth(fm.width( timeString ) + 32 ); |
@@ -199,42 +202,42 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e) | |||
199 | qApp->processEvents(); | 202 | qApp->processEvents(); |
200 | bool hour12Format = ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ); | 203 | bool hour12Format = ( KPimGlobalPrefs::instance()->mPreferredTime == 1 ); |
201 | int maxpos = hour12Format?7:5; | 204 | int maxpos = hour12Format?7:5; |
202 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { | 205 | if ( e->isAutoRepeat() && !mFlagKeyPressed ) { |
203 | e->ignore(); | 206 | e->ignore(); |
204 | // qDebug(" ignore %d",e->isAutoRepeat() ); | 207 | // qDebug(" ignore %d",e->isAutoRepeat() ); |
205 | return; | 208 | return; |
206 | } | 209 | } |
207 | if (! e->isAutoRepeat() ) { | 210 | if (! e->isAutoRepeat() ) { |
208 | mFlagKeyPressed = true; | 211 | mFlagKeyPressed = true; |
209 | } | 212 | } |
210 | // Tap -> Focus Next Widget | 213 | // Tap -> Focus Next Widget |
211 | if ( e->key() == Key_Tab ) { | 214 | if ( e->key() == Qt::Key_Tab ) { |
212 | QComboBox::keyPressEvent(e); | 215 | Q3ComboBox::keyPressEvent(e); |
213 | return; | 216 | return; |
214 | } | 217 | } |
215 | 218 | ||
216 | // save Text from QLineEdit and CursorPosition | 219 | // save Text from QLineEdit and CursorPosition |
217 | QString text = lineEdit()->text(); | 220 | QString text = lineEdit()->text(); |
218 | int cpos = lineEdit()->cursorPosition(); | 221 | int cpos = lineEdit()->cursorPosition(); |
219 | // qDebug("cpos %d ", cpos); | 222 | // qDebug("cpos %d ", cpos); |
220 | 223 | ||
221 | // Switch for arrows, backspace and escape | 224 | // Switch for arrows, backspace and escape |
222 | switch(e->key()) { | 225 | switch(e->key()) { |
223 | case Key_Escape: | 226 | case Qt::Key_Escape: |
224 | lineEdit()->deselect(); | 227 | lineEdit()->deselect(); |
225 | case Key_Tab: | 228 | case Qt::Key_Tab: |
226 | QComboBox::keyPressEvent(e); | 229 | Q3ComboBox::keyPressEvent(e); |
227 | break; | 230 | break; |
228 | case Key_Up: | 231 | case Qt::Key_Up: |
229 | if ( e->state () == Qt::ControlButton ) { | 232 | if ( e->state () == Qt::ControlButton ) { |
230 | addTime(QTime(0,15,0), false ); | 233 | addTime(QTime(0,15,0), false ); |
231 | lineEdit()->setCursorPosition(3); | 234 | lineEdit()->setCursorPosition(3); |
232 | setSelect( 3 , 2 ); | 235 | setSelect( 3 , 2 ); |
233 | } | 236 | } |
234 | else | 237 | else |
235 | if ( e->state () == Qt::ShiftButton ) { | 238 | if ( e->state () == Qt::ShiftButton ) { |
236 | addTime(QTime(1,0,0), false ); | 239 | addTime(QTime(1,0,0), false ); |
237 | lineEdit()->setCursorPosition(0); | 240 | lineEdit()->setCursorPosition(0); |
238 | setSelect( 0 , 2 ); | 241 | setSelect( 0 , 2 ); |
239 | } | 242 | } |
240 | else | 243 | else |
@@ -258,25 +261,25 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e) | |||
258 | addTime(QTime(0,10,0), false ); | 261 | addTime(QTime(0,10,0), false ); |
259 | setSelect ( cpos , 1 ); | 262 | setSelect ( cpos , 1 ); |
260 | break; | 263 | break; |
261 | case 2: | 264 | case 2: |
262 | lineEdit()->setCursorPosition(--cpos); | 265 | lineEdit()->setCursorPosition(--cpos); |
263 | case 1: | 266 | case 1: |
264 | case 0: | 267 | case 0: |
265 | addTime(QTime(1,0,0), false ); | 268 | addTime(QTime(1,0,0), false ); |
266 | setSelect ( 0, 2 ); | 269 | setSelect ( 0, 2 ); |
267 | break; | 270 | break; |
268 | } | 271 | } |
269 | break; | 272 | break; |
270 | case Key_Down: | 273 | case Qt::Key_Down: |
271 | if ( e->state () == Qt::ControlButton ) { | 274 | if ( e->state () == Qt::ControlButton ) { |
272 | subTime(QTime(0,15,0), false ); | 275 | subTime(QTime(0,15,0), false ); |
273 | lineEdit()->setCursorPosition(3); | 276 | lineEdit()->setCursorPosition(3); |
274 | setSelect( 3 , 2 ); | 277 | setSelect( 3 , 2 ); |
275 | } | 278 | } |
276 | else | 279 | else |
277 | if ( e->state () == Qt::ShiftButton ) { | 280 | if ( e->state () == Qt::ShiftButton ) { |
278 | subTime(QTime(1,0,0), false ); | 281 | subTime(QTime(1,0,0), false ); |
279 | lineEdit()->setCursorPosition(0); | 282 | lineEdit()->setCursorPosition(0); |
280 | setSelect( 0 , 2 ); | 283 | setSelect( 0 , 2 ); |
281 | } | 284 | } |
282 | else | 285 | else |
@@ -301,146 +304,146 @@ void KOTimeEdit::keyPressEvent(QKeyEvent *e) | |||
301 | setSelect ( cpos , 1 ); | 304 | setSelect ( cpos , 1 ); |
302 | break; | 305 | break; |
303 | case 2: | 306 | case 2: |
304 | lineEdit()->setCursorPosition(--cpos); | 307 | lineEdit()->setCursorPosition(--cpos); |
305 | case 1: | 308 | case 1: |
306 | case 0: | 309 | case 0: |
307 | subTime(QTime(1,0,0), false ); | 310 | subTime(QTime(1,0,0), false ); |
308 | setSelect ( 0 , 2 ); | 311 | setSelect ( 0 , 2 ); |
309 | break; | 312 | break; |
310 | } | 313 | } |
311 | break; | 314 | break; |
312 | // set cursor to correct place | 315 | // set cursor to correct place |
313 | case Key_Left: | 316 | case Qt::Key_Left: |
314 | if ( cpos == 3 ) | 317 | if ( cpos == 3 ) |
315 | --cpos; | 318 | --cpos; |
316 | if ( cpos > 0) { | 319 | if ( cpos > 0) { |
317 | lineEdit()->setCursorPosition(--cpos); | 320 | lineEdit()->setCursorPosition(--cpos); |
318 | setSelect ( cpos , 1 ); | 321 | setSelect ( cpos , 1 ); |
319 | } | 322 | } |
320 | else | 323 | else |
321 | setSelect ( 0 , 1 ); | 324 | setSelect ( 0 , 1 ); |
322 | break; | 325 | break; |
323 | // set cursor to correct place | 326 | // set cursor to correct place |
324 | case Key_Right: | 327 | case Qt::Key_Right: |
325 | if ( cpos == 1 ) | 328 | if ( cpos == 1 ) |
326 | ++cpos; | 329 | ++cpos; |
327 | if ( cpos < maxpos ) { | 330 | if ( cpos < maxpos ) { |
328 | lineEdit()->setCursorPosition(++cpos); | 331 | lineEdit()->setCursorPosition(++cpos); |
329 | setSelect ( cpos , 1 ); | 332 | setSelect ( cpos , 1 ); |
330 | } | 333 | } |
331 | break; | 334 | break; |
332 | // rest | 335 | // rest |
333 | case Key_Prior: | 336 | case Qt::Key_Prior: |
334 | subTime(QTime(1,0,0)); | 337 | subTime(QTime(1,0,0)); |
335 | break; | 338 | break; |
336 | case Key_Next: | 339 | case Qt::Key_Next: |
337 | addTime(QTime(1,0,0)); | 340 | addTime(QTime(1,0,0)); |
338 | break; | 341 | break; |
339 | case Key_Backspace: | 342 | case Qt::Key_Backspace: |
340 | if ( cpos > 0) { | 343 | if ( cpos > 0) { |
341 | if ( cpos == 3 ) | 344 | if ( cpos == 3 ) |
342 | --cpos; | 345 | --cpos; |
343 | if ( cpos > 5) | 346 | if ( cpos > 5) |
344 | cpos = 5; | 347 | cpos = 5; |
345 | text.at( cpos-1 ) = '0'; | 348 | text[ cpos-1 ] = '0'; |
346 | lineEdit()->setText( text ); | 349 | lineEdit()->setText( text ); |
347 | lineEdit()->setCursorPosition(--cpos); | 350 | lineEdit()->setCursorPosition(--cpos); |
348 | setSelect ( cpos , 1 ); | 351 | setSelect ( cpos , 1 ); |
349 | changedText(); | 352 | changedText(); |
350 | } | 353 | } |
351 | break; | 354 | break; |
352 | } // switch arrows | 355 | } // switch arrows |
353 | 356 | ||
354 | // if cursor at string end, alltext market and keyEvent don't ArrowLeft -> deselect and cpos | 357 | // if cursor at string end, alltext market and keyEvent don't ArrowLeft -> deselect and cpos |
355 | if( cpos > 4 && lineEdit()->markedText().length() == 5 && e->key() != Key_Left ) { | 358 | if( cpos > 4 && lineEdit()->markedText().length() == 5 && e->key() != Qt::Key_Left ) { |
356 | lineEdit()->deselect(); | 359 | lineEdit()->deselect(); |
357 | cpos = 0; | 360 | cpos = 0; |
358 | lineEdit()->setCursorPosition(cpos); | 361 | lineEdit()->setCursorPosition(cpos); |
359 | setSelect(cpos , 1); | 362 | setSelect(cpos , 1); |
360 | } | 363 | } |
361 | 364 | ||
362 | if ( cpos == 2 ) { | 365 | if ( cpos == 2 ) { |
363 | lineEdit()->setCursorPosition(++cpos); | 366 | lineEdit()->setCursorPosition(++cpos); |
364 | } | 367 | } |
365 | 368 | ||
366 | // num keys when cursorPos preEnd | 369 | // num keys when cursorPos preEnd |
367 | if ( cpos < 5 ) { | 370 | if ( cpos < 5 ) { |
368 | // switch another keys | 371 | // switch another keys |
369 | switch(e->key()) { | 372 | switch(e->key()) { |
370 | case Key_Delete: | 373 | case Qt::Key_Delete: |
371 | text.at( cpos ) = '0'; | 374 | text[ cpos ] = '0'; |
372 | lineEdit()->setText( text ); | 375 | lineEdit()->setText( text ); |
373 | lineEdit()->setCursorPosition(cpos); | 376 | lineEdit()->setCursorPosition(cpos); |
374 | setSelect ( cpos , 1 ); | 377 | setSelect ( cpos , 1 ); |
375 | changedText(); | 378 | changedText(); |
376 | break; | 379 | break; |
377 | case Key_9: | 380 | case Qt::Key_9: |
378 | case Key_8: | 381 | case Qt::Key_8: |
379 | case Key_7: | 382 | case Qt::Key_7: |
380 | case Key_6: | 383 | case Qt::Key_6: |
381 | if ( !(cpos == 1 || cpos == 4) ) | 384 | if ( !(cpos == 1 || cpos == 4) ) |
382 | return; | 385 | return; |
383 | if ( cpos == 1 && text.at( 0 ) > '1') | 386 | if ( cpos == 1 && text.at( 0 ) > '1') |
384 | text.at( 0 ) = '1'; | 387 | text[ 0 ] = '1'; |
385 | case Key_5: | 388 | case Qt::Key_5: |
386 | case Key_4: | 389 | case Qt::Key_4: |
387 | case Key_3: | 390 | case Qt::Key_3: |
388 | if ( cpos < 1 ) | 391 | if ( cpos < 1 ) |
389 | return; | 392 | return; |
390 | if ( hour12Format && cpos == 1 ) | 393 | if ( hour12Format && cpos == 1 ) |
391 | return; | 394 | return; |
392 | case Key_2: | 395 | case Qt::Key_2: |
393 | if ( hour12Format && cpos == 0 ) | 396 | if ( hour12Format && cpos == 0 ) |
394 | return; | 397 | return; |
395 | if ( cpos == 0 && text.at( 1 ) > '3') | 398 | if ( cpos == 0 && text.at( 1 ) > '3') |
396 | text.at( 1 ) = '3'; | 399 | text[ 1 ] = '3'; |
397 | case Key_1: | 400 | case Qt::Key_1: |
398 | case Key_0: | 401 | case Qt::Key_0: |
399 | if ( hour12Format ) { | 402 | if ( hour12Format ) { |
400 | if ( e->key() == Key_0 && cpos == 1 && text.at( 0 ) == '0' ) | 403 | if ( e->key() == Qt::Key_0 && cpos == 1 && text.at( 0 ) == '0' ) |
401 | return; | 404 | return; |
402 | if ( e->key() == Key_0 && cpos == 0 && text.at( 1 ) == '0' ) | 405 | if ( e->key() == Qt::Key_0 && cpos == 0 && text.at( 1 ) == '0' ) |
403 | text.at( 1 ) = '1'; | 406 | text[ 1 ] = '1'; |
404 | } | 407 | } |
405 | text.at( cpos ) = QChar ( e->key() ); | 408 | text[ cpos ] = QChar ( e->key() ); |
406 | lineEdit()->setText( text ); | 409 | lineEdit()->setText( text ); |
407 | if ( cpos == 1 ) | 410 | if ( cpos == 1 ) |
408 | ++cpos; | 411 | ++cpos; |
409 | if ( cpos < 5) | 412 | if ( cpos < 5) |
410 | lineEdit()->setCursorPosition(++cpos); | 413 | lineEdit()->setCursorPosition(++cpos); |
411 | setSelect( cpos , 1 ); | 414 | setSelect( cpos , 1 ); |
412 | changedText(); | 415 | changedText(); |
413 | break; | 416 | break; |
414 | case Key_Home: | 417 | case Qt::Key_Home: |
415 | lineEdit()->setCursorPosition(0); | 418 | lineEdit()->setCursorPosition(0); |
416 | setSelect( cpos , 1 ); | 419 | setSelect( cpos , 1 ); |
417 | break; | 420 | break; |
418 | case Key_End: | 421 | case Qt::Key_End: |
419 | lineEdit()->setCursorPosition(5); | 422 | lineEdit()->setCursorPosition(5); |
420 | lineEdit()->deselect(); | 423 | lineEdit()->deselect(); |
421 | break; | 424 | break; |
422 | default: | 425 | default: |
423 | // QComboBox::keyPressEvent(e); | 426 | // QComboBox::keyPressEvent(e); |
424 | break; | 427 | break; |
425 | } // switch num keys | 428 | } // switch num keys |
426 | } else if ( cpos == 5 ) {// if cpos < 5 | 429 | } else if ( cpos == 5 ) {// if cpos < 5 |
427 | if ( hour12Format ) { | 430 | if ( hour12Format ) { |
428 | if ( e->key() == Key_A ) { | 431 | if ( e->key() == Qt::Key_A ) { |
429 | text.at( 5 ) = 'a'; | 432 | text[ 5 ] = 'a'; |
430 | lineEdit()->setText( text ); | 433 | lineEdit()->setText( text ); |
431 | lineEdit()->setCursorPosition(5); | 434 | lineEdit()->setCursorPosition(5); |
432 | 435 | ||
433 | } else if ( e->key() == Key_P ) { | 436 | } else if ( e->key() == Qt::Key_P ) { |
434 | text.at( 5 ) = 'p'; | 437 | text[ 5 ] = 'p'; |
435 | lineEdit()->setText( text ); | 438 | lineEdit()->setText( text ); |
436 | lineEdit()->setCursorPosition(5); | 439 | lineEdit()->setCursorPosition(5); |
437 | 440 | ||
438 | } | 441 | } |
439 | } | 442 | } |
440 | } | 443 | } |
441 | 444 | ||
442 | 445 | ||
443 | } | 446 | } |
444 | 447 | ||
445 | void KOTimeEdit::updateText() | 448 | void KOTimeEdit::updateText() |
446 | { | 449 | { |