summaryrefslogtreecommitdiff
authorzecke <zecke>2004-08-22 22:21:26 (UTC)
committer zecke <zecke>2004-08-22 22:21:26 (UTC)
commit3f4e6c92a607424e0af2c551525a2e4915fdc03e (patch) (unidiff)
tree1fbc04167adc12986fdaf0fff6d7f5b277cc573a
parent8b5ab9a283c219aaba84a8b23adc6c3d29cef7d5 (diff)
downloadopie-3f4e6c92a607424e0af2c551525a2e4915fdc03e.zip
opie-3f4e6c92a607424e0af2c551525a2e4915fdc03e.tar.gz
opie-3f4e6c92a607424e0af2c551525a2e4915fdc03e.tar.bz2
Revert last try to remove flicker for all styles but have
problems with liquid
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/clock/analogclock.cpp98
-rw-r--r--noncore/tools/clock/analogclock.h1
2 files changed, 52 insertions, 47 deletions
diff --git a/noncore/tools/clock/analogclock.cpp b/noncore/tools/clock/analogclock.cpp
index 7f8ca67..c5f0155 100644
--- a/noncore/tools/clock/analogclock.cpp
+++ b/noncore/tools/clock/analogclock.cpp
@@ -41,6 +41,13 @@ QSizePolicy AnalogClock::sizePolicy() const
41 41
42void AnalogClock::drawContents( QPainter *p ) 42void AnalogClock::drawContents( QPainter *p )
43{ 43{
44#if !defined(NO_DEBUG)
45 static bool first = true;
46 if ( first ) {
47 //QTOPIA_PROFILE("first paint event");
48 first = false;
49 }
50#endif
44 51
45 QRect r = contentsRect(); 52 QRect r = contentsRect();
46 53
@@ -49,73 +56,71 @@ void AnalogClock::drawContents( QPainter *p )
49 r.setHeight( r.width() ); 56 r.setHeight( r.width() );
50 } 57 }
51 58
52 QPoint l1( r.x() + r.width() / 2, r.y() + 2 );
53 QPoint l2( r.x() + r.width() / 2, r.y() + 8 );
54 QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 59 QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 );
55 60
56 QBrush bgBrush = colorGroup().brush( QColorGroup::Background ); 61 const int w_tick = r.width()/300+1;
62 const int w_sec = r.width()/400+1;
63 const int w_hour = r.width()/80+1;
57 64
58// if ( clear ){ 65 QPoint l1( r.x() + r.width() / 2, r.y() + 2 );
59 p->fillRect ( r, bgBrush ); 66 QPoint l2( r.x() + r.width() / 2, r.y() + 8 );
60 67
68 QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 );
69 QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
61 70
62 // draw ticks 71 QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 9 );
63 p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); 72 QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
64 for ( int i = 0; i < 12; i++ )
65 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
66// }else {
67// p->setBrush( bgBrush );
68// drawPointers ( p, r, colorGroup ( ). color ( QColorGroup::Background ), prevTime, &currTime );
69// }
70 73
71 QColor col = colorGroup().color( QColorGroup::Text ); 74 QPoint s1( r.x() + r.width() / 2, r.y() + 8 );
72 p->setBrush( col ); 75 QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
73 drawPointers ( p, r, col, currTime );
74 76
77 QColor color( clear ? backgroundColor() : black );
78 QTime time = clear ? prevTime : currTime;
75 79
76 prevTime = currTime; 80 if ( clear && prevTime.secsTo(currTime) > 1 ) {
81 p->eraseRect( rect() );
82 return;
77} 83}
78 84
79void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) 85 if ( !clear ) {
80{ 86 // draw ticks
81 QPoint center = r. center ( ); 87 p->setPen( QPen( color, w_tick ) );
82 88 for ( int i = 0; i < 12; i++ )
83 89 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
84 QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); 90 }
85 QPoint h2( center. x ( ), center. y ( ) );
86
87 QPoint m1( center. x ( ), r.y() + r.height() / 8 );
88 QPoint m2( center. x ( ), center. y ( ) );
89
90 QPoint s1( center. x ( ), r. y ( ) + 8 );
91 QPoint s2( center. x ( ), center. y ( ) );
92
93 91
94 if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { 92 if ( !clear || prevTime.minute() != currTime.minute() ||
93 prevTime.hour() != currTime.hour() ) {
95 // draw hour pointer 94 // draw hour pointer
96 h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); 95 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
97 h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); 96 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
98 p-> setPen ( QPen ( c, 3 )); 97 p->setPen( color );
98 p->setBrush( color );
99 drawHand( p, h1, h2 ); 99 drawHand( p, h1, h2 );
100 } 100 }
101 101
102 if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { 102 if ( !clear || prevTime.minute() != currTime.minute() ) {
103 // draw minute pointer 103 // draw minute pointer
104 m1 = rotate( center, m1, t.minute() * 6 ); 104 m1 = rotate( center, m1, time.minute() * 6 );
105 m2 = rotate( center, m2, t.minute() * 6 ); 105 m2 = rotate( center, m2, time.minute() * 6 );
106 p-> setPen ( QPen ( c, 2 )); 106 p->setPen( color );
107 p->setBrush( color );
107 drawHand( p, m1, m2 ); 108 drawHand( p, m1, m2 );
108 } 109 }
109 110
110 if ( !t2 || ( t. second ( ) != t2-> second ( ))) {
111 // draw second pointer 111 // draw second pointer
112 s1 = rotate( center, s1, t.second() * 6 ); 112 s1 = rotate( center, s1, time.second() * 6 );
113 s2 = rotate( center, s2, t.second() * 6 ); 113 s2 = rotate( center, s2, time.second() * 6 );
114 p-> setPen ( QPen ( c, 1 )); 114 p->setPen( QPen( color, w_sec ) );
115 p-> drawLine ( s1, s2 ); 115 p-> drawLine ( s1, s2 );
116 }
117}
118 116
117 // cap
118 p->setBrush(color);
119 p->drawEllipse( center.x()-w_hour/2, center.y()-w_hour/2, w_hour, w_hour );
120
121 if ( !clear )
122 prevTime = currTime;
123}
119 124
120// Dijkstra's bisection algorithm to find the square root as an integer. 125// Dijkstra's bisection algorithm to find the square root as an integer.
121 126
@@ -181,9 +186,10 @@ void AnalogClock::drawHand( QPainter *p, QPoint p1, QPoint p2 )
181void AnalogClock::display( const QTime& t ) 186void AnalogClock::display( const QTime& t )
182{ 187{
183 currTime = t; 188 currTime = t;
189 clear = true;
190 repaint( false );
184 clear = false; 191 clear = false;
185 repaint( false ); 192 repaint( false );
186 clear = true;
187} 193}
188 194
189QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) 195QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
diff --git a/noncore/tools/clock/analogclock.h b/noncore/tools/clock/analogclock.h
index 5f30d68..3aa035e 100644
--- a/noncore/tools/clock/analogclock.h
+++ b/noncore/tools/clock/analogclock.h
@@ -36,7 +36,6 @@ public:
36protected: 36protected:
37 void drawContents( QPainter *p ); 37 void drawContents( QPainter *p );
38 void drawHand( QPainter *p, QPoint, QPoint ); 38 void drawHand( QPainter *p, QPoint, QPoint );
39 void drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0);
40 39
41private: 40private:
42 QPoint rotate( QPoint center, QPoint p, int angle ); 41 QPoint rotate( QPoint center, QPoint p, int angle );