summaryrefslogtreecommitdiff
authorzecke <zecke>2004-08-22 22:21:26 (UTC)
committer zecke <zecke>2004-08-22 22:21:26 (UTC)
commit3f4e6c92a607424e0af2c551525a2e4915fdc03e (patch) (side-by-side diff)
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) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/analogclock.cpp112
-rw-r--r--noncore/tools/clock/analogclock.h1
2 files changed, 59 insertions, 54 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
@@ -36,91 +36,96 @@ AnalogClock::AnalogClock( QWidget *parent, const char *name )
QSizePolicy AnalogClock::sizePolicy() const
{
return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
}
void AnalogClock::drawContents( QPainter *p )
{
+#if !defined(NO_DEBUG)
+ static bool first = true;
+ if ( first ) {
+// QTOPIA_PROFILE("first paint event");
+ first = false;
+ }
+#endif
QRect r = contentsRect();
if ( r.width() < r.height() ) {
r.setY( (r.height() - r.width())/2 );
r.setHeight( r.width() );
}
- QPoint l1( r.x() + r.width() / 2, r.y() + 2 );
- QPoint l2( r.x() + r.width() / 2, r.y() + 8 );
QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 );
- QBrush bgBrush = colorGroup().brush( QColorGroup::Background );
-
-// if ( clear ){
- p->fillRect ( r, bgBrush );
-
-
- // draw ticks
- p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) );
- for ( int i = 0; i < 12; i++ )
- p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
-// }else {
-// p->setBrush( bgBrush );
-// drawPointers ( p, r, colorGroup ( ). color ( QColorGroup::Background ), prevTime, &currTime );
-// }
+ const int w_tick = r.width()/300+1;
+ const int w_sec = r.width()/400+1;
+ const int w_hour = r.width()/80+1;
- QColor col = colorGroup().color( QColorGroup::Text );
- p->setBrush( col );
- drawPointers ( p, r, col, currTime );
-
-
- prevTime = currTime;
-}
-
-void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 )
-{
- QPoint center = r. center ( );
+ QPoint l1( r.x() + r.width() / 2, r.y() + 2 );
+ QPoint l2( r.x() + r.width() / 2, r.y() + 8 );
+ QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 );
+ QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
- QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 );
- QPoint h2( center. x ( ), center. y ( ) );
+ QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 9 );
+ QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
- QPoint m1( center. x ( ), r.y() + r.height() / 8 );
- QPoint m2( center. x ( ), center. y ( ) );
+ QPoint s1( r.x() + r.width() / 2, r.y() + 8 );
+ QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
- QPoint s1( center. x ( ), r. y ( ) + 8 );
- QPoint s2( center. x ( ), center. y ( ) );
+ QColor color( clear ? backgroundColor() : black );
+ QTime time = clear ? prevTime : currTime;
+ if ( clear && prevTime.secsTo(currTime) > 1 ) {
+ p->eraseRect( rect() );
+ return;
+ }
- if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) {
- // draw hour pointer
- h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 );
- h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 );
- p-> setPen ( QPen ( c, 3 ));
- drawHand( p, h1, h2 );
+ if ( !clear ) {
+ // draw ticks
+ p->setPen( QPen( color, w_tick ) );
+ for ( int i = 0; i < 12; i++ )
+ p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
}
- if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) {
- // draw minute pointer
- m1 = rotate( center, m1, t.minute() * 6 );
- m2 = rotate( center, m2, t.minute() * 6 );
- p-> setPen ( QPen ( c, 2 ));
- drawHand( p, m1, m2 );
+ if ( !clear || prevTime.minute() != currTime.minute() ||
+ prevTime.hour() != currTime.hour() ) {
+ // draw hour pointer
+ h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
+ h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
+ p->setPen( color );
+ p->setBrush( color );
+ drawHand( p, h1, h2 );
}
- if ( !t2 || ( t. second ( ) != t2-> second ( ))) {
- // draw second pointer
- s1 = rotate( center, s1, t.second() * 6 );
- s2 = rotate( center, s2, t.second() * 6 );
- p-> setPen ( QPen ( c, 1 ));
- p-> drawLine ( s1, s2 );
+ if ( !clear || prevTime.minute() != currTime.minute() ) {
+ // draw minute pointer
+ m1 = rotate( center, m1, time.minute() * 6 );
+ m2 = rotate( center, m2, time.minute() * 6 );
+ p->setPen( color );
+ p->setBrush( color );
+ drawHand( p, m1, m2 );
}
-}
+ // draw second pointer
+ s1 = rotate( center, s1, time.second() * 6 );
+ s2 = rotate( center, s2, time.second() * 6 );
+ p->setPen( QPen( color, w_sec ) );
+ p->drawLine( s1, s2 );
+
+ // cap
+ p->setBrush(color);
+ p->drawEllipse( center.x()-w_hour/2, center.y()-w_hour/2, w_hour, w_hour );
+
+ if ( !clear )
+ prevTime = currTime;
+}
// Dijkstra's bisection algorithm to find the square root as an integer.
static uint int_sqrt(uint n)
{
if ( n >= UINT_MAX>>2 ) // n must be in the range 0...UINT_MAX/2-1
return 2*int_sqrt( n/4 );
uint h, p= 0, q= 1, r= n;
@@ -176,19 +181,20 @@ void AnalogClock::drawHand( QPainter *p, QPoint p1, QPoint p2 )
pa[3] = p1;
p->drawPolygon( pa );
}
void AnalogClock::display( const QTime& t )
{
currTime = t;
+ clear = true;
+ repaint( false );
clear = false;
repaint( false );
- clear = true;
}
QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
{
double angle = deg2rad * ( - a + 180 );
double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
( p.y() - c.y() ) * sin( angle );
double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
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
@@ -31,17 +31,16 @@ public:
QSizePolicy sizePolicy() const;
void display( const QTime& time );
protected:
void drawContents( QPainter *p );
void drawHand( QPainter *p, QPoint, QPoint );
- void drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0);
private:
QPoint rotate( QPoint center, QPoint p, int angle );
QTime currTime;
QTime prevTime;
bool clear;
};