summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp94
-rw-r--r--noncore/tools/clock/clock.h3
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
@@ -428,104 +428,120 @@ void Clock::timerEvent( QTimerEvent *e )
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
444QSizePolicy AnalogClock::sizePolicy() const 444QSizePolicy AnalogClock::sizePolicy() const
445{ 445{
446 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 446 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
447} 447}
448 448
449void AnalogClock::drawContents( QPainter *p ) 449void 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
486void 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
508void AnalogClock::display( const QTime& t ) 525void 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
517QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) 533QPoint 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
527void Clock::slotAdjustTime() 543void 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
@@ -15,59 +15,60 @@
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
26class QLCDNumber; 26class QLCDNumber;
27class QLabel; 27class QLabel;
28class QTimer; 28class QTimer;
29class QRadioButton; 29class QRadioButton;
30class QPushButton; 30class QPushButton;
31class QDateTime; 31class QDateTime;
32 32
33class AnalogClock : public QFrame 33class AnalogClock : public QFrame
34{ 34{
35 Q_OBJECT 35 Q_OBJECT
36 36
37public: 37public:
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
45protected: 45protected:
46 void drawContents( QPainter *p ); 46 void drawContents( QPainter *p );
47 47
48private: 48private:
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
56class Clock : public QVBox 57class Clock : public QVBox
57{ 58{
58 Q_OBJECT 59 Q_OBJECT
59 60
60public: 61public:
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;
66private slots: 67private 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();