summaryrefslogtreecommitdiff
authorzecke <zecke>2004-08-22 23:17:08 (UTC)
committer zecke <zecke>2004-08-22 23:17:08 (UTC)
commita1cb5750328eb4e6d232568c5cc5b8ba7ef99eb5 (patch) (side-by-side diff)
tree49a955d1eb6e44f9acd8c82908928082fd067409
parent3f4e6c92a607424e0af2c551525a2e4915fdc03e (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/analogclock.cpp112
-rw-r--r--noncore/tools/clock/analogclock.h3
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 @@
#include "analogclock.h"
+#include <qtopia/global.h>
+
#include <qlayout.h>
#include <qpainter.h>
-#include <qtopia/global.h>
+#include <qpixmap.h>
+
#include <math.h>
@@ -30,7 +33,15 @@ const double deg2rad = 0.017453292519943295769; // pi/180
AnalogClock::AnalogClock( QWidget *parent, const char *name )
- : QFrame( parent, name ), clear(false)
+ : QFrame( parent, name )
{
setMinimumSize(50,50);
+
+ /* initial the buffer pixmap */
+ QRect r = contentsRect();
+ _pixmap = new QPixmap( r.width(), r.height() );
+}
+
+AnalogClock::~AnalogClock() {
+ delete _pixmap;
}
@@ -40,13 +51,10 @@ QSizePolicy AnalogClock::sizePolicy() const
}
-void AnalogClock::drawContents( QPainter *p )
+void AnalogClock::drawContents( QPainter * )
{
-#if !defined(NO_DEBUG)
- static bool first = true;
- if ( first ) {
-// QTOPIA_PROFILE("first paint event");
- first = false;
- }
-#endif
+ /* no need to draw... */
+ if ( !isVisible() )
+ return;
+
QRect r = contentsRect();
@@ -57,4 +65,13 @@ void AnalogClock::drawContents( QPainter *p )
}
+ /* resize the buffer */
+ if ( r.width() != _pixmap->width() ||
+ r.height() != _pixmap->height() )
+ _pixmap->resize( r.width(), r.height() );
+
+ QPainter p;
+ p.begin( _pixmap );
+
+
QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 );
@@ -75,50 +92,48 @@ void AnalogClock::drawContents( QPainter *p )
QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
- QColor color( clear ? backgroundColor() : black );
- QTime time = clear ? prevTime : currTime;
+ /* fill the pixmap */
+ _pixmap->fill( this, 0, 0 );
- if ( clear && prevTime.secsTo(currTime) > 1 ) {
- p->eraseRect( rect() );
- return;
- }
- 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 ) );
- }
+ // draw ticks
+ QColor color = black;
+ 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 ( !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 ( !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 hour pointer
+ h1 = rotate( center, h1, 30 * ( currTime.hour() % 12 ) + currTime.minute() / 2 );
+ h2 = rotate( center, h2, 30 * ( currTime.hour() % 12 ) + currTime.minute() / 2 );
+ p.setPen( color );
+ p.setBrush( color );
+ drawHand( &p, h1, h2 );
+
+
+ // draw minute pointer
+ m1 = rotate( center, m1, currTime.minute() * 6 );
+ m2 = rotate( center, m2, currTime.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 );
+ s1 = rotate( center, s1, currTime.second() * 6 );
+ s2 = rotate( center, s2, currTime.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 );
+ p.setBrush(color);
+ p.drawEllipse( center.x()-w_hour/2, center.y()-w_hour/2, w_hour, w_hour );
+
+ prevTime = currTime;
+
+ p.end();
- if ( !clear )
- prevTime = currTime;
+ p.begin( this );
+ p.drawPixmap( 0, 0, *_pixmap );
+
+ /* leave */
}
@@ -187,7 +202,4 @@ void AnalogClock::display( const QTime& t )
{
currTime = t;
- clear = true;
- repaint( false );
- clear = false;
repaint( false );
}
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
public:
AnalogClock( QWidget *parent=0, const char *name=0 );
+ ~AnalogClock();
QSizePolicy sizePolicy() const;
@@ -43,5 +44,5 @@ private:
QTime currTime;
QTime prevTime;
- bool clear;
+ QPixmap *_pixmap;
};