-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 | |||
@@ -448,71 +448,87 @@ QSizePolicy AnalogClock::sizePolicy() const | |||
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 | { |
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 | |||
@@ -35,9 +35,9 @@ class AnalogClock : public QFrame | |||
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 ); |
@@ -46,8 +46,9 @@ 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; |