-rw-r--r-- | noncore/tools/clock/clock.cpp | 94 | ||||
-rw-r--r-- | noncore/tools/clock/clock.h | 3 |
2 files changed, 57 insertions, 40 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp index 5b901c1..d69c56f 100644 --- a/noncore/tools/clock/clock.cpp +++ b/noncore/tools/clock/clock.cpp | |||
@@ -404,128 +404,144 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) | |||
404 | bSound = TRUE; | 404 | bSound = TRUE; |
405 | qDebug( "Message received in clock" ); | 405 | qDebug( "Message received in clock" ); |
406 | if ( msg == "alarm(QDateTime,int)" ) { | 406 | if ( msg == "alarm(QDateTime,int)" ) { |
407 | Config config( "qpe" ); | 407 | Config config( "qpe" ); |
408 | config.setGroup( "Time" ); | 408 | config.setGroup( "Time" ); |
409 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) { | 409 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) { |
410 | 410 | ||
411 | QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); | 411 | QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); |
412 | e << config.readEntry( "mp3File", "" ); | 412 | e << config.readEntry( "mp3File", "" ); |
413 | } | 413 | } |
414 | else { | 414 | else { |
415 | 415 | ||
416 | Sound::soundAlarm(); | 416 | Sound::soundAlarm(); |
417 | stopTimer = startTimer( timerStay ); | 417 | stopTimer = startTimer( timerStay ); |
418 | } | 418 | } |
419 | } | 419 | } |
420 | show(); | 420 | show(); |
421 | raise(); | 421 | raise(); |
422 | QPEApplication::setKeepRunning(); | 422 | QPEApplication::setKeepRunning(); |
423 | setActiveWindow(); | 423 | setActiveWindow(); |
424 | } | 424 | } |
425 | 425 | ||
426 | void Clock::timerEvent( QTimerEvent *e ) | 426 | void Clock::timerEvent( QTimerEvent *e ) |
427 | { | 427 | { |
428 | static int stop = 0; | 428 | static int stop = 0; |
429 | if ( stop < 120 && bSound ) { | 429 | if ( stop < 120 && bSound ) { |
430 | Sound::soundAlarm(); | 430 | Sound::soundAlarm(); |
431 | stop++; | 431 | stop++; |
432 | } | 432 | } |
433 | else { | 433 | else { |
434 | stop = 0; | 434 | stop = 0; |
435 | killTimer( e->timerId() ); | 435 | killTimer( e->timerId() ); |
436 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 436 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
437 | alarmBool = FALSE; | 437 | alarmBool = FALSE; |
438 | snoozeBtn->hide(); | 438 | snoozeBtn->hide(); |
439 | setCaption( tr( "Clock: Alarm was missed." ) ); | 439 | setCaption( tr( "Clock: Alarm was missed." ) ); |
440 | } | 440 | } |
441 | } | 441 | } |
442 | 442 | ||
443 | 443 | ||
444 | QSizePolicy AnalogClock::sizePolicy() const | 444 | QSizePolicy AnalogClock::sizePolicy() const |
445 | { | 445 | { |
446 | return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); | 446 | return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); |
447 | } | 447 | } |
448 | 448 | ||
449 | void AnalogClock::drawContents( QPainter *p ) | 449 | void AnalogClock::drawContents( QPainter *p ) |
450 | { | 450 | { |
451 | QRect r = contentsRect(); | 451 | QRect r = contentsRect(); |
452 | QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | 452 | QRect fr; |
453 | |||
454 | QPoint l1( r.x() + r.width() / 2, r.y() + 2 ); | ||
455 | QPoint l2( r.x() + r.width() / 2, r.y() + 8 ); | ||
456 | |||
457 | QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 ); | ||
458 | QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | ||
459 | 453 | ||
460 | QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 ); | 454 | if ( r. width ( ) > r. height ( )) |
461 | QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | 455 | fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); |
456 | else | ||
457 | fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); | ||
458 | |||
459 | QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); | ||
460 | QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); | ||
461 | QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); | ||
462 | 462 | ||
463 | QPoint s1( r.x() + r.width() / 2, r.y() + 8 ); | ||
464 | QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | ||
465 | 463 | ||
466 | QColor color( clear ? backgroundColor() : black ); | ||
467 | QTime time = clear ? prevTime : currTime; | ||
468 | 464 | ||
469 | if ( clear ) { | 465 | if ( clear ) { |
470 | erase( rect() ); | 466 | erase ( r ); |
471 | return ; | 467 | p-> setPen ( NoPen ); |
472 | } | 468 | p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); |
469 | p-> drawEllipse ( fr ); | ||
470 | p-> setBrush ( NoBrush ); | ||
473 | 471 | ||
474 | if ( !clear ) { | ||
475 | // draw ticks | 472 | // draw ticks |
476 | p->setPen( QPen( color, 1 ) ); | 473 | p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); |
477 | for ( int i = 0; i < 12; i++ ) | 474 | for ( int i = 0; i < 12; i++ ) |
478 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); | 475 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); |
479 | } | 476 | } |
477 | else { | ||
478 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); | ||
479 | } | ||
480 | |||
481 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); | ||
482 | |||
483 | prevTime = currTime; | ||
484 | } | ||
485 | |||
486 | void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) | ||
487 | { | ||
488 | QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | ||
480 | 489 | ||
481 | if ( !clear || prevTime.minute() != currTime.minute() || | 490 | QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); |
482 | prevTime.hour() != currTime.hour() ) { | 491 | QPoint h2( center. x ( ), center. y ( ) ); |
492 | |||
493 | QPoint m1( center. x ( ), r.y() + r.height() / 8 ); | ||
494 | QPoint m2( center. x ( ), center. y ( ) ); | ||
495 | |||
496 | QPoint s1( center. x ( ), r. y ( ) + 8 ); | ||
497 | QPoint s2( center. x ( ), center. y ( ) ); | ||
498 | |||
499 | |||
500 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { | ||
483 | // draw hour pointer | 501 | // draw hour pointer |
484 | h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); | 502 | h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
485 | h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); | 503 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
486 | p->setPen( QPen( color, 3 ) ); | 504 | p-> setPen ( QPen ( c, 3 )); |
487 | p->drawLine( h1, h2 ); | 505 | p-> drawLine ( h1, h2 ); |
488 | } | 506 | } |
489 | 507 | ||
490 | if ( !clear || prevTime.minute() != currTime.minute() ) { | 508 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { |
491 | // draw minute pointer | 509 | // draw minute pointer |
492 | m1 = rotate( center, m1, time.minute() * 6 ); | 510 | m1 = rotate( center, m1, t.minute() * 6 ); |
493 | m2 = rotate( center, m2, time.minute() * 6 ); | 511 | m2 = rotate( center, m2, t.minute() * 6 ); |
494 | p->setPen( QPen( color, 2 ) ); | 512 | p-> setPen ( QPen ( c, 2 )); |
495 | p->drawLine( m1, m2 ); | 513 | p-> drawLine ( m1, m2 ); |
496 | } | 514 | } |
497 | 515 | ||
498 | // draw second pointer | 516 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { |
499 | s1 = rotate( center, s1, time.second() * 6 ); | 517 | // draw second pointer |
500 | s2 = rotate( center, s2, time.second() * 6 ); | 518 | s1 = rotate( center, s1, t.second() * 6 ); |
501 | p->setPen( QPen( color, 1 ) ); | 519 | s2 = rotate( center, s2, t.second() * 6 ); |
502 | p->drawLine( s1, s2 ); | 520 | p-> setPen ( QPen ( c, 1 )); |
503 | 521 | p-> drawLine ( s1, s2 ); | |
504 | if ( !clear ) | 522 | } |
505 | prevTime = currTime; | ||
506 | } | 523 | } |
507 | 524 | ||
508 | void AnalogClock::display( const QTime& t ) | 525 | void AnalogClock::display( const QTime& t ) |
509 | { | 526 | { |
510 | currTime = t; | 527 | currTime = t; |
511 | clear = true; | ||
512 | repaint( false ); | ||
513 | clear = false; | 528 | clear = false; |
514 | repaint( false ); | 529 | repaint( false ); |
530 | clear = true; | ||
515 | } | 531 | } |
516 | 532 | ||
517 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) | 533 | QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) |
518 | { | 534 | { |
519 | double angle = deg2rad * ( - a + 180 ); | 535 | double angle = deg2rad * ( - a + 180 ); |
520 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - | 536 | double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - |
521 | ( p.y() - c.y() ) * sin( angle ); | 537 | ( p.y() - c.y() ) * sin( angle ); |
522 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + | 538 | double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + |
523 | ( p.x() - c.x() ) * sin( angle ); | 539 | ( p.x() - c.x() ) * sin( angle ); |
524 | return QPoint( nx, ny ); | 540 | return QPoint( nx, ny ); |
525 | } | 541 | } |
526 | 542 | ||
527 | void Clock::slotAdjustTime() | 543 | void Clock::slotAdjustTime() |
528 | { | 544 | { |
529 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 545 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
530 | e << QString( "systemtime" ); | 546 | e << QString( "systemtime" ); |
531 | } | 547 | } |
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h index be71b9d..092d84f 100644 --- a/noncore/tools/clock/clock.h +++ b/noncore/tools/clock/clock.h | |||
@@ -1,97 +1,98 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef CLOCK_H | 20 | #ifndef CLOCK_H |
21 | #define CLOCK_H | 21 | #define CLOCK_H |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qvbox.h> | 24 | #include <qvbox.h> |
25 | 25 | ||
26 | class QLCDNumber; | 26 | class QLCDNumber; |
27 | class QLabel; | 27 | class QLabel; |
28 | class QTimer; | 28 | class QTimer; |
29 | class QRadioButton; | 29 | class QRadioButton; |
30 | class QPushButton; | 30 | class QPushButton; |
31 | class QDateTime; | 31 | class QDateTime; |
32 | 32 | ||
33 | class AnalogClock : public QFrame | 33 | class AnalogClock : public QFrame |
34 | { | 34 | { |
35 | Q_OBJECT | 35 | Q_OBJECT |
36 | 36 | ||
37 | public: | 37 | public: |
38 | AnalogClock( QWidget * parent = 0, const char * name = 0 ) | 38 | AnalogClock( QWidget * parent = 0, const char * name = 0 ) |
39 | : QFrame( parent, name ), clear(false) {} | 39 | : QFrame( parent, name ), clear(true) {} |
40 | 40 | ||
41 | QSizePolicy sizePolicy() const; | 41 | QSizePolicy sizePolicy() const; |
42 | 42 | ||
43 | void display( const QTime& time ); | 43 | void display( const QTime& time ); |
44 | 44 | ||
45 | protected: | 45 | protected: |
46 | void drawContents( QPainter *p ); | 46 | void drawContents( QPainter *p ); |
47 | 47 | ||
48 | private: | 48 | private: |
49 | QPoint rotate( QPoint center, QPoint p, int angle ); | 49 | QPoint rotate( QPoint center, QPoint p, int angle ); |
50 | void drawPointers ( QPainter *, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0 ); | ||
50 | 51 | ||
51 | QTime currTime; | 52 | QTime currTime; |
52 | QTime prevTime; | 53 | QTime prevTime; |
53 | bool clear; | 54 | bool clear; |
54 | }; | 55 | }; |
55 | 56 | ||
56 | class Clock : public QVBox | 57 | class Clock : public QVBox |
57 | { | 58 | { |
58 | Q_OBJECT | 59 | Q_OBJECT |
59 | 60 | ||
60 | public: | 61 | public: |
61 | Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); | 62 | Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); |
62 | ~Clock(); | 63 | ~Clock(); |
63 | QDateTime when; | 64 | QDateTime when; |
64 | bool bSound; | 65 | bool bSound; |
65 | int hour, minute, snoozeTime; | 66 | int hour, minute, snoozeTime; |
66 | private slots: | 67 | private slots: |
67 | void slotSet(); | 68 | void slotSet(); |
68 | void slotReset(); | 69 | void slotReset(); |
69 | void modeSelect(int); | 70 | void modeSelect(int); |
70 | void updateClock(); | 71 | void updateClock(); |
71 | void changeClock( bool ); | 72 | void changeClock( bool ); |
72 | void slotSetAlarm(); | 73 | void slotSetAlarm(); |
73 | void slotSnooze(); | 74 | void slotSnooze(); |
74 | void slotToggleAlarm(); | 75 | void slotToggleAlarm(); |
75 | void alarmOn(); | 76 | void alarmOn(); |
76 | void alarmOff(); | 77 | void alarmOff(); |
77 | void appMessage(const QCString& msg, const QByteArray& data); | 78 | void appMessage(const QCString& msg, const QByteArray& data); |
78 | void timerEvent( QTimerEvent *e ); | 79 | void timerEvent( QTimerEvent *e ); |
79 | void slotAdjustTime(); | 80 | void slotAdjustTime(); |
80 | private: | 81 | private: |
81 | void clearClock(); | 82 | void clearClock(); |
82 | 83 | ||
83 | bool alarmBool; | 84 | bool alarmBool; |
84 | QTimer *t; | 85 | QTimer *t; |
85 | QLCDNumber *lcd; | 86 | QLCDNumber *lcd; |
86 | QLabel *date; | 87 | QLabel *date; |
87 | QLabel *ampmLabel; | 88 | QLabel *ampmLabel; |
88 | QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; | 89 | QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; |
89 | QRadioButton *clockRB, *swatchRB; | 90 | QRadioButton *clockRB, *swatchRB; |
90 | AnalogClock *aclock; | 91 | AnalogClock *aclock; |
91 | QTime swatch_start; | 92 | QTime swatch_start; |
92 | int swatch_totalms; | 93 | int swatch_totalms; |
93 | bool swatch_running; | 94 | bool swatch_running; |
94 | bool ampm; | 95 | bool ampm; |
95 | }; | 96 | }; |
96 | 97 | ||
97 | #endif | 98 | #endif |