• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kprogress.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 1996 Martynas Kunigelis
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
22#include <stdlib.h>
23#include <limits.h>
24
25#include <tqpainter.h>
26#include <tqpixmap.h>
27#include <tqlabel.h>
28#include <tqlayout.h>
29#include <tqpushbutton.h>
30#include <tqstring.h>
31#include <tqregexp.h>
32#include <tqstyle.h>
33#include <tqtimer.h>
34
35#include "kprogress.h"
36
37#include <tdeapplication.h>
38#include <tdelocale.h>
39#include <twin.h>
40
41KProgress::KProgress(TQWidget *parent, const char *name, WFlags f)
42 : TQProgressBar(parent, name, f),
43 mFormat("%p%")
44{
45 setProgress(0);
46}
47
48KProgress::KProgress(int totalSteps, TQWidget *parent, const char *name, WFlags f)
49 : TQProgressBar(totalSteps, parent, name, f),
50 mFormat("%p%")
51{
52 setProgress(0);
53}
54
55KProgress::~KProgress()
56{
57}
58
59void KProgress::advance(int offset)
60{
61 setProgress(progress() + offset);
62}
63
64void KProgress::setTotalSteps(int totalSteps)
65{
66 TQProgressBar::setTotalSteps(totalSteps);
67
68 if (totalSteps)
69 {
70 emit percentageChanged((progress() * 100) / totalSteps);
71 }
72}
73
74void KProgress::setProgress(int progress)
75{
76 TQProgressBar::setProgress(progress);
77
78 if (totalSteps())
79 {
80 emit percentageChanged((progress * 100) / totalSteps());
81 }
82}
83
84// ### KDE 4 remove
85void KProgress::setValue(int progress)
86{
87 setProgress(progress);
88}
89
90// ### KDE 4 remove
91void KProgress::setRange(int /*min*/, int max)
92{
93 setTotalSteps(max);
94}
95
96// ### KDE 4 remove
97int KProgress::maxValue()
98{
99 return totalSteps();
100}
101
102void KProgress::setTextEnabled(bool enable)
103{
104 setPercentageVisible(enable);
105}
106
107bool KProgress::textEnabled() const
108{
109 return percentageVisible();
110}
111
112void KProgress::setFormat(const TQString & format)
113{
114 mFormat = format;
115 if (mFormat != "%p%")
116 setCenterIndicator(true);
117}
118
119TQString KProgress::format() const
120{
121 return mFormat;
122}
123
124// ### KDE 4 remove
125int KProgress::value() const
126{
127 return progress();
128}
129
130bool KProgress::setIndicator(TQString &indicator, int progress, int totalSteps)
131{
132 if (!totalSteps)
133 return false;
134 TQString newString(mFormat);
135 newString.replace(TQString::fromLatin1("%v"),
136 TQString::number(progress));
137 newString.replace(TQString::fromLatin1("%m"),
138 TQString::number(totalSteps));
139
140 if (totalSteps > INT_MAX / 1000) {
141 progress /= 1000;
142 totalSteps /= 1000;
143 }
144
145 newString.replace(TQString::fromLatin1("%p"),
146 TQString::number((progress * 100) / totalSteps));
147
148 if (newString != indicator)
149 {
150 indicator = newString;
151 return true;
152 }
153
154 return false;
155}
156
157struct KProgressDialog::KProgressDialogPrivate
158{
159 KProgressDialogPrivate() : cancelButtonShown(true)
160 {
161 }
162
163 bool cancelButtonShown;
164};
165
166/*
167 * KProgressDialog implementation
168 */
169KProgressDialog::KProgressDialog(TQWidget* parent, const char* name,
170 const TQString& caption, const TQString& text,
171 bool modal)
172 : KDialogBase(KDialogBase::Plain, caption, KDialogBase::Cancel,
173 KDialogBase::Cancel, parent, name, modal),
174 mAutoClose(true),
175 mAutoReset(false),
176 mCancelled(false),
177 mAllowCancel(true),
178 mShown(false),
179 mMinDuration(2000),
180 d(new KProgressDialogPrivate)
181{
182#ifdef TQ_WS_X11
183 KWin::setIcons(winId(), tdeApp->icon(), tdeApp->miniIcon());
184#endif
185 mShowTimer = new TQTimer(this);
186
187 showButton(KDialogBase::Close, false);
188 mCancelText = actionButton(KDialogBase::Cancel)->text();
189
190 TQFrame* mainWidget = plainPage();
191 TQVBoxLayout* layout = new TQVBoxLayout(mainWidget, 10);
192
193 mLabel = new TQLabel(text, mainWidget);
194 layout->addWidget(mLabel);
195
196 mProgressBar = new KProgress(mainWidget);
197 layout->addWidget(mProgressBar);
198
199 connect(mProgressBar, TQ_SIGNAL(percentageChanged(int)),
200 this, TQ_SLOT(slotAutoActions(int)));
201 connect(mShowTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(slotAutoShow()));
202 mShowTimer->start(mMinDuration, true);
203}
204
205KProgressDialog::~KProgressDialog()
206{
207 delete d;
208}
209
210void KProgressDialog::slotAutoShow()
211{
212 if (mShown || mCancelled)
213 {
214 return;
215 }
216
217 show();
218 tdeApp->processEvents();
219}
220
221void KProgressDialog::slotCancel()
222{
223 mCancelled = true;
224
225 if (mAllowCancel)
226 {
227 KDialogBase::slotCancel();
228 }
229}
230
231bool KProgressDialog::wasCancelled()
232{
233 return mCancelled;
234}
235
236void KProgressDialog::ignoreCancel()
237{
238 mCancelled = false;
239}
240
241bool KProgressDialog::wasCancelled() const
242{
243 return mCancelled;
244}
245
246void KProgressDialog::setMinimumDuration(int ms)
247{
248 mMinDuration = ms;
249 if (!mShown)
250 {
251 mShowTimer->stop();
252 mShowTimer->start(mMinDuration, true);
253 }
254}
255
256int KProgressDialog::minimumDuration()
257{
258 return mMinDuration;
259}
260
261int KProgressDialog::minimumDuration() const
262{
263 return mMinDuration;
264}
265
266void KProgressDialog::setAllowCancel(bool allowCancel)
267{
268 mAllowCancel = allowCancel;
269 showCancelButton(allowCancel);
270}
271
272// ### KDE 4 remove
273bool KProgressDialog::allowCancel()
274{
275 return mAllowCancel;
276}
277
278bool KProgressDialog::allowCancel() const
279{
280 return mAllowCancel;
281}
282
283KProgress* KProgressDialog::progressBar()
284{
285 return mProgressBar;
286}
287
288const KProgress* KProgressDialog::progressBar() const
289{
290 return mProgressBar;
291}
292
293void KProgressDialog::setLabel(const TQString& text)
294{
295 mLabel->setText(text);
296}
297
298// ### KDE 4 remove
299TQString KProgressDialog::labelText()
300{
301 return mLabel->text();
302}
303
304TQString KProgressDialog::labelText() const
305{
306 return mLabel->text();
307}
308
309void KProgressDialog::showCancelButton(bool show)
310{
311 showButtonCancel(show);
312}
313
314// ### KDE 4 remove
315bool KProgressDialog::autoClose()
316{
317 return mAutoClose;
318}
319
320bool KProgressDialog::autoClose() const
321{
322 return mAutoClose;
323}
324
325void KProgressDialog::setAutoClose(bool autoClose)
326{
327 mAutoClose = autoClose;
328}
329
330// ### KDE 4 remove
331bool KProgressDialog::autoReset()
332{
333 return mAutoReset;
334}
335
336bool KProgressDialog::autoReset() const
337{
338 return mAutoReset;
339}
340
341void KProgressDialog::setAutoReset(bool autoReset)
342{
343 mAutoReset = autoReset;
344}
345
346void KProgressDialog::setButtonText(const TQString& text)
347{
348 mCancelText = text;
349 setButtonCancel(text);
350}
351
352// ### KDE 4 remove
353TQString KProgressDialog::buttonText()
354{
355 return mCancelText;
356}
357
358TQString KProgressDialog::buttonText() const
359{
360 return mCancelText;
361}
362
363void KProgressDialog::slotAutoActions(int percentage)
364{
365 if (percentage < 100)
366 {
367 if (!d->cancelButtonShown)
368 {
369 setButtonCancel(mCancelText);
370 d->cancelButtonShown = true;
371 }
372 return;
373 }
374
375 mShowTimer->stop();
376
377 if (mAutoReset)
378 {
379 mProgressBar->setProgress(0);
380 }
381 else
382 {
383 setAllowCancel(true);
384 setButtonCancel(KStdGuiItem::close());
385 d->cancelButtonShown = false;
386 }
387
388 if (mAutoClose)
389 {
390 if (mShown)
391 {
392 hide();
393 }
394 else
395 {
396 emit finished();
397 }
398 }
399}
400
401void KProgressDialog::show()
402{
403 KDialogBase::show();
404 mShown = true;
405}
406
407
408void KProgress::virtual_hook( int, void* )
409{ /*BASE::virtual_hook( id, data );*/ }
410
411void KProgressDialog::virtual_hook( int id, void* data )
412{ KDialogBase::virtual_hook( id, data ); }
413
414#include "kprogress.moc"
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:192
KDialogBase::slotCancel
virtual void slotCancel()
Activated when the Cancel button has been clicked.
Definition: kdialogbase.cpp:1215
KDialogBase::mainWidget
TQWidget * mainWidget()
Returns the main widget if any.
Definition: kdialogbase.cpp:1464
KDialogBase::setButtonCancel
void setButtonCancel(const KGuiItem &item=KStdGuiItem::cancel())
Sets the appearance of the Cancel button.
Definition: kdialogbase.cpp:970
KDialogBase::showButton
void showButton(ButtonCode id, bool state)
Hide or display a general action button.
Definition: kdialogbase.cpp:866
KDialogBase::plainPage
TQFrame * plainPage()
Retrieve the empty page when the predefined layout is used in Plain mode.
Definition: kdialogbase.cpp:420
KDialogBase::actionButton
TQPushButton * actionButton(ButtonCode id)
Returns the action button that corresponds to the id.
Definition: kdialogbase.cpp:832
KDialogBase::showButtonCancel
void showButtonCancel(bool state)
Hide or display the Cancel button.
Definition: kdialogbase.cpp:888
KDialogBase::Close
@ Close
Show Close-button.
Definition: kdialogbase.h:205
KDialogBase::Cancel
@ Cancel
Show Cancel-button.
Definition: kdialogbase.h:204
KDialogBase::finished
void finished()
The dialog has finished.
KProgressDialog::autoClose
bool autoClose()
Returns true if the dialog will close upon completion, or false otherwise.
Definition: kprogress.cpp:315
KProgressDialog::labelText
TQString labelText() TDE_DEPRECATED
Returns the current dialog text.
Definition: kprogress.cpp:299
KProgressDialog::setAutoReset
void setAutoReset(bool autoReset)
Sets whether the dialog should reset the KProgress dialog back to 0 steps compelete when all steps ha...
Definition: kprogress.cpp:341
KProgressDialog::~KProgressDialog
~KProgressDialog()
Destructor.
Definition: kprogress.cpp:205
KProgressDialog::allowCancel
bool allowCancel() TDE_DEPRECATED
Returns true if the dialog can be canceled, false otherwise.
Definition: kprogress.cpp:273
KProgressDialog::KProgressDialog
KProgressDialog(TQWidget *parent=0, const char *name=0, const TQString &caption=TQString::null, const TQString &text=TQString::null, bool modal=false)
Constructs a KProgressDialog.
Definition: kprogress.cpp:169
KProgressDialog::ignoreCancel
void ignoreCancel()
Definition: kprogress.cpp:236
KProgressDialog::show
virtual void show()
Reimplemented for internal reasons, the API is not affected.
Definition: kprogress.cpp:401
KProgressDialog::setMinimumDuration
void setMinimumDuration(int ms)
Set the minimum number of milliseconds to wait before actually showing the dialog.
Definition: kprogress.cpp:246
KProgressDialog::buttonText
TQString buttonText() TDE_DEPRECATED
Returns the text on the cancel button.
Definition: kprogress.cpp:353
KProgressDialog::setAllowCancel
void setAllowCancel(bool allowCancel)
Sets whether or not the user can cancel the process.
Definition: kprogress.cpp:266
KProgressDialog::wasCancelled
bool wasCancelled()
Returns true if the dialog was closed or canceled before completion.
Definition: kprogress.cpp:231
KProgressDialog::autoReset
bool autoReset()
Returns true if the KProgress widget will be reset upon completion, or false otherwise.
Definition: kprogress.cpp:331
KProgressDialog::progressBar
KProgress * progressBar()
Returns the KProgress used in this dialog.
Definition: kprogress.cpp:283
KProgressDialog::showCancelButton
void showCancelButton(bool show)
Sets whether the cancel button is visible.
Definition: kprogress.cpp:309
KProgressDialog::setAutoClose
void setAutoClose(bool close)
Sets whether the dialog should close automagically when all the steps in the KProgress have been comp...
Definition: kprogress.cpp:325
KProgressDialog::setButtonText
void setButtonText(const TQString &)
Sets the text to appear on the cancel button.
Definition: kprogress.cpp:346
KProgressDialog::minimumDuration
int minimumDuration() TDE_DEPRECATED
Returns the wait duration in milliseconds.
Definition: kprogress.cpp:256
KProgressDialog::setLabel
void setLabel(const TQString &text)
Sets the text in the dialog.
Definition: kprogress.cpp:293
KProgress
A progress indicator widget.
Definition: kprogress.h:47
KProgress::setRange
void setRange(int min, int max) TDE_DEPRECATED
Definition: kprogress.cpp:91
KProgress::textEnabled
bool textEnabled() const
Returns true if progress text will be displayed, false otherwise.
Definition: kprogress.cpp:107
KProgress::setTextEnabled
void setTextEnabled(bool)
If this is set to true, the progress text will be displayed.
Definition: kprogress.cpp:102
KProgress::setFormat
void setFormat(const TQString &format)
Set the format of the text to use to display status.
Definition: kprogress.cpp:112
KProgress::KProgress
KProgress(TQWidget *parent=0, const char *name=0, WFlags f=0)
Construct a progress bar.
Definition: kprogress.cpp:41
KProgress::value
int value() const TDE_DEPRECATED
Definition: kprogress.cpp:125
KProgress::~KProgress
~KProgress()
Destruct the progress bar.
Definition: kprogress.cpp:55
KProgress::setProgress
virtual void setProgress(int progress)
Set the current value of the progress bar to progress.
Definition: kprogress.cpp:74
KProgress::setValue
void setValue(int progress)
Definition: kprogress.cpp:85
KProgress::setTotalSteps
void setTotalSteps(int totalSteps)
Set the current total number of steps in the action that the progress bar is representing.
Definition: kprogress.cpp:64
KProgress::percentageChanged
void percentageChanged(int)
Emitted when the state of the progress bar changes.
KProgress::advance
virtual void advance(int offset)
Advance the progress bar by offset.
Definition: kprogress.cpp:59
KProgress::format
TQString format() const
Retrieve the current format for printing status text.
Definition: kprogress.cpp:119
KProgress::maxValue
int maxValue() TDE_DEPRECATED
Definition: kprogress.cpp:97
KWin::setIcons
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
tdelocale.h

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.