summaryrefslogtreecommitdiffstats
path: root/examples/life/lifedlg.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/life/lifedlg.cpp
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/life/lifedlg.cpp')
-rw-r--r--examples/life/lifedlg.cpp162
1 files changed, 162 insertions, 0 deletions
diff --git a/examples/life/lifedlg.cpp b/examples/life/lifedlg.cpp
new file mode 100644
index 000000000..1f9af427c
--- /dev/null
+++ b/examples/life/lifedlg.cpp
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** 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 "lifedlg.h"
+#include <qapplication.h>
+#include <qpushbutton.h>
+#include <qlabel.h>
+#include <qslider.h>
+#include <qcombobox.h>
+#include <qdatetime.h>
+#include <stdlib.h>
+
+#include "patterns.cpp"
+
+
+// A simple timer which has a pause and a setSpeed slot
+
+LifeTimer::LifeTimer( TQWidget *parent ) : TQTimer( parent ), interval( 500 )
+{
+ start( interval );
+}
+
+
+void LifeTimer::pause( bool stopIt )
+{
+ if ( stopIt )
+ stop();
+ else
+ start( interval );
+}
+
+
+void LifeTimer::setSpeed( int speed )
+{
+ interval = MAXSPEED - speed;
+ if ( isActive() )
+ changeInterval( interval );
+}
+
+
+// A top-level container widget to organize the others
+
+LifeDialog::LifeDialog( int scale, TQWidget * parent, const char * name )
+ : TQWidget( parent, name )
+{
+ qb = new TQPushButton( "Quit!", this );
+ cb = new TQComboBox( this, "comboBox" );
+ life = new LifeWidget(scale, this);
+ life->move( SIDEBORDER, TOPBORDER );
+
+
+ connect( qb, SIGNAL(clicked()), qApp, SLOT(tquit()) );
+ qb->setGeometry( SIDEBORDER, SIDEBORDER, qb->sizeHint().width(), 25 );
+ timer = new LifeTimer( this );
+
+ connect( timer, SIGNAL(timeout()), life, SLOT(nextGeneration()) );
+ pb = new TQPushButton( "Pause", this );
+ pb->setToggleButton( TRUE );
+ connect( pb, SIGNAL(toggled(bool)), timer, SLOT(pause(bool)) );
+ pb->resize( pb->sizeHint().width(), 25 );
+ pb->move( width() - SIDEBORDER - pb->width(), SIDEBORDER );
+
+ sp = new TQLabel( "Speed:", this );
+ sp->adjustSize();
+ sp->move( SIDEBORDER, 45 );
+ scroll = new TQSlider( 0, LifeTimer::MAXSPEED, 50,
+ LifeTimer::MAXSPEED / 2,
+ TQSlider::Horizontal, this );
+ connect( scroll, SIGNAL(valueChanged(int)),
+ timer, SLOT(setSpeed(int)) );
+
+ scroll->move( sp->width() + 2 * SIDEBORDER, 45 );
+ scroll->resize( 200, 15 );
+
+ life->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
+ life->show();
+
+ srand( TQTime(0,0,0).msecsTo(TQTime::currentTime()) );
+ int sel = rand() % NPATS;
+ getPattern( sel );
+
+ cb->move( 2*SIDEBORDER + qb->width(), SIDEBORDER);
+ cb->insertItem( "Glider Gun " );
+ cb->insertItem( "Figure Eight " );
+ cb->insertItem( "Pulsar " );
+ cb->insertItem( "Barber Pole P2 " );
+ cb->insertItem( "Achim P5 " );
+ cb->insertItem( "Hertz P4 " );
+ cb->insertItem( "Tumbler " );
+ cb->insertItem( "Pulse1 P4" );
+ cb->insertItem( "Shining Flower P5 " );
+ cb->insertItem( "Pulse2 P6 " );
+ cb->insertItem( "Pinwheel, Clock P4 " );
+ cb->insertItem( "Pentadecatholon " );
+ cb->insertItem( "Piston " );
+ cb->insertItem( "Piston2 " );
+ cb->insertItem( "Switch Engine " );
+ cb->insertItem( "Gears (Gear, Flywheel, Blinker) " );
+ cb->insertItem( "Turbine8 " );
+ cb->insertItem( "P16 " );
+ cb->insertItem( "Puffer " );
+ cb->insertItem( "Escort " );
+ cb->insertItem( "Dart Speed 1/3 " );
+ cb->insertItem( "Period 4 Speed 1/2 " );
+ cb->insertItem( "Another Period 4 Speed 1/2 " );
+ cb->insertItem( "Smallest Known Period 3 Spaceship Speed 1/3 " );
+ cb->insertItem( "Turtle Speed 1/3 " );
+ cb->insertItem( "Smallest Known Period 5 Speed 2/5 " );
+ cb->insertItem( "Sym Puffer " );
+ cb->insertItem( "], Near Ship, Pi Heptomino " );
+ cb->insertItem( "R Pentomino " );
+ cb->setAutoResize( FALSE );
+ cb->setCurrentItem( sel );
+ cb->show();
+ connect( cb, SIGNAL(activated(int)), SLOT(getPattern(int)) );
+
+ TQSize s;
+ s = life->minimumSize();
+ setMinimumSize( s.width() + 2 * SIDEBORDER,
+ s.height() + TOPBORDER + SIDEBORDER );
+ s = life->maximumSize();
+ setMaximumSize( s.width() + 2 * SIDEBORDER,
+ s.height() + TOPBORDER + SIDEBORDER );
+ s = life->sizeIncrement();
+ setSizeIncrement( s.width(), s.height() );
+
+ resize( TQMIN(512, qApp->desktop()->width()),
+ TQMIN(480, qApp->desktop()->height()) );
+}
+
+
+void LifeDialog::resizeEvent( TQResizeEvent * e )
+{
+ life->resize( e->size() - TQSize( 2 * SIDEBORDER, TOPBORDER + SIDEBORDER ));
+ pb->move( e->size().width() - SIDEBORDER - pb->width(), SIDEBORDER );
+ scroll->resize( e->size().width() - sp->width() - 3 * SIDEBORDER,
+ scroll->height() );
+ cb->resize( width() - 4*SIDEBORDER - qb->width() - pb->width() , 25 );
+}
+
+
+// Adapted from xlock, see pattern.cpp for copyright info.
+
+void LifeDialog::getPattern( int pat )
+{
+ life->clear();
+ int i = pat % NPATS;
+ int col;
+ int * patptr = &patterns[i][0];
+ while ( (col = *patptr++) != 127 ) {
+ int row = *patptr++;
+ col += life->maxCol() / 2;
+ row += life->maxRow() / 2;
+ life->setPoint( col, row );
+ }
+}