author | zecke <zecke> | 2004-08-22 23:17:08 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-08-22 23:17:08 (UTC) |
commit | a1cb5750328eb4e6d232568c5cc5b8ba7ef99eb5 (patch) (unidiff) | |
tree | 49a955d1eb6e44f9acd8c82908928082fd067409 | |
parent | 3f4e6c92a607424e0af2c551525a2e4915fdc03e (diff) | |
download | opie-a1cb5750328eb4e6d232568c5cc5b8ba7ef99eb5.zip opie-a1cb5750328eb4e6d232568c5cc5b8ba7ef99eb5.tar.gz opie-a1cb5750328eb4e6d232568c5cc5b8ba7ef99eb5.tar.bz2 |
Buffer painting which is hopefully flicker free and it works
with Phase and Liquid Styles
-rw-r--r-- | noncore/tools/clock/analogclock.cpp | 112 | ||||
-rw-r--r-- | noncore/tools/clock/analogclock.h | 3 |
2 files changed, 64 insertions, 51 deletions
diff --git a/noncore/tools/clock/analogclock.cpp b/noncore/tools/clock/analogclock.cpp index c5f0155..16ecc5c 100644 --- a/noncore/tools/clock/analogclock.cpp +++ b/noncore/tools/clock/analogclock.cpp | |||
@@ -21,7 +21,10 @@ | |||
21 | #include "analogclock.h" | 21 | #include "analogclock.h" |
22 | 22 | ||
23 | #include <qtopia/global.h> | ||
24 | |||
23 | #include <qlayout.h> | 25 | #include <qlayout.h> |
24 | #include <qpainter.h> | 26 | #include <qpainter.h> |
25 | #include <qtopia/global.h> | 27 | #include <qpixmap.h> |
28 | |||
26 | 29 | ||
27 | #include <math.h> | 30 | #include <math.h> |
@@ -30,7 +33,15 @@ const double deg2rad = 0.017453292519943295769; // pi/180 | |||
30 | 33 | ||
31 | AnalogClock::AnalogClock( QWidget *parent, const char *name ) | 34 | AnalogClock::AnalogClock( QWidget *parent, const char *name ) |
32 | : QFrame( parent, name ), clear(false) | 35 | : QFrame( parent, name ) |
33 | { | 36 | { |
34 | setMinimumSize(50,50); | 37 | setMinimumSize(50,50); |
38 | |||
39 | /* initial the buffer pixmap */ | ||
40 | QRect r = contentsRect(); | ||
41 | _pixmap = new QPixmap( r.width(), r.height() ); | ||
42 | } | ||
43 | |||
44 | AnalogClock::~AnalogClock() { | ||
45 | delete _pixmap; | ||
35 | } | 46 | } |
36 | 47 | ||
@@ -40,13 +51,10 @@ QSizePolicy AnalogClock::sizePolicy() const | |||
40 | } | 51 | } |
41 | 52 | ||
42 | void AnalogClock::drawContents( QPainter *p ) | 53 | void AnalogClock::drawContents( QPainter * ) |
43 | { | 54 | { |
44 | #if !defined(NO_DEBUG) | 55 | /* no need to draw... */ |
45 | static bool first = true; | 56 | if ( !isVisible() ) |
46 | if ( first ) { | 57 | return; |
47 | //QTOPIA_PROFILE("first paint event"); | 58 | |
48 | first = false; | ||
49 | } | ||
50 | #endif | ||
51 | 59 | ||
52 | QRect r = contentsRect(); | 60 | QRect r = contentsRect(); |
@@ -57,4 +65,13 @@ void AnalogClock::drawContents( QPainter *p ) | |||
57 | } | 65 | } |
58 | 66 | ||
67 | /* resize the buffer */ | ||
68 | if ( r.width() != _pixmap->width() || | ||
69 | r.height() != _pixmap->height() ) | ||
70 | _pixmap->resize( r.width(), r.height() ); | ||
71 | |||
72 | QPainter p; | ||
73 | p.begin( _pixmap ); | ||
74 | |||
75 | |||
59 | QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | 76 | QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); |
60 | 77 | ||
@@ -75,50 +92,48 @@ void AnalogClock::drawContents( QPainter *p ) | |||
75 | QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); | 92 | QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); |
76 | 93 | ||
77 | QColor color( clear ? backgroundColor() : black ); | 94 | /* fill the pixmap */ |
78 | QTime time = clear ? prevTime : currTime; | 95 | _pixmap->fill( this, 0, 0 ); |
79 | 96 | ||
80 | if ( clear && prevTime.secsTo(currTime) > 1 ) { | ||
81 | p->eraseRect( rect() ); | ||
82 | return; | ||
83 | } | ||
84 | 97 | ||
85 | if ( !clear ) { | 98 | // draw ticks |
86 | // draw ticks | 99 | QColor color = black; |
87 | p->setPen( QPen( color, w_tick ) ); | 100 | p.setPen( QPen( color, w_tick ) ); |
88 | for ( int i = 0; i < 12; i++ ) | 101 | for ( int i = 0; i < 12; i++ ) |
89 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); | 102 | p.drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); |
90 | } | ||
91 | 103 | ||
92 | if ( !clear || prevTime.minute() != currTime.minute() || | ||
93 | prevTime.hour() != currTime.hour() ) { | ||
94 | // draw hour pointer | ||
95 | h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); | ||
96 | h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); | ||
97 | p->setPen( color ); | ||
98 | p->setBrush( color ); | ||
99 | drawHand( p, h1, h2 ); | ||
100 | } | ||
101 | 104 | ||
102 | if ( !clear || prevTime.minute() != currTime.minute() ) { | 105 | // draw hour pointer |
103 | // draw minute pointer | 106 | h1 = rotate( center, h1, 30 * ( currTime.hour() % 12 ) + currTime.minute() / 2 ); |
104 | m1 = rotate( center, m1, time.minute() * 6 ); | 107 | h2 = rotate( center, h2, 30 * ( currTime.hour() % 12 ) + currTime.minute() / 2 ); |
105 | m2 = rotate( center, m2, time.minute() * 6 ); | 108 | p.setPen( color ); |
106 | p->setPen( color ); | 109 | p.setBrush( color ); |
107 | p->setBrush( color ); | 110 | drawHand( &p, h1, h2 ); |
108 | drawHand( p, m1, m2 ); | 111 | |
109 | } | 112 | |
113 | // draw minute pointer | ||
114 | m1 = rotate( center, m1, currTime.minute() * 6 ); | ||
115 | m2 = rotate( center, m2, currTime.minute() * 6 ); | ||
116 | p.setPen( color ); | ||
117 | p.setBrush( color ); | ||
118 | drawHand( &p, m1, m2 ); | ||
110 | 119 | ||
111 | // draw second pointer | 120 | // draw second pointer |
112 | s1 = rotate( center, s1, time.second() * 6 ); | 121 | s1 = rotate( center, s1, currTime.second() * 6 ); |
113 | s2 = rotate( center, s2, time.second() * 6 ); | 122 | s2 = rotate( center, s2, currTime.second() * 6 ); |
114 | p->setPen( QPen( color, w_sec ) ); | 123 | p.setPen( QPen( color, w_sec ) ); |
115 | p->drawLine( s1, s2 ); | 124 | p.drawLine( s1, s2 ); |
116 | 125 | ||
117 | // cap | 126 | // cap |
118 | p->setBrush(color); | 127 | p.setBrush(color); |
119 | p->drawEllipse( center.x()-w_hour/2, center.y()-w_hour/2, w_hour, w_hour ); | 128 | p.drawEllipse( center.x()-w_hour/2, center.y()-w_hour/2, w_hour, w_hour ); |
129 | |||
130 | prevTime = currTime; | ||
131 | |||
132 | p.end(); | ||
120 | 133 | ||
121 | if ( !clear ) | 134 | p.begin( this ); |
122 | prevTime = currTime; | 135 | p.drawPixmap( 0, 0, *_pixmap ); |
136 | |||
137 | /* leave */ | ||
123 | } | 138 | } |
124 | 139 | ||
@@ -187,7 +202,4 @@ void AnalogClock::display( const QTime& t ) | |||
187 | { | 202 | { |
188 | currTime = t; | 203 | currTime = t; |
189 | clear = true; | ||
190 | repaint( false ); | ||
191 | clear = false; | ||
192 | repaint( false ); | 204 | repaint( false ); |
193 | } | 205 | } |
diff --git a/noncore/tools/clock/analogclock.h b/noncore/tools/clock/analogclock.h index 3aa035e..2287888 100644 --- a/noncore/tools/clock/analogclock.h +++ b/noncore/tools/clock/analogclock.h | |||
@@ -29,4 +29,5 @@ class AnalogClock : public QFrame | |||
29 | public: | 29 | public: |
30 | AnalogClock( QWidget *parent=0, const char *name=0 ); | 30 | AnalogClock( QWidget *parent=0, const char *name=0 ); |
31 | ~AnalogClock(); | ||
31 | 32 | ||
32 | QSizePolicy sizePolicy() const; | 33 | QSizePolicy sizePolicy() const; |
@@ -43,5 +44,5 @@ private: | |||
43 | QTime currTime; | 44 | QTime currTime; |
44 | QTime prevTime; | 45 | QTime prevTime; |
45 | bool clear; | 46 | QPixmap *_pixmap; |
46 | }; | 47 | }; |
47 | 48 | ||