summaryrefslogtreecommitdiffstats
path: root/examples/forever
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
committerTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/forever
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/forever')
-rw-r--r--examples/forever/README4
-rw-r--r--examples/forever/forever.cpp99
-rw-r--r--examples/forever/forever.doc25
-rw-r--r--examples/forever/forever.h39
-rw-r--r--examples/forever/forever.pro10
5 files changed, 177 insertions, 0 deletions
diff --git a/examples/forever/README b/examples/forever/README
new file mode 100644
index 000000000..b3fbbb679
--- /dev/null
+++ b/examples/forever/README
@@ -0,0 +1,4 @@
+The forever program draws filled rectangles with random color and random
+position and size.
+
+WARNING: This program has a strobe effect.
diff --git a/examples/forever/forever.cpp b/examples/forever/forever.cpp
new file mode 100644
index 000000000..278572541
--- /dev/null
+++ b/examples/forever/forever.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** 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 <qtimer.h>
+#include <qpainter.h>
+#include <qapplication.h>
+#include <stdlib.h> // defines rand() function
+
+#include "forever.h"
+
+
+//
+// Forever - a widget that draws rectangles forever.
+//
+
+//
+// Constructs a Forever widget.
+//
+
+Forever::Forever( TQWidget *parent, const char *name )
+ : TQWidget( parent, name )
+{
+ for (int a=0; a<numColors; a++) {
+ colors[a] = TQColor( rand()&255,
+ rand()&255,
+ rand()&255 );
+ }
+ rectangles = 0;
+ startTimer( 0 ); // run continuous timer
+ TQTimer * counter = new TQTimer( this );
+ connect( counter, SIGNAL(timeout()),
+ this, SLOT(updateCaption()) );
+ counter->start( 1000 );
+}
+
+
+void Forever::updateCaption()
+{
+ TQString s;
+ s.sprintf( "TQt Example - Forever - %d rectangles/second", rectangles );
+ rectangles = 0;
+ setCaption( s );
+}
+
+
+//
+// Handles paint events for the Forever widget.
+//
+
+void Forever::paintEvent( TQPaintEvent * )
+{
+ TQPainter paint( this ); // painter object
+ int w = width();
+ int h = height();
+ if(w <= 0 || h <= 0)
+ return;
+ paint.setPen( NoPen ); // do not draw outline
+ paint.setBrush( colors[rand() % numColors]);// set random brush color
+
+ TQPoint p1( rand()%w, rand()%h ); // p1 = top left
+ TQPoint p2( rand()%w, rand()%h ); // p2 = bottom right
+
+ TQRect r( p1, p2 );
+ paint.drawRect( r ); // draw filled rectangle
+}
+
+//
+// Handles timer events for the Forever widget.
+//
+
+void Forever::timerEvent( TQTimerEvent * )
+{
+ for ( int i=0; i<100; i++ ) {
+ repaint( FALSE ); // repaint, don't erase
+ rectangles++;
+ }
+}
+
+
+//
+// Create and display Forever widget.
+//
+
+int main( int argc, char **argv )
+{
+ TQApplication a( argc, argv ); // create application object
+ Forever always; // create widget
+ always.resize( 400, 250 ); // start up with size 400x250
+ a.setMainWidget( &always ); // set as main widget
+ always.setCaption("TQt Example - Forever");
+ always.show(); // show widget
+ return a.exec(); // run event loop
+}
diff --git a/examples/forever/forever.doc b/examples/forever/forever.doc
new file mode 100644
index 000000000..be5633328
--- /dev/null
+++ b/examples/forever/forever.doc
@@ -0,0 +1,25 @@
+
+/*
+*/
+/*! \page forever-example.html
+
+ \ingroup examples
+ \title A Rectangle Draw "Benchmark"
+
+ This example continuously draws rectangles in a window and
+ has another widget that counts the number of rectangles that
+ are drawn per second.
+
+ <hr>
+
+ Header file:
+
+ \include forever/forever.h
+
+ <hr>
+
+ Implementation:
+
+ \include forever/forever.cpp
+*/
+
diff --git a/examples/forever/forever.h b/examples/forever/forever.h
new file mode 100644
index 000000000..480e5691c
--- /dev/null
+++ b/examples/forever/forever.h
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Definition of something or other
+**
+** Created : 979899
+**
+** Copyright (C) 1997-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 FOREVER_H
+#define FOREVER_H
+
+#include <qwidget.h>
+
+
+const int numColors = 120;
+
+
+class Forever : public TQWidget
+{
+ Q_OBJECT
+public:
+ Forever( TQWidget *parent=0, const char *name=0 );
+protected:
+ void paintEvent( TQPaintEvent * );
+ void timerEvent( TQTimerEvent * );
+private slots:
+ void updateCaption();
+private:
+ int rectangles;
+ TQColor colors[numColors];
+};
+
+
+#endif
diff --git a/examples/forever/forever.pro b/examples/forever/forever.pro
new file mode 100644
index 000000000..2886d983a
--- /dev/null
+++ b/examples/forever/forever.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+TARGET = forever
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../include
+
+REQUIRES = small-config
+
+HEADERS = forever.h
+SOURCES = forever.cpp