summaryrefslogtreecommitdiffstats
path: root/examples/progressbar
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/progressbar
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/progressbar')
-rw-r--r--examples/progressbar/main.cpp23
-rw-r--r--examples/progressbar/progressbar.cpp165
-rw-r--r--examples/progressbar/progressbar.doc29
-rw-r--r--examples/progressbar/progressbar.h40
-rw-r--r--examples/progressbar/progressbar.pro11
5 files changed, 268 insertions, 0 deletions
diff --git a/examples/progressbar/main.cpp b/examples/progressbar/main.cpp
new file mode 100644
index 000000000..73a5fbc8e
--- /dev/null
+++ b/examples/progressbar/main.cpp
@@ -0,0 +1,23 @@
+/****************************************************************************
+**
+** 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 "progressbar.h"
+#include <qapplication.h>
+
+int main(int argc,char **argv)
+{
+ TQApplication a(argc,argv);
+
+ ProgressBar progressbar;
+ progressbar.setCaption("TQt Example - ProgressBar");
+ a.setMainWidget(&progressbar);
+ progressbar.show();
+
+ return a.exec();
+}
diff --git a/examples/progressbar/progressbar.cpp b/examples/progressbar/progressbar.cpp
new file mode 100644
index 000000000..9befa6e80
--- /dev/null
+++ b/examples/progressbar/progressbar.cpp
@@ -0,0 +1,165 @@
+/****************************************************************************
+**
+** 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 "progressbar.h"
+
+#include <qradiobutton.h>
+#include <qpushbutton.h>
+#include <qprogressbar.h>
+#include <qlayout.h>
+
+#include <qmotifstyle.h>
+
+/*
+ * Constructor
+ *
+ * Creates child widgets of the ProgressBar widget
+ */
+
+ProgressBar::ProgressBar( TQWidget *parent, const char *name )
+ : TQButtonGroup( 0, Horizontal, "Progress Bar", parent, name ), timer()
+{
+ setMargin( 10 );
+
+ TQGridLayout* toplayout = new TQGridLayout( layout(), 2, 2, 5);
+
+ setRadioButtonExclusive( TRUE );
+
+ // insert three radiobuttons which the user can use
+ // to set the speed of the progress and two pushbuttons
+ // to start/pause/continue and reset the progress
+ slow = new TQRadioButton( "S&low", this );
+ normal = new TQRadioButton( "&Normal", this );
+ fast = new TQRadioButton( "&Fast", this );
+ TQVBoxLayout* vb1 = new TQVBoxLayout;
+ toplayout->addLayout( vb1, 0, 0 );
+ vb1->addWidget( slow );
+ vb1->addWidget( normal );
+ vb1->addWidget( fast );
+
+ // two push buttons, one for start, for for reset.
+ start = new TQPushButton( "&Start", this );
+ reset = new TQPushButton( "&Reset", this );
+ TQVBoxLayout* vb2 = new TQVBoxLayout;
+ toplayout->addLayout( vb2, 0, 1 );
+ vb2->addWidget( start );
+ vb2->addWidget( reset );
+
+ // Create the progressbar
+ progress = new TQProgressBar( 100, this );
+ // progress->setStyle( new TQMotifStyle() );
+ toplayout->addMultiCellWidget( progress, 1, 1, 0, 1 );
+
+ // connect the clicked() SIGNALs of the pushbuttons to SLOTs
+ connect( start, SIGNAL( clicked() ), this, SLOT( slotStart() ) );
+ connect( reset, SIGNAL( clicked() ), this, SLOT( slotReset() ) );
+
+ // connect the timeout() SIGNAL of the progress-timer to a SLOT
+ connect( &timer, SIGNAL( timeout() ), this, SLOT( slotTimeout() ) );
+
+ // Let's start with normal speed...
+ normal->setChecked( TRUE );
+
+
+ // some contraints
+ start->setFixedWidth( 80 );
+ setMinimumWidth( 300 );
+}
+
+/*
+ * SLOT slotStart
+ *
+ * This SLOT is called if the user clicks start/pause/continue
+ * button
+ */
+
+void ProgressBar::slotStart()
+{
+ // If the progress bar is at the beginning...
+ if ( progress->progress() == -1 ) {
+ // ...set according to the checked speed-radiobutton
+ // the number of steps which are needed to complete the process
+ if ( slow->isChecked() )
+ progress->setTotalSteps( 10000 );
+ else if ( normal->isChecked() )
+ progress->setTotalSteps( 1000 );
+ else
+ progress->setTotalSteps( 50 );
+
+ // disable the speed-radiobuttons
+ slow->setEnabled( FALSE );
+ normal->setEnabled( FALSE );
+ fast->setEnabled( FALSE );
+ }
+
+ // If the progress is not running...
+ if ( !timer.isActive() ) {
+ // ...start the timer (and so the progress) with a interval of 1 ms...
+ timer.start( 1 );
+ // ...and rename the start/pause/continue button to Pause
+ start->setText( "&Pause" );
+ } else { // if the prgress is running...
+ // ...stop the timer (and so the prgress)...
+ timer.stop();
+ // ...and rename the start/pause/continue button to Continue
+ start->setText( "&Continue" );
+ }
+}
+
+/*
+ * SLOT slotReset
+ *
+ * This SLOT is called when the user clicks the reset button
+ */
+
+void ProgressBar::slotReset()
+{
+ // stop the timer and progress
+ timer.stop();
+
+ // rename the start/pause/continue button to Start...
+ start->setText( "&Start" );
+ // ...and enable this button
+ start->setEnabled( TRUE );
+
+ // enable the speed-radiobuttons
+ slow->setEnabled( TRUE );
+ normal->setEnabled( TRUE );
+ fast->setEnabled( TRUE );
+
+ // reset the progressbar
+ progress->reset();
+}
+
+/*
+ * SLOT slotTimeout
+ *
+ * This SLOT is called each ms when the timer is
+ * active (== progress is running)
+ */
+
+void ProgressBar::slotTimeout()
+{
+ int p = progress->progress();
+
+#if 1
+ // If the progress is complete...
+ if ( p == progress->totalSteps() ) {
+ // ...rename the start/pause/continue button to Start...
+ start->setText( "&Start" );
+ // ...and disable it...
+ start->setEnabled( FALSE );
+ // ...and return
+ return;
+ }
+#endif
+
+ // If the process is not complete increase it
+ progress->setProgress( ++p );
+}
diff --git a/examples/progressbar/progressbar.doc b/examples/progressbar/progressbar.doc
new file mode 100644
index 000000000..6950c7295
--- /dev/null
+++ b/examples/progressbar/progressbar.doc
@@ -0,0 +1,29 @@
+
+/*
+*/
+/*! \page progressbar-example.html
+
+ \ingroup examples
+ \title Progress Bar
+
+ This example shows how to use a progress bar.
+
+ <hr>
+
+ Header file:
+
+ \include progressbar/progressbar.h
+
+ <hr>
+
+ Implementation:
+
+ \include progressbar/progressbar.cpp
+
+ <hr>
+
+ Main:
+
+ \include progressbar/main.cpp
+*/
+
diff --git a/examples/progressbar/progressbar.h b/examples/progressbar/progressbar.h
new file mode 100644
index 000000000..0fe4bc4a1
--- /dev/null
+++ b/examples/progressbar/progressbar.h
@@ -0,0 +1,40 @@
+/****************************************************************************
+**
+** 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 PROGRESSBAR_H
+#define PROGRESSBAR_H
+
+#include <qbuttongroup.h>
+#include <qtimer.h>
+
+class TQRadioButton;
+class TQPushButton;
+class TQProgressBar;
+
+class ProgressBar : public TQButtonGroup
+{
+ Q_OBJECT
+
+public:
+ ProgressBar( TQWidget *parent = 0, const char *name = 0 );
+
+protected:
+ TQRadioButton *slow, *normal, *fast;
+ TQPushButton *start, *pause, *reset;
+ TQProgressBar *progress;
+ TQTimer timer;
+
+protected slots:
+ void slotStart();
+ void slotReset();
+ void slotTimeout();
+
+};
+
+#endif
diff --git a/examples/progressbar/progressbar.pro b/examples/progressbar/progressbar.pro
new file mode 100644
index 000000000..9b25197cd
--- /dev/null
+++ b/examples/progressbar/progressbar.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = progressbar
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../include
+
+REQUIRES = large-config
+
+HEADERS = progressbar.h
+SOURCES = main.cpp \
+ progressbar.cpp