diff options
author | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/aclock | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/aclock')
-rw-r--r-- | examples/aclock/README | 5 | ||||
-rw-r--r-- | examples/aclock/aclock.cpp | 147 | ||||
-rw-r--r-- | examples/aclock/aclock.doc | 28 | ||||
-rw-r--r-- | examples/aclock/aclock.h | 44 | ||||
-rw-r--r-- | examples/aclock/aclock.pro | 11 | ||||
-rw-r--r-- | examples/aclock/main.cpp | 27 |
6 files changed, 262 insertions, 0 deletions
diff --git a/examples/aclock/README b/examples/aclock/README new file mode 100644 index 000000000..82857aedb --- /dev/null +++ b/examples/aclock/README @@ -0,0 +1,5 @@ +The aclock program displays an analog clock widget. + +See also the dclock sample that displays a digital LCD clock and can +switch between time and date. + diff --git a/examples/aclock/aclock.cpp b/examples/aclock/aclock.cpp new file mode 100644 index 000000000..5c6a88882 --- /dev/null +++ b/examples/aclock/aclock.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "aclock.h" +#include <qtimer.h> +#include <qpainter.h> +#include <qbitmap.h> + +// +// Constructs an analog clock widget that uses an internal TQTimer. +// + +AnalogClock::AnalogClock( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + time = TQTime::currentTime(); // get current time + internalTimer = new TQTimer( this ); // create internal timer + connect( internalTimer, SIGNAL(timeout()), SLOT(timeout()) ); + internalTimer->start( 5000 ); // emit signal every 5 seconds +} + +void AnalogClock::mousePressEvent( TQMouseEvent *e ) +{ + if(isTopLevel()) + clickPos = e->pos() + TQPoint(geometry().topLeft() - frameGeometry().topLeft()); +} + +void AnalogClock::mouseMoveEvent( TQMouseEvent *e ) +{ + if(isTopLevel()) + move( e->globalPos() - clickPos ); +} + +// +// The TQTimer::timeout() signal is received by this slot. +// + +// +// When we set an explicit time we don't want the timeout() slot to be +// called anymore as this relies on currentTime() +// +void AnalogClock::setTime( const TQTime & t ) +{ + time = t; + disconnect( internalTimer, SIGNAL(timeout()), this, SLOT(timeout()) ); + if (autoMask()) + updateMask(); + else + update(); +} + + +void AnalogClock::timeout() +{ + TQTime old_time = time; + time = TQTime::currentTime(); + if ( old_time.minute() != time.minute() + || old_time.hour() != time.hour() ) { // minute or hour has changed + if (autoMask()) + updateMask(); + else + update(); + } +} + + +void AnalogClock::paintEvent( TQPaintEvent * ) +{ + if ( autoMask() ) + return; + TQPainter paint( this ); + paint.setBrush( colorGroup().foreground() ); + drawClock( &paint ); +} + +// If the clock is transparent, we use updateMask() +// instead of paintEvent() + +void AnalogClock::updateMask() // paint clock mask +{ + TQBitmap bm( size() ); + bm.fill( color0 ); //transparent + + TQPainter paint; + paint.begin( &bm, this ); + paint.setBrush( color1 ); // use non-transparent color + paint.setPen( color1 ); + + drawClock( &paint ); + + paint.end(); + setMask( bm ); +} + +// +// The clock is painted using a 1000x1000 square coordinate system, in +// the a centered square, as big as possible. The painter's pen and +// brush colors are used. +// +void AnalogClock::drawClock( TQPainter *paint ) +{ + paint->save(); + + paint->setWindow( -500,-500, 1000,1000 ); + + TQRect v = paint->viewport(); + int d = TQMIN( v.width(), v.height() ); + paint->setViewport( v.left() + (v.width()-d)/2, + v.top() + (v.height()-d)/2, d, d ); + + TQPointArray pts; + + paint->save(); + paint->rotate( 30*(time.hour()%12-3) + time.minute()/2 ); + pts.setPoints( 4, -20,0, 0,-20, 300,0, 0,20 ); + paint->drawConvexPolygon( pts ); + paint->restore(); + + paint->save(); + paint->rotate( (time.minute()-15)*6 ); + pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 ); + paint->drawConvexPolygon( pts ); + paint->restore(); + + for ( int i=0; i<12; i++ ) { + paint->drawLine( 440,0, 460,0 ); + paint->rotate( 30 ); + } + + paint->restore(); +} + + +void AnalogClock::setAutoMask(bool b) +{ + if (b) + setBackgroundMode( PaletteForeground ); + else + setBackgroundMode( PaletteBackground ); + TQWidget::setAutoMask(b); +} diff --git a/examples/aclock/aclock.doc b/examples/aclock/aclock.doc new file mode 100644 index 000000000..c45fd242b --- /dev/null +++ b/examples/aclock/aclock.doc @@ -0,0 +1,28 @@ +/* +*/ +/*! \page aclock-example.html + + \ingroup examples + \title Analog Clock + + This example displays an analog clock widget. + + <hr> + + Header file: + + \include aclock/aclock.h + + <hr> + + Implementation: + + \include aclock/aclock.cpp + + <hr> + + Main: + + \include aclock/main.cpp +*/ + diff --git a/examples/aclock/aclock.h b/examples/aclock/aclock.h new file mode 100644 index 000000000..dcd5728d2 --- /dev/null +++ b/examples/aclock/aclock.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef ACLOCK_H +#define ACLOCK_H + +#include <qwidget.h> +#include <qdatetime.h> + +class TQTimer; +class AnalogClock : public TQWidget // analog clock widget +{ + Q_OBJECT +public: + AnalogClock( TQWidget *parent=0, const char *name=0 ); + void setAutoMask(bool b); + +protected: + void updateMask(); + void paintEvent( TQPaintEvent *); + void mousePressEvent( TQMouseEvent *); + void mouseMoveEvent( TQMouseEvent *); + void drawClock( TQPainter* ); + +private slots: + void timeout(); + +public slots: + void setTime( const TQTime & t ); + +private: + TQPoint clickPos; + TQTime time; + TQTimer *internalTimer; +}; + + +#endif // ACLOCK_H diff --git a/examples/aclock/aclock.pro b/examples/aclock/aclock.pro new file mode 100644 index 000000000..0b3b0123a --- /dev/null +++ b/examples/aclock/aclock.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = aclock + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = full-config + +HEADERS = aclock.h +SOURCES = aclock.cpp \ + main.cpp diff --git a/examples/aclock/main.cpp b/examples/aclock/main.cpp new file mode 100644 index 000000000..374e468bf --- /dev/null +++ b/examples/aclock/main.cpp @@ -0,0 +1,27 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "aclock.h" +#include <qapplication.h> + + +int main( int argc, char **argv ) +{ + TQApplication a( argc, argv ); + AnalogClock *clock = new AnalogClock; + if ( argc == 2 && strcmp( argv[1], "-transparent" ) == 0 ) + clock->setAutoMask( TRUE ); + clock->resize( 100, 100 ); + a.setMainWidget( clock ); + clock->setCaption("TQt Example - Analog Clock"); + clock->show(); + int result = a.exec(); + delete clock; + return result; +} |