summaryrefslogtreecommitdiffstats
path: root/qtjava/javalib/examples/progressbar
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /qtjava/javalib/examples/progressbar
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtjava/javalib/examples/progressbar')
-rw-r--r--qtjava/javalib/examples/progressbar/Main.java31
-rw-r--r--qtjava/javalib/examples/progressbar/ProgressBar.java174
2 files changed, 205 insertions, 0 deletions
diff --git a/qtjava/javalib/examples/progressbar/Main.java b/qtjava/javalib/examples/progressbar/Main.java
new file mode 100644
index 00000000..be103c03
--- /dev/null
+++ b/qtjava/javalib/examples/progressbar/Main.java
@@ -0,0 +1,31 @@
+/***************************************************************************
+* $Id$
+**
+* Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
+**
+* This file is part of an example program for Qt. This example
+* program may be used, distributed and modified without limitation.
+**
+****************************************************************************/
+
+import org.kde.qt.*;
+
+class Main {
+
+public static void main(String[] args)
+{
+ QApplication a = new QApplication( args );
+
+ ProgressBar progressbar = new ProgressBar();
+ progressbar.setCaption("Qt Example - ProgressBar");
+ a.setMainWidget(progressbar);
+ progressbar.show();
+
+ a.exec();
+ return;
+}
+
+ static {
+ qtjava.initialize();
+ }
+}
diff --git a/qtjava/javalib/examples/progressbar/ProgressBar.java b/qtjava/javalib/examples/progressbar/ProgressBar.java
new file mode 100644
index 00000000..1d8ab1d3
--- /dev/null
+++ b/qtjava/javalib/examples/progressbar/ProgressBar.java
@@ -0,0 +1,174 @@
+/***************************************************************************
+* $Id$
+**
+* Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
+**
+* This file is part of an example program for Qt. This example
+* program may be used, distributed and modified without limitation.
+**
+****************************************************************************/
+
+import org.kde.qt.*;
+
+
+class ProgressBar extends QButtonGroup
+{
+
+protected QRadioButton slow, normal, fast;
+protected QPushButton start, pause, reset;
+protected QProgressBar progress;
+protected QTimer timer;
+
+
+/*
+ Constructor
+ *
+ Creates child widgets of the ProgressBar widget
+ */
+
+ProgressBar( )
+{
+ this(null, null);
+}
+
+ProgressBar( QWidget parent, String name )
+{
+ super( 0, Horizontal, "Progress Bar", parent, name );
+ timer = new QTimer();
+ setMargin( 10 );
+
+ QGridLayout toplayout = new QGridLayout( 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 QRadioButton( "&Slow", this );
+ normal = new QRadioButton( "&Normal", this );
+ fast = new QRadioButton( "&Fast", this );
+ QVBoxLayout vb1 = new QVBoxLayout();
+ 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 QPushButton( "&Start", this );
+ reset = new QPushButton( "&Reset", this );
+ QVBoxLayout vb2 = new QVBoxLayout();
+ toplayout.addLayout( vb2, 0, 1 );
+ vb2.addWidget( start );
+ vb2.addWidget( reset );
+
+ // Create the progressbar
+ progress = new QProgressBar( 100, this );
+ // progress.setStyle( new QMotifStyle() );
+ 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 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 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 slotTimeout()
+{
+ int p = progress.progress();
+
+ // 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;
+ }
+
+ // If the process is not complete increase it
+ progress.setProgress( ++p );
+}
+}