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/progress/README | 6 + examples/progress/progress.cpp | 337 +++++++++++++++++++++++++++++++++++++++++ examples/progress/progress.doc | 17 +++ examples/progress/progress.pro | 10 ++ 4 files changed, 370 insertions(+) create mode 100644 examples/progress/README create mode 100644 examples/progress/progress.cpp create mode 100644 examples/progress/progress.doc create mode 100644 examples/progress/progress.pro (limited to 'examples/progress') diff --git a/examples/progress/README b/examples/progress/README new file mode 100644 index 000000000..97ba32365 --- /dev/null +++ b/examples/progress/README @@ -0,0 +1,6 @@ +This example demonstrates the use of QProgressBar when performing +operations which may take a long time to complete. + +The progress dialog only appears if the estimated completion time +is 3-4 seconds. + diff --git a/examples/progress/progress.cpp b/examples/progress/progress.cpp new file mode 100644 index 000000000..fa8ff1d60 --- /dev/null +++ b/examples/progress/progress.cpp @@ -0,0 +1,337 @@ +/**************************************************************************** +** +** 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 +#include +#include + +class AnimatedThingy : public TQLabel { +public: + AnimatedThingy( TQWidget* parent, const TQString& s ) : + TQLabel(parent), + label(s), + step(0) + { + setBackgroundColor(white); + label+="\n... and wasting CPU\nwith this animation!\n"; + + for (int i=0; irect()); + for (int i=0; i=b) { x=b-1; dx=-(rand()%8+2); } + } + + enum {nqix=10}; + int ox[2][nqix]; + int oy[2][nqix]; + int x0,y0,x1,y1; + int dx0,dy0,dx1,dy1; + TQString label; + int step; +}; + + +class CPUWaster : public TQWidget +{ + Q_OBJECT + + enum { first_draw_item = 1000, last_draw_item = 1006 }; + + int drawItemRects(int id) + { + int n = id - first_draw_item; + int r = 100; + while (n--) r*=(n%3 ? 5 : 4); + return r; + } + TQString drawItemText(int id) + { + TQString str; + str.sprintf("%d Rectangles", drawItemRects(id)); + return str; + } + +public: + CPUWaster() : + pb(0) + { + menubar = new TQMenuBar( this, "menu" ); + Q_CHECK_PTR( menubar ); + + TQPopupMenu* file = new TQPopupMenu(); + Q_CHECK_PTR( file ); + menubar->insertItem( "&File", file ); + for (int i=first_draw_item; i<=last_draw_item; i++) + file->insertItem( drawItemText(i), i ); + connect( menubar, SIGNAL(activated(int)), this, SLOT(doMenuItem(int)) ); + file->insertSeparator(); + file->insertItem( "Quit", qApp, SLOT(tquit()) ); + + options = new TQPopupMenu(); + Q_CHECK_PTR( options ); + menubar->insertItem( "&Options", options ); + td_id = options->insertItem( "Timer driven", this, SLOT(timerDriven()) ); + ld_id = options->insertItem( "Loop driven", this, SLOT(loopDriven()) ); + options->insertSeparator(); + dl_id = options->insertItem( "Default label", this, SLOT(defaultLabel()) ); + cl_id = options->insertItem( "Custom label", this, SLOT(customLabel()) ); + options->insertSeparator(); + md_id = options->insertItem( "No minimum duration", this, SLOT(toggleMinimumDuration()) ); + options->setCheckable( TRUE ); + loopDriven(); + defaultLabel(); + + setFixedSize( 400, 300 ); + + setBackgroundColor( black ); + } + +public slots: + void doMenuItem(int id) + { + if (id >= first_draw_item && id <= last_draw_item) + draw(drawItemRects(id)); + } + + void stopDrawing() { got_stop = TRUE; } + + void timerDriven() + { + timer_driven = TRUE; + options->setItemChecked( td_id, TRUE ); + options->setItemChecked( ld_id, FALSE ); + } + + void loopDriven() + { + timer_driven = FALSE; + options->setItemChecked( ld_id, TRUE ); + options->setItemChecked( td_id, FALSE ); + } + + void defaultLabel() + { + default_label = TRUE; + options->setItemChecked( dl_id, TRUE ); + options->setItemChecked( cl_id, FALSE ); + } + + void customLabel() + { + default_label = FALSE; + options->setItemChecked( dl_id, FALSE ); + options->setItemChecked( cl_id, TRUE ); + } + + void toggleMinimumDuration() + { + options->setItemChecked( md_id, + !options->isItemChecked( md_id ) ); + } + +private: + void timerEvent( TQTimerEvent* ) + { + if (!got_stop) + pb->setProgress( pb->totalSteps() - rects ); + rects--; + + { + TQPainter p(this); + + int ww = width(); + int wh = height(); + + if ( ww > 8 && wh > 8 ) { + TQColor c(rand()%255, rand()%255, rand()%255); + int x = rand() % (ww-8); + int y = rand() % (wh-8); + int w = rand() % (ww-x); + int h = rand() % (wh-y); + p.fillRect( x, y, w, h, c ); + } + } + + if (!rects || got_stop) { + if (!got_stop) + pb->setProgress( pb->totalSteps() ); + TQPainter p(this); + p.fillRect(0, 0, width(), height(), backgroundColor()); + enableDrawingItems(TRUE); + killTimers(); + delete pb; + pb = 0; + } + } + + TQProgressDialog* newProgressDialog( const char* label, int steps, bool modal ) + { + TQProgressDialog *d = new TQProgressDialog(label, "Cancel", steps, this, + "progress", modal); + if ( options->isItemChecked( md_id ) ) + d->setMinimumDuration(0); + if ( !default_label ) + d->setLabel( new AnimatedThingy(d,label) ); + return d; + } + + void enableDrawingItems(bool yes) + { + for (int i=first_draw_item; i<=last_draw_item; i++) { + menubar->setItemEnabled(i, yes); + } + } + + void draw(int n) + { + if ( timer_driven ) { + if ( pb ) { + qWarning("This cannot happen!"); + return; + } + rects = n; + pb = newProgressDialog("Drawing rectangles.\n" + "Using timer event.", n, FALSE); + pb->setCaption("Please Wait"); + connect(pb, SIGNAL(cancelled()), this, SLOT(stopDrawing())); + enableDrawingItems(FALSE); + startTimer(0); + got_stop = FALSE; + } else { + TQProgressDialog* lpb = newProgressDialog( + "Drawing rectangles.\nUsing loop.", n, TRUE); + lpb->setCaption("Please Wait"); + + TQPainter p(this); + for (int i=0; isetProgress(i); + if ( lpb->wasCancelled() ) + break; + + TQColor c(rand()%255, rand()%255, rand()%255); + int x = rand()%(width()-8); + int y = rand()%(height()-8); + int w = rand()%(width()-x); + int h = rand()%(height()-y); + p.fillRect(x,y,w,h,c); + } + + p.fillRect(0, 0, width(), height(), backgroundColor()); + + delete lpb; + } + } + + TQMenuBar* menubar; + TQProgressDialog* pb; + TQPopupMenu* options; + int td_id, ld_id; + int dl_id, cl_id; + int md_id; + int rects; + bool timer_driven; + bool default_label; + bool got_stop; +}; + +int main( int argc, char **argv ) +{ + TQApplication a( argc, argv ); + + int wincount = argc > 1 ? atoi(argv[1]) : 1; + + for ( int i=0; ishow(); + } + return a.exec(); +} + +#include "progress.moc" diff --git a/examples/progress/progress.doc b/examples/progress/progress.doc new file mode 100644 index 000000000..478013a16 --- /dev/null +++ b/examples/progress/progress.doc @@ -0,0 +1,17 @@ +/* +*/ +/*! \page progress-example.html + + \ingroup examples + \title Progress Bar and Dialog Example + + This example displays either a simple (text-only) or a + custom-labelled (user-supplied widget) progress dialog. It also + demonstrates simple use of menus. +
+ + Implementation: + + \include progress/progress.cpp +*/ + diff --git a/examples/progress/progress.pro b/examples/progress/progress.pro new file mode 100644 index 000000000..d9217e2b8 --- /dev/null +++ b/examples/progress/progress.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = progress + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = full-config + +HEADERS = +SOURCES = progress.cpp -- cgit v1.2.1