From d796c9dd933ab96ec83b9a634feedd5d32e1ba3f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 8 Nov 2011 12:31:36 -0600 Subject: Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731 --- examples/forever/forever.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 examples/forever/forever.cpp (limited to 'examples/forever/forever.cpp') diff --git a/examples/forever/forever.cpp b/examples/forever/forever.cpp new file mode 100644 index 00000000..27857254 --- /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 +#include +#include +#include // 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; astart( 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 +} -- cgit v1.2.3