summaryrefslogtreecommitdiffstats
path: root/doc/html/progressbar-example.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/html/progressbar-example.html')
-rw-r--r--doc/html/progressbar-example.html289
1 files changed, 289 insertions, 0 deletions
diff --git a/doc/html/progressbar-example.html b/doc/html/progressbar-example.html
new file mode 100644
index 0000000..fcd3aea
--- /dev/null
+++ b/doc/html/progressbar-example.html
@@ -0,0 +1,289 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/progressbar/progressbar.doc:5 -->
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Progress Bar</title>
+<style type="text/css"><!--
+fn { margin-left: 1cm; text-indent: -1cm; }
+a:link { color: #004faf; text-decoration: none }
+a:visited { color: #672967; text-decoration: none }
+body { background: #ffffff; color: black; }
+--></style>
+</head>
+<body>
+
+<table border="0" cellpadding="0" cellspacing="0" width="100%">
+<tr bgcolor="#E5E5E5">
+<td valign=center>
+ <a href="index.html">
+<font color="#004faf">Home</font></a>
+ | <a href="classes.html">
+<font color="#004faf">All&nbsp;Classes</font></a>
+ | <a href="mainclasses.html">
+<font color="#004faf">Main&nbsp;Classes</font></a>
+ | <a href="annotated.html">
+<font color="#004faf">Annotated</font></a>
+ | <a href="groups.html">
+<font color="#004faf">Grouped&nbsp;Classes</font></a>
+ | <a href="functions.html">
+<font color="#004faf">Functions</font></a>
+</td>
+<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Progress Bar</h1>
+
+
+<p>
+This example shows how to use a progress bar.
+<p> <hr>
+<p> Header file:
+<p> <pre>/****************************************************************************
+** $Id: qt/progressbar.h 3.3.8 edited Jan 11 14:37 $
+**
+** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#ifndef PROGRESSBAR_H
+#define PROGRESSBAR_H
+
+#include &lt;<a href="qbuttongroup-h.html">qbuttongroup.h</a>&gt;
+#include &lt;<a href="qtimer-h.html">qtimer.h</a>&gt;
+
+class QRadioButton;
+class QPushButton;
+class QProgressBar;
+
+class ProgressBar : public <a href="qbuttongroup.html">QButtonGroup</a>
+{
+ <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
+
+public:
+ ProgressBar( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0 );
+
+protected:
+ <a href="qradiobutton.html">QRadioButton</a> *slow, *normal, *fast;
+ <a href="qpushbutton.html">QPushButton</a> *start, *pause, *reset;
+ <a href="qprogressbar.html">QProgressBar</a> *progress;
+ <a href="qtimer.html">QTimer</a> timer;
+
+protected slots:
+ void slotStart();
+ void slotReset();
+ void slotTimeout();
+
+};
+
+#endif
+</pre>
+
+<p> <hr>
+<p> Implementation:
+<p> <pre>/****************************************************************************
+** $Id: qt/progressbar.cpp 3.3.8 edited Jan 11 14:37 $
+**
+** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "progressbar.h"
+
+#include &lt;<a href="qradiobutton-h.html">qradiobutton.h</a>&gt;
+#include &lt;<a href="qpushbutton-h.html">qpushbutton.h</a>&gt;
+#include &lt;<a href="qprogressbar-h.html">qprogressbar.h</a>&gt;
+#include &lt;<a href="qlayout-h.html">qlayout.h</a>&gt;
+
+#include &lt;<a href="qmotifstyle-h.html">qmotifstyle.h</a>&gt;
+
+/*
+ * Constructor
+ *
+ * Creates child widgets of the ProgressBar widget
+ */
+
+<a name="f346"></a>ProgressBar::ProgressBar( <a href="qwidget.html">QWidget</a> *parent, const char *name )
+ : <a href="qbuttongroup.html">QButtonGroup</a>( 0, Horizontal, "Progress Bar", parent, name ), timer()
+{
+ <a href="qframe.html#setMargin">setMargin</a>( 10 );
+
+ <a href="qgridlayout.html">QGridLayout</a>* toplayout = new <a href="qgridlayout.html">QGridLayout</a>( <a href="qwidget.html#layout">layout</a>(), 2, 2, 5);
+
+ <a href="qbuttongroup.html#setRadioButtonExclusive">setRadioButtonExclusive</a>( 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 <a href="qradiobutton.html">QRadioButton</a>( "S&amp;low", this );
+ normal = new <a href="qradiobutton.html">QRadioButton</a>( "&amp;Normal", this );
+ fast = new <a href="qradiobutton.html">QRadioButton</a>( "&amp;Fast", this );
+ <a href="qvboxlayout.html">QVBoxLayout</a>* vb1 = new <a href="qvboxlayout.html">QVBoxLayout</a>;
+<a name="x964"></a> toplayout-&gt;<a href="qgridlayout.html#addLayout">addLayout</a>( vb1, 0, 0 );
+ vb1-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( slow );
+ vb1-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( normal );
+ vb1-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( fast );
+
+ // two push buttons, one for start, for for reset.
+ start = new <a href="qpushbutton.html">QPushButton</a>( "&amp;Start", this );
+ reset = new <a href="qpushbutton.html">QPushButton</a>( "&amp;Reset", this );
+ <a href="qvboxlayout.html">QVBoxLayout</a>* vb2 = new <a href="qvboxlayout.html">QVBoxLayout</a>;
+ toplayout-&gt;<a href="qgridlayout.html#addLayout">addLayout</a>( vb2, 0, 1 );
+ vb2-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( start );
+ vb2-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( reset );
+
+ // Create the progressbar
+ progress = new <a href="qprogressbar.html">QProgressBar</a>( 100, this );
+<a name="x975"></a> // progress-&gt;<a href="qwidget.html#setStyle">setStyle</a>( new <a href="qmotifstyle.html">QMotifStyle</a>() );
+<a name="x965"></a> toplayout-&gt;<a href="qgridlayout.html#addMultiCellWidget">addMultiCellWidget</a>( progress, 1, 1, 0, 1 );
+
+ // connect the clicked() SIGNALs of the pushbuttons to SLOTs
+<a name="x962"></a> <a href="qobject.html#connect">connect</a>( start, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotStart() ) );
+ <a href="qobject.html#connect">connect</a>( reset, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotReset() ) );
+
+ // connect the timeout() SIGNAL of the progress-timer to a SLOT
+ <a href="qobject.html#connect">connect</a>( &amp;timer, SIGNAL( timeout() ), this, SLOT( slotTimeout() ) );
+
+ // Let's start with normal speed...
+<a name="x972"></a> normal-&gt;<a href="qradiobutton.html#setChecked">setChecked</a>( TRUE );
+
+
+ // some contraints
+<a name="x974"></a> start-&gt;<a href="qwidget.html#setFixedWidth">setFixedWidth</a>( 80 );
+ <a href="qwidget.html#setMinimumWidth">setMinimumWidth</a>( 300 );
+}
+
+/*
+ * SLOT slotStart
+ *
+ * This SLOT is called if the user clicks start/pause/continue
+ * button
+ */
+
+void <a name="f347"></a>ProgressBar::slotStart()
+{
+ // If the progress bar is at the beginning...
+<a name="x966"></a> if ( progress-&gt;<a href="qprogressbar.html#progress">progress</a>() == -1 ) {
+ // ...set according to the checked speed-radiobutton
+ // the number of steps which are needed to complete the process
+<a name="x971"></a> if ( slow-&gt;<a href="qradiobutton.html#isChecked">isChecked</a>() )
+<a name="x969"></a> progress-&gt;<a href="qprogressbar.html#setTotalSteps">setTotalSteps</a>( 10000 );
+ else if ( normal-&gt;<a href="qradiobutton.html#isChecked">isChecked</a>() )
+ progress-&gt;<a href="qprogressbar.html#setTotalSteps">setTotalSteps</a>( 1000 );
+ else
+ progress-&gt;<a href="qprogressbar.html#setTotalSteps">setTotalSteps</a>( 50 );
+
+ // disable the speed-radiobuttons
+<a name="x973"></a> slow-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
+ normal-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
+ fast-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( 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
+<a name="x963"></a> start-&gt;<a href="qbutton.html#setText">setText</a>( "&amp;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-&gt;<a href="qbutton.html#setText">setText</a>( "&amp;Continue" );
+ }
+}
+
+/*
+ * SLOT slotReset
+ *
+ * This SLOT is called when the user clicks the reset button
+ */
+
+void <a name="f348"></a>ProgressBar::slotReset()
+{
+ // stop the timer and progress
+ timer.stop();
+
+ // rename the start/pause/continue button to Start...
+ start-&gt;<a href="qbutton.html#setText">setText</a>( "&amp;Start" );
+ // ...and enable this button
+ start-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
+
+ // enable the speed-radiobuttons
+ slow-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
+ normal-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
+ fast-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
+
+ // reset the progressbar
+<a name="x967"></a> progress-&gt;<a href="qprogressbar.html#reset">reset</a>();
+}
+
+/*
+ * SLOT slotTimeout
+ *
+ * This SLOT is called each ms when the timer is
+ * active (== progress is running)
+ */
+
+void <a name="f349"></a>ProgressBar::slotTimeout()
+{
+ int p = progress-&gt;<a href="qprogressbar.html#progress">progress</a>();
+
+#if 1
+ // If the progress is complete...
+<a name="x970"></a> if ( p == progress-&gt;<a href="qprogressbar.html#totalSteps">totalSteps</a>() ) {
+ // ...rename the start/pause/continue button to Start...
+ start-&gt;<a href="qbutton.html#setText">setText</a>( "&amp;Start" );
+ // ...and disable it...
+ start-&gt;<a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
+ // ...and return
+ return;
+ }
+#endif
+
+ // If the process is not complete increase it
+<a name="x968"></a> progress-&gt;<a href="qprogressbar.html#setProgress">setProgress</a>( ++p );
+}
+</pre>
+
+<p> <hr>
+<p> Main:
+<p> <pre>/****************************************************************************
+** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:37 $
+**
+** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "progressbar.h"
+#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
+
+int main(int argc,char **argv)
+{
+ <a href="qapplication.html">QApplication</a> a(argc,argv);
+
+ ProgressBar progressbar;
+ progressbar.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - ProgressBar");
+ a.<a href="qapplication.html#setMainWidget">setMainWidget</a>(&amp;progressbar);
+ progressbar.<a href="qwidget.html#show">show</a>();
+
+ return a.<a href="qapplication.html#exec">exec</a>();
+}
+</pre>
+
+<p>See also <a href="examples.html">Examples</a>.
+
+<!-- eof -->
+<p><address><hr><div align=center>
+<table width=100% cellspacing=0 border=0><tr>
+<td>Copyright &copy; 2007
+<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
+<td align=right><div align=right>Qt 3.3.8</div>
+</table></div></address></body>
+</html>