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

tdeui

  • tdeui
kprogressbox.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2010 Timothy Pearson
3  Copyright (C) 1996 Martynas Kunigelis
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
23 #include <stdlib.h>
24 #include <limits.h>
25 
26 #include <tqpainter.h>
27 #include <tqpixmap.h>
28 #include <tqlabel.h>
29 #include <tqlayout.h>
30 #include <tqpushbutton.h>
31 #include <tqstring.h>
32 #include <tqregexp.h>
33 #include <tqstyle.h>
34 #include <tqtimer.h>
35 
36 #include "kprogress.h"
37 #include "ktextedit.h"
38 #include "kprogressbox.h"
39 
40 #include <tdeapplication.h>
41 #include <tdelocale.h>
42 #include <twin.h>
43 
44 struct KProgressBoxDialog::KProgressBoxDialogPrivate
45 {
46  KProgressBoxDialogPrivate() : cancelButtonShown(true)
47  {
48  }
49 
50  bool cancelButtonShown;
51 };
52 
53 /*
54  * KProgressBoxDialog implementation
55  */
56 KProgressBoxDialog::KProgressBoxDialog(TQWidget* parent, const char* name,
57  const TQString& caption, const TQString& text,
58  bool modal)
59  : KDialogBase(KDialogBase::Plain, caption, KDialogBase::Cancel,
60  KDialogBase::Cancel, parent, name, modal),
61  mAutoClose(true),
62  mAutoReset(false),
63  mCancelled(false),
64  mAllowCancel(true),
65  mAllowTextEdit(false),
66  mShown(false),
67  mMinDuration(2000),
68  d(new KProgressBoxDialogPrivate)
69 {
70 #ifdef Q_WS_X11
71  KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
72 #endif
73  mShowTimer = new TQTimer(this);
74 
75  showButton(KDialogBase::Close, false);
76  mCancelText = actionButton(KDialogBase::Cancel)->text();
77 
78  TQFrame* mainWidget = plainPage();
79  TQVBoxLayout* layout = new TQVBoxLayout(mainWidget, 10);
80 
81  mLabel = new TQLabel(text, mainWidget);
82  layout->addWidget(mLabel);
83 
84  mProgressBar = new KProgress(mainWidget);
85  layout->addWidget(mProgressBar);
86  mTextBox = new KTextEdit(mainWidget);
87  layout->addWidget(mTextBox);
88 
89  connect(mProgressBar, TQT_SIGNAL(percentageChanged(int)),
90  this, TQT_SLOT(slotAutoActions(int)));
91  connect(mShowTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotAutoShow()));
92  mShowTimer->start(mMinDuration, true);
93 }
94 
95 KProgressBoxDialog::~KProgressBoxDialog()
96 {
97  delete d;
98 }
99 
100 void KProgressBoxDialog::slotAutoShow()
101 {
102  if (mShown || mCancelled)
103  {
104  return;
105  }
106 
107  show();
108  kapp->processEvents();
109 }
110 
111 void KProgressBoxDialog::slotCancel()
112 {
113  mCancelled = true;
114 
115  if (mAllowCancel)
116  {
117  KDialogBase::slotCancel();
118  }
119 }
120 
121 bool KProgressBoxDialog::wasCancelled()
122 {
123  return mCancelled;
124 }
125 
126 void KProgressBoxDialog::ignoreCancel()
127 {
128  mCancelled = false;
129 }
130 
131 bool KProgressBoxDialog::wasCancelled() const
132 {
133  return mCancelled;
134 }
135 
136 void KProgressBoxDialog::setMinimumDuration(int ms)
137 {
138  mMinDuration = ms;
139  if (!mShown)
140  {
141  mShowTimer->stop();
142  mShowTimer->start(mMinDuration, true);
143  }
144 }
145 
146 int KProgressBoxDialog::minimumDuration()
147 {
148  return mMinDuration;
149 }
150 
151 int KProgressBoxDialog::minimumDuration() const
152 {
153  return mMinDuration;
154 }
155 
156 void KProgressBoxDialog::setAllowCancel(bool allowCancel)
157 {
158  mAllowCancel = allowCancel;
159  showCancelButton(allowCancel);
160 }
161 
162 void KProgressBoxDialog::setAllowTextEdit(bool allowTextEdit)
163 {
164  mAllowTextEdit = allowTextEdit;
165  mTextBox->setReadOnly(!allowTextEdit);
166 }
167 
168 // ### KDE 4 remove
169 bool KProgressBoxDialog::allowCancel()
170 {
171  return mAllowCancel;
172 }
173 
174 bool KProgressBoxDialog::allowCancel() const
175 {
176  return mAllowCancel;
177 }
178 
179 KProgress* KProgressBoxDialog::progressBar()
180 {
181  return mProgressBar;
182 }
183 
184 KTextEdit* KProgressBoxDialog::textEdit()
185 {
186  return mTextBox;
187 }
188 
189 const KProgress* KProgressBoxDialog::progressBar() const
190 {
191  return mProgressBar;
192 }
193 
194 const KTextEdit* KProgressBoxDialog::textEdit() const
195 {
196  return mTextBox;
197 }
198 
199 void KProgressBoxDialog::setLabel(const TQString& text)
200 {
201  mLabel->setText(text);
202 }
203 
204 // ### KDE 4 remove
205 TQString KProgressBoxDialog::labelText()
206 {
207  return mLabel->text();
208 }
209 
210 TQString KProgressBoxDialog::labelText() const
211 {
212  return mLabel->text();
213 }
214 
215 void KProgressBoxDialog::showCancelButton(bool show)
216 {
217  showButtonCancel(show);
218 }
219 
220 // ### KDE 4 remove
221 bool KProgressBoxDialog::autoClose()
222 {
223  return mAutoClose;
224 }
225 
226 bool KProgressBoxDialog::autoClose() const
227 {
228  return mAutoClose;
229 }
230 
231 void KProgressBoxDialog::setAutoClose(bool autoClose)
232 {
233  mAutoClose = autoClose;
234 }
235 
236 // ### KDE 4 remove
237 bool KProgressBoxDialog::autoReset()
238 {
239  return mAutoReset;
240 }
241 
242 bool KProgressBoxDialog::autoReset() const
243 {
244  return mAutoReset;
245 }
246 
247 void KProgressBoxDialog::setAutoReset(bool autoReset)
248 {
249  mAutoReset = autoReset;
250 }
251 
252 void KProgressBoxDialog::setButtonText(const TQString& text)
253 {
254  mCancelText = text;
255  setButtonCancel(text);
256 }
257 
258 // ### KDE 4 remove
259 TQString KProgressBoxDialog::buttonText()
260 {
261  return mCancelText;
262 }
263 
264 TQString KProgressBoxDialog::buttonText() const
265 {
266  return mCancelText;
267 }
268 
269 void KProgressBoxDialog::slotAutoActions(int percentage)
270 {
271  if (percentage < 100)
272  {
273  if (!d->cancelButtonShown)
274  {
275  setButtonCancel(mCancelText);
276  d->cancelButtonShown = true;
277  }
278  return;
279  }
280 
281  mShowTimer->stop();
282 
283  if (mAutoReset)
284  {
285  mProgressBar->setProgress(0);
286  }
287  else
288  {
289  setAllowCancel(true);
290  setButtonCancel(KStdGuiItem::close());
291  d->cancelButtonShown = false;
292  }
293 
294  if (mAutoClose)
295  {
296  if (mShown)
297  {
298  hide();
299  }
300  else
301  {
302  emit finished();
303  }
304  }
305 }
306 
307 void KProgressBoxDialog::show()
308 {
309  KDialogBase::show();
310  mShown = true;
311 }
312 
313 void KProgressBoxDialog::virtual_hook( int id, void* data )
314 { KDialogBase::virtual_hook( id, data ); }
315 
316 #include "kprogressbox.moc"
KProgressBoxDialog::wasCancelled
bool wasCancelled()
Returns true if the dialog was closed or canceled before completion.
Definition: kprogressbox.cpp:121
KProgress::setProgress
virtual void setProgress(int progress)
Set the current value of the progress bar to progress.
Definition: kprogress.cpp:74
KDialogBase::Close
Show Close-button.
Definition: kdialogbase.h:205
KProgressBoxDialog::setMinimumDuration
void setMinimumDuration(int ms)
Set the minimum number of milliseconds to wait before actually showing the dialog.
Definition: kprogressbox.cpp:136
KDialogBase::setButtonCancel
void setButtonCancel(const KGuiItem &item=KStdGuiItem::cancel())
Sets the appearance of the Cancel button.
Definition: kdialogbase.cpp:970
KProgress
A progress indicator widget.
Definition: kprogress.h:46
KProgressBoxDialog::labelText
TQString labelText() KDE_DEPRECATED
Returns the current dialog text.
Definition: kprogressbox.cpp:205
KProgressBoxDialog::show
virtual void show()
Reimplemented for internal reasons, the API is not affected.
Definition: kprogressbox.cpp:307
KDialogBase::Cancel
Show Cancel-button.
Definition: kdialogbase.h:204
KProgressBoxDialog::setLabel
void setLabel(const TQString &text)
Sets the text in the dialog.
Definition: kprogressbox.cpp:199
KProgressBoxDialog::progressBar
KProgress * progressBar()
Returns the KProgressBox used in this dialog.
Definition: kprogressbox.cpp:179
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:191
KTextEdit::setReadOnly
virtual void setReadOnly(bool readOnly)
Reimplemented to set a proper "deactivated" background color.
Definition: ktextedit.cpp:309
tdelocale.h
KProgressBoxDialog::allowCancel
bool allowCancel() KDE_DEPRECATED
Returns true if the dialog can be canceled, false otherwise.
Definition: kprogressbox.cpp:169
KProgressBoxDialog::~KProgressBoxDialog
~KProgressBoxDialog()
Destructor.
Definition: kprogressbox.cpp:95
KProgressBoxDialog::setButtonText
void setButtonText(const TQString &)
Sets the text to appear on the cancel button.
Definition: kprogressbox.cpp:252
KProgressBoxDialog::textEdit
KTextEdit * textEdit()
Returns the KTextEdit used in this dialog.
Definition: kprogressbox.cpp:184
KProgressBoxDialog::showCancelButton
void showCancelButton(bool show)
Sets whether the cancel button is visible.
Definition: kprogressbox.cpp:215
KProgressBoxDialog::minimumDuration
int minimumDuration() KDE_DEPRECATED
Returns the wait duration in milliseconds.
Definition: kprogressbox.cpp:146
KDialogBase::actionButton
TQPushButton * actionButton(ButtonCode id)
Returns the action button that corresponds to the id.
Definition: kdialogbase.cpp:832
KDialogBase::plainPage
TQFrame * plainPage()
Retrieve the empty page when the predefined layout is used in Plain mode.
Definition: kdialogbase.cpp:420
KProgressBoxDialog::setAllowTextEdit
void setAllowTextEdit(bool allowTextEdit)
Sets whether or not the user can edit the text shown in the textbox.
Definition: kprogressbox.cpp:162
KProgressBoxDialog::buttonText
TQString buttonText() KDE_DEPRECATED
Returns the text on the cancel button.
Definition: kprogressbox.cpp:259
KProgressBoxDialog::ignoreCancel
void ignoreCancel()
Ignores the last cancel action if the cancel button was pressed.
Definition: kprogressbox.cpp:126
KProgressBoxDialog::setAutoReset
void setAutoReset(bool autoReset)
Sets whether the dialog should reset the KProgressBox dialog back to 0 steps compelete when all steps...
Definition: kprogressbox.cpp:247
KProgressBoxDialog::KProgressBoxDialog
KProgressBoxDialog(TQWidget *parent=0, const char *name=0, const TQString &caption=TQString::null, const TQString &text=TQString::null, bool modal=false)
Constructs a KProgressBoxDialog.
Definition: kprogressbox.cpp:56
KDialogBase::slotCancel
virtual void slotCancel()
Activated when the Cancel button has been clicked.
Definition: kdialogbase.cpp:1215
KDialogBase::showButton
void showButton(ButtonCode id, bool state)
Hide or display a general action button.
Definition: kdialogbase.cpp:866
KProgressBoxDialog::autoReset
bool autoReset()
Returns true if the KProgressBox widget will be reset upon completion, or false otherwise.
Definition: kprogressbox.cpp:237
KDialogBase::mainWidget
TQWidget * mainWidget()
Returns the main widget if any.
Definition: kdialogbase.cpp:1464
KDialogBase::showButtonCancel
void showButtonCancel(bool state)
Hide or display the Cancel button.
Definition: kdialogbase.cpp:888
KProgressBoxDialog::setAllowCancel
void setAllowCancel(bool allowCancel)
Sets whether or not the user can cancel the process.
Definition: kprogressbox.cpp:156
KProgressBoxDialog::autoClose
bool autoClose()
Returns true if the dialog will close upon completion, or false otherwise.
Definition: kprogressbox.cpp:221
KWin::setIcons
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
KTextEdit
A KDE'ified QTextEdit.
Definition: ktextedit.h:43
KDialogBase::finished
void finished()
The dialog has finished.
KProgressBoxDialog::setAutoClose
void setAutoClose(bool close)
Sets whether the dialog should close automagically when all the steps in the KProgressBox have been c...
Definition: kprogressbox.cpp:231

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.