summaryrefslogtreecommitdiffstats
path: root/src/dialogs/qprogressdialog.cpp
blob: d29b4c5817db7a105e3d96785cc2bc26ee91c757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
/****************************************************************************
**
** Implementation of TQProgressDialog class
**
** Created : 970521
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of the dialogs module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file.  Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#include "ntqprogressdialog.h"

#ifndef QT_NO_PROGRESSDIALOG

#include "ntqaccel.h"
#include "ntqpainter.h"
#include "ntqdrawutil.h"
#include "ntqdatetime.h"
#include "ntqapplication.h"
#include "ntqstyle.h"
#include "ntqpushbutton.h"
#include "ntqcursor.h"
#include "ntqtimer.h"
#include <limits.h>

// If the operation is expected to take this long (as predicted by
// progress time), show the progress dialog.
static const int defaultShowTime    = 4000;
// Wait at least this long before attempting to make a prediction.
static const int minWaitTime = 50;

// Various layout values
static const int margin_lr   = 10;
static const int margin_tb   = 10;
static const int spacing     = 4;


class TQProgressDialogData
{
public:
    TQProgressDialogData( TQProgressDialog* that, TQWidget* parent,
		   const TQString& labelText,
		   int totalSteps ) :
	creator( parent ),
	label( new TQLabel(labelText,that,"label") ),
	cancel( 0 ),
	bar( new TQProgressBar(totalSteps,that,"bar") ),
	shown_once( FALSE ),
	cancellation_flag( FALSE ),
	showTime( defaultShowTime )
    {
	label->setAlignment(that->style().styleHint(TQStyle::SH_ProgressDialog_TextLabelAlignment, that));
    }

    TQWidget	 *creator;
    TQLabel	 *label;
    TQPushButton	 *cancel;
    TQProgressBar *bar;
    bool	  shown_once;
    bool	  cancellation_flag;
    TQTime	  starttime;
#ifndef QT_NO_CURSOR
    TQCursor	  parentCursor;
#endif
    int		  showTime;
    bool autoClose;
    bool autoReset;
    bool forceHide;
};


/*!
  \class TQProgressDialog ntqprogressdialog.h
  \brief The TQProgressDialog class provides feedback on the progress of a slow operation.
  \ingroup dialogs
  \mainclass

  A progress dialog is used to give the user an indication of how long
  an operation is going to take, and to demonstrate that the
  application has not frozen. It can also give the user an opportunity
  to abort the operation.

  A common problem with progress dialogs is that it is difficult to know
  when to use them; operations take different amounts of time on different
  hardware.  TQProgressDialog offers a solution to this problem:
  it estimates the time the operation will take (based on time for
  steps), and only shows itself if that estimate is beyond minimumDuration()
  (4 seconds by default).

  Use setTotalSteps() (or the constructor) to set the number of
  "steps" in the operation and call setProgress() as the operation
  progresses. The step value can be chosen arbitrarily. It can be the
  number of files copied, the number of bytes received, the number of
  iterations through the main loop of your algorithm, or some other
  suitable unit.  Progress starts at 0, and the progress dialog shows
  that the operation has finished when you call setProgress() with
  totalSteps() as its argument.

  The dialog automatically resets and hides itself at the end of the
  operation. Use setAutoReset() and setAutoClose() to change this
  behavior.

  There are two ways of using TQProgressDialog: modal and modeless.

  Using a modal TQProgressDialog is simpler for the programmer, but you
  must call TQApplication::processEvents() or
  TQEventLoop::processEvents(ExcludeUserInput) to keep the event loop
  running to ensure that the application doesn't freeze. Do the
  operation in a loop, call \l setProgress() at intervals, and check
  for cancellation with wasCanceled(). For example:
\code
TQProgressDialog progress( "Copying files...", "Abort Copy", numFiles,
                          this, "progress", TRUE );
for ( int i = 0; i < numFiles; i++ ) {
    progress.setProgress( i );
    qApp->processEvents();

    if ( progress.wasCanceled() )
        break;
    //... copy one file
}
progress.setProgress( numFiles );
\endcode

  A modeless progress dialog is suitable for operations that take
  place in the background, where the user is able to interact with the
  application. Such operations are typically based on TQTimer (or
  TQObject::timerEvent()), TQSocketNotifier, or TQUrlOperator; or performed
  in a separate thread. A TQProgressBar in the status bar of your main window
  is often an alternative to a modeless progress dialog.

  You need to have an event loop to be running, connect the
  canceled() signal to a slot that stops the operation, and call \l
  setProgress() at intervals. For example:
\code
Operation::Operation( TQObject *parent = 0 )
    : TQObject( parent ), steps( 0 )
{
    pd = new TQProgressDialog( "Operation in progress.", "Cancel", 100 );
    connect( pd, SIGNAL(canceled()), this, SLOT(cancel()) );
    t = new TQTimer( this );
    connect( t, SIGNAL(timeout()), this, SLOT(perform()) );
    t->start( 0 );
}

void Operation::perform()
{
    pd->setProgress( steps );
    //... perform one percent of the operation
    steps++;
    if ( steps > pd->totalSteps() )
        t->stop();
}

void Operation::cancel()
{
    t->stop();
    //... cleanup
}
\endcode


  In both modes the progress dialog may be customized by
  replacing the child widgets with custom widgets by using setLabel(),
  setBar(), and setCancelButton().
  The functions setLabelText() and setCancelButtonText()
  set the texts shown.

  <img src=qprogdlg-m.png> <img src=qprogdlg-w.png>

  \sa TQDialog TQProgressBar
  \link guibooks.html#fowler GUI Design Handbook: Progress Indicator\endlink
*/


/*!
  Returns the TQLabel currently being displayed above the progress bar.
  This TQLabel is owned by the TQProgressDialog.

  \sa setLabel()
*/
TQLabel *TQProgressDialog::label() const
{
    return d->label;
}

/*!
  Returns the TQProgressBar currently being used to display progress.
  This TQProgressBar is owned by the TQProgressDialog.

  \sa setBar()
*/
TQProgressBar *TQProgressDialog::bar() const
{
    return d->bar;
}


/*!
  Constructs a progress dialog.

  Default settings:
  \list
  \i The label text is empty.
  \i The cancel button text is (translated) "Cancel".
  \i The total number of steps is 100.
  \endlist

  The \a creator argument is the widget to use as the dialog's parent.
  The \a name, \a modal, and the widget flags, \a f, are
  passed to the TQDialog::TQDialog() constructor. If \a modal is FALSE (the
  default), you must have an event loop proceeding for any redrawing
  of the dialog to occur. If \a modal is TRUE, the dialog ensures that
  events are processed when needed.

  \sa setLabelText(), setLabel(), setCancelButtonText(), setCancelButton(),
  setTotalSteps()
*/

TQProgressDialog::TQProgressDialog( TQWidget *creator, const char *name,
				  bool modal, WFlags f )
    : TQDialog( creator, name, modal, f)
{
    init( creator, TQString::fromLatin1(""), tr("Cancel"), 100 );
}

/*!
  Constructs a progress dialog.

   The \a labelText is text used to remind the user what is progressing.

   The \a cancelButtonText is the text to display on the cancel button,
	    or 0 if no cancel button is to be shown.

   The \a totalSteps is the total number of steps in the operation for
   which this progress dialog shows progress.  For example, if the
   operation is to examine 50 files, this value would be 50. Before
   examining the first file, call setProgress(0). As each file is
   processed call setProgress(1), setProgress(2), etc., finally
   calling setProgress(50) after examining the last file.

   The \a creator argument is the widget to use as the dialog's parent.
   The \a name, \a modal, and widget flags, \a f, are passed to the
   TQDialog::TQDialog() constructor. If \a modal is FALSE (the default),
   you will must have an event loop proceeding for any redrawing of
   the dialog to occur. If \a modal is TRUE, the dialog ensures that
   events are processed when needed.


  \sa setLabelText(), setLabel(), setCancelButtonText(), setCancelButton(),
  setTotalSteps()
*/

TQProgressDialog::TQProgressDialog( const TQString &labelText,
				  const TQString &cancelButtonText,
				  int totalSteps,
				  TQWidget *creator, const char *name,
				  bool modal, WFlags f )
    : TQDialog( creator, name, modal, f)
{
    init( creator, labelText, cancelButtonText, totalSteps );
}


/*!
  Destroys the progress dialog.
*/

TQProgressDialog::~TQProgressDialog()
{
#ifndef QT_NO_CURSOR
    if ( d->creator )
	d->creator->setCursor( d->parentCursor );
#endif
    delete d;
}

void TQProgressDialog::init( TQWidget *creator,
			    const TQString& lbl, const TQString& canc,
			    int totstps)
{
    d = new TQProgressDialogData(this, creator, lbl, totstps);
    d->autoClose = TRUE;
    d->autoReset = TRUE;
    d->forceHide = FALSE;
    setCancelButtonText( canc );
    connect( this, SIGNAL(canceled()), this, SIGNAL(cancelled()) );
    connect( this, SIGNAL(canceled()), this, SLOT(cancel()) );
    forceTimer = new TQTimer( this );
    connect( forceTimer, SIGNAL(timeout()), this, SLOT(forceShow()) );
    layout();
}

/*!
  \fn void TQProgressDialog::canceled()

  This signal is emitted when the cancel button is clicked.
  It is connected to the cancel() slot by default.

  \sa wasCanceled()
*/

/*!
  \fn void TQProgressDialog::cancelled()

  \obsolete

  Use canceled() instead.
*/


/*!
  Sets the label to \a label. The progress dialog resizes to fit. The
  label becomes owned by the progress dialog and will be deleted when
  necessary, so do not pass the address of an object on the stack.

  \sa setLabelText()
*/

void TQProgressDialog::setLabel( TQLabel *label )
{
    delete d->label;
    d->label = label;
    if (label) {
	if ( label->parentWidget() == this ) {
	    label->hide(); // until we resize
	} else {
	    label->reparent( this, 0, TQPoint(0,0), FALSE );
	}
    }
    int w = TQMAX( isVisible() ? width() : 0, sizeHint().width() );
    int h = TQMAX( isVisible() ? height() : 0, sizeHint().height() );
    resize( w, h );
    if (label)
	label->show();
}


/*!
  \property TQProgressDialog::labelText
  \brief the label's text

  The default text is TQString::null.
*/

TQString TQProgressDialog::labelText() const
{
    if ( label() )
	return label()->text();
    return TQString::null;
}

void TQProgressDialog::setLabelText( const TQString &text )
{
    if ( label() ) {
	label()->setText( text );
	int w = TQMAX( isVisible() ? width() : 0, sizeHint().width() );
	int h = TQMAX( isVisible() ? height() : 0, sizeHint().height() );
	resize( w, h );
    }
}


/*!
  Sets the cancel button to the push button, \a cancelButton. The
  progress dialog takes ownership of this button which will be deleted
  when necessary, so do not pass the address of an object that is on
  the stack, i.e. use new() to create the button.

  \sa setCancelButtonText()
*/

void TQProgressDialog::setCancelButton( TQPushButton *cancelButton )
{
    delete d->cancel;
    d->cancel = cancelButton;
    if (cancelButton) {
	if ( cancelButton->parentWidget() == this ) {
	    cancelButton->hide(); // until we resize
	} else {
	    cancelButton->reparent( this, 0, TQPoint(0,0), FALSE );
	}
	connect( d->cancel, SIGNAL(clicked()), this, SIGNAL(canceled()) );
#ifndef QT_NO_ACCEL
	TQAccel *accel = new TQAccel( this );
	accel->connectItem( accel->insertItem(Key_Escape),
			    d->cancel, SIGNAL(clicked()) );
#endif
    }
    int w = TQMAX( isVisible() ? width() : 0, sizeHint().width() );
    int h = TQMAX( isVisible() ? height() : 0, sizeHint().height() );
    resize( w, h );
    if (cancelButton)
	cancelButton->show();
}

/*!
  Sets the cancel button's text to \a cancelButtonText.
  \sa setCancelButton()
*/

void TQProgressDialog::setCancelButtonText( const TQString &cancelButtonText )
{
    if ( !cancelButtonText.isNull() ) {
	if ( d->cancel )
	    d->cancel->setText(cancelButtonText);
	else
	    setCancelButton(new TQPushButton(cancelButtonText, this, "cancel"));
    } else {
	setCancelButton(0);
    }
    int w = TQMAX( isVisible() ? width() : 0, sizeHint().width() );
    int h = TQMAX( isVisible() ? height() : 0, sizeHint().height() );
    resize( w, h );
}


/*!
  Sets the progress bar widget to \a bar. The progress dialog resizes to
  fit. The progress dialog takes ownership of the progress \a bar which
  will be deleted when necessary, so do not use a progress bar
  allocated on the stack.
*/

void TQProgressDialog::setBar( TQProgressBar *bar )
{
    if ( progress() > 0 ) {
#if defined(QT_CHECK_STATE)
	qWarning( "TQProgrssDialog::setBar: Cannot set a new progress bar "
		 "while the old one is active" );
#endif
    }
    delete d->bar;
    d->bar = bar;
    int w = TQMAX( isVisible() ? width() : 0, sizeHint().width() );
    int h = TQMAX( isVisible() ? height() : 0, sizeHint().height() );
    resize( w, h );
}


/*!
  \property TQProgressDialog::wasCancelled
  \brief whether the dialog was canceled

  \obsolete

  Use \l wasCanceled instead.
*/

/*!
  \property TQProgressDialog::wasCanceled
  \brief whether the dialog was canceled

  \sa setProgress()
*/

bool TQProgressDialog::wasCancelled() const
{
    return d->cancellation_flag;
}


/*!
  \property TQProgressDialog::totalSteps
  \brief the total number of steps

  The default is 0.
*/

int TQProgressDialog::totalSteps() const
{
    if ( d && d->bar )
	return bar()->totalSteps();
    return 0;
}

void TQProgressDialog::setTotalSteps( int totalSteps )
{
    bar()->setTotalSteps( totalSteps );
}


/*!
  Resets the progress dialog.
  The progress dialog becomes hidden if autoClose() is TRUE.

  \sa setAutoClose(), setAutoReset()
*/

void TQProgressDialog::reset()
{
#ifndef QT_NO_CURSOR
    if ( progress() >= 0 ) {
	if ( d->creator )
	    d->creator->setCursor( d->parentCursor );
    }
#endif
    if ( d->autoClose || d->forceHide )
	hide();
    bar()->reset();
    d->cancellation_flag = FALSE;
    d->shown_once = FALSE;
    forceTimer->stop();
}

/*!
  Resets the progress dialog. wasCanceled() becomes TRUE until
  the progress dialog is reset.
  The progress dialog becomes hidden.
*/

void TQProgressDialog::cancel()
{
    d->forceHide = TRUE;
    reset();
    d->forceHide = FALSE;
    d->cancellation_flag = TRUE;
}

/*!
  \property TQProgressDialog::progress
  \brief the current amount of progress made.

  For the progress dialog to work as expected, you should initially set
  this property to 0 and finally set it to
  TQProgressDialog::totalSteps(); you can call setProgress() any number of times
  in-between.

  \warning If the progress dialog is modal
    (see TQProgressDialog::TQProgressDialog()),
    this function calls TQApplication::processEvents(), so take care that
    this does not cause undesirable re-entrancy in your code. For example,
    don't use a TQProgressDialog inside a paintEvent()!

  \sa totalSteps
*/

int TQProgressDialog::progress() const
{
    return bar()->progress();
}

void TQProgressDialog::setProgress( int progress )
{
    if ( progress == bar()->progress() ||
	 bar()->progress() == -1 && progress == bar()->totalSteps() )
	return;

    bar()->setProgress(progress);

    if ( d->shown_once ) {
	if (testWFlags(WShowModal))
	    qApp->processEvents();
    } else {
	if ( progress == 0 ) {
#ifndef QT_NO_CURSOR
	    if ( d->creator ) {
		d->parentCursor = d->creator->cursor();
		d->creator->setCursor( waitCursor );
	    }
#endif
	    d->starttime.start();
	    forceTimer->start( d->showTime );
	    return;
	} else {
	    bool need_show;
	    int elapsed = d->starttime.elapsed();
	    if ( elapsed >= d->showTime ) {
		need_show = TRUE;
	    } else {
		if ( elapsed > minWaitTime ) {
		    int estimate;
		    if ( (totalSteps() - progress) >= INT_MAX / elapsed )
			estimate = (totalSteps() - progress) / progress * elapsed;
		    else
			estimate = elapsed * (totalSteps() - progress) / progress;
		    need_show = estimate >= d->showTime;
		} else {
		    need_show = FALSE;
		}
	    }
	    if ( need_show ) {
		int w = TQMAX( isVisible() ? width() : 0, sizeHint().width() );
		int h = TQMAX( isVisible() ? height() : 0, sizeHint().height() );
		resize( w, h );
		show();
		d->shown_once = TRUE;
	    }
	}
#ifdef Q_WS_MACX
	TQApplication::flush();
#endif
    }

    if ( progress == bar()->totalSteps() && d->autoReset )
	reset();
}

/*!
  \overload

  Sets the current amount of progress to \a progress and the total number of
  steps to \a totalSteps.

  \sa setTotalSteps()
*/

void TQProgressDialog::setProgress( int progress, int totalSteps )
{
    setTotalSteps( totalSteps );
    setProgress( progress );
}

/*!
  Returns a size that fits the contents of the progress dialog.
  The progress dialog resizes itself as required, so you should not
  need to call this yourself.
*/

TQSize TQProgressDialog::sizeHint() const
{
    TQSize sh = label()->sizeHint();
    TQSize bh = bar()->sizeHint();
    int h = margin_tb*2 + bh.height() + sh.height() + spacing;
    if ( d->cancel )
	h += d->cancel->sizeHint().height() + spacing;
    return TQSize( TQMAX(200, sh.width() + 2*margin_lr), h );
}

/*!\reimp
*/
void TQProgressDialog::resizeEvent( TQResizeEvent * )
{
    layout();
}

/*!
  \reimp
*/
void TQProgressDialog::styleChange(TQStyle& s)
{
    TQDialog::styleChange(s);
    layout();
}

void TQProgressDialog::layout()
{
    int sp = spacing;
    int mtb = margin_tb;
    int mlr = TQMIN(width()/10, margin_lr);
    const bool centered =
	bool(style().styleHint(TQStyle::SH_ProgressDialog_CenterCancelButton, this));

    TQSize cs = d->cancel ? d->cancel->sizeHint() : TQSize(0,0);
    TQSize bh = bar()->sizeHint();
    int cspc;
    int lh = 0;

    // Find spacing and sizes that fit.  It is important that a progress
    // dialog can be made very small if the user demands it so.
    for (int attempt=5; attempt--; ) {
	cspc = d->cancel ? cs.height() + sp : 0;
	lh = TQMAX(0, height() - mtb - bh.height() - sp - cspc);

	if ( lh < height()/4 ) {
	    // Getting cramped
	    sp /= 2;
	    mtb /= 2;
	    if ( d->cancel ) {
		cs.setHeight(TQMAX(4,cs.height()-sp-2));
	    }
	    bh.setHeight(TQMAX(4,bh.height()-sp-1));
	} else {
	    break;
	}
    }

    if ( d->cancel ) {
	d->cancel->setGeometry(
	    centered ? width()/2 - cs.width()/2 : width() - mlr - cs.width(),
	    height() - mtb - cs.height() + sp,
	    cs.width(), cs.height() );
    }

    label()->setGeometry( mlr, 0, width()-mlr*2, lh );
    bar()->setGeometry( mlr, lh+sp, width()-mlr*2, bh.height() );
}

/*!
    \property TQProgressDialog::minimumDuration
    \brief the time that must pass before the dialog appears

    If the expected duration of the task is less than the
    minimumDuration, the dialog will not appear at all. This prevents
    the dialog popping up for tasks that are tquickly over. For tasks
    that are expected to exceed the minimumDuration, the dialog will
    pop up after the minimumDuration time or as soon as any progress
    is set.

    If set to 0, the dialog is always shown as soon as any progress is
    set. The default is 4000 milliseconds.
*/
void TQProgressDialog::setMinimumDuration( int ms )
{
    d->showTime = ms;
    if ( bar()->progress() == 0 ) {
	forceTimer->stop();
	forceTimer->start( ms );
    }
}

int TQProgressDialog::minimumDuration() const
{
    return d->showTime;
}


/*!
  \reimp
*/

void TQProgressDialog::closeEvent( TQCloseEvent *e )
{
    emit canceled();
    TQDialog::closeEvent( e );
}

/*!
  \property TQProgressDialog::autoReset
  \brief whether the progress dialog calls reset() as soon as progress() equals totalSteps()

  The default is TRUE.

  \sa setAutoClose()
*/

void TQProgressDialog::setAutoReset( bool b )
{
    d->autoReset = b;
}

bool TQProgressDialog::autoReset() const
{
    return d->autoReset;
}

/*!
  \property TQProgressDialog::autoClose
  \brief whether the dialog gets hidden by reset()

  The default is TRUE.

  \sa setAutoReset()
*/

void TQProgressDialog::setAutoClose( bool b )
{
    d->autoClose = b;
}

bool TQProgressDialog::autoClose() const
{
    return d->autoClose;
}

/*!
  \reimp
*/

void TQProgressDialog::showEvent( TQShowEvent *e )
{
    TQDialog::showEvent( e );
    int w = TQMAX( isVisible() ? width() : 0, sizeHint().width() );
    int h = TQMAX( isVisible() ? height() : 0, sizeHint().height() );
    resize( w, h );
    forceTimer->stop();
}

/*!
  Shows the dialog if it is still hidden after the algorithm has been started
  and minimumDuration milliseconds have passed.

  \sa setMinimumDuration()
*/

void TQProgressDialog::forceShow()
{
    if ( d->shown_once || d->cancellation_flag )
	return;

    show();
    d->shown_once = TRUE;
}


#endif