• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • dialogs
kprogressdialog.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 1996 Martynas Kunigelis // krazy:exclude=copyright (email unknown)
3  Copyright (C) 2006-2007 Urs Wolfer <uwolfer at kde.org>
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 */
19 
20 #include "kprogressdialog.h"
21 
22 #include <QLabel>
23 #include <QLayout>
24 #include <QProgressBar>
25 #include <QTimer>
26 
27 #include <kguiitem.h>
28 #include <kpushbutton.h>
29 
30 class KProgressDialog::KProgressDialogPrivate
31 {
32 public:
33  KProgressDialogPrivate(KProgressDialog *q)
34  : q(q),
35  cancelButtonShown(true),
36  mAutoClose(true),
37  mAutoReset(false),
38  mCancelled(false),
39  mAllowCancel(true),
40  mShown(false),
41  mMinDuration(2000)
42  {
43  }
44 
45  void slotAutoShow();
46  void slotAutoActions(int percentage);
47 
48  KProgressDialog *q;
49  bool cancelButtonShown : 1;
50  bool mAutoClose : 1;
51  bool mAutoReset : 1;
52  bool mCancelled : 1;
53  bool mAllowCancel : 1;
54  bool mShown : 1;
55  QString mCancelText;
56  QLabel* mLabel;
57  QProgressBar* mProgressBar;
58  QTimer* mShowTimer;
59  int mMinDuration;
60 };
61 
62 KProgressDialog::KProgressDialog(QWidget* parent, const QString& caption,
63  const QString& text, Qt::WindowFlags flags)
64  : KDialog(parent, flags),
65  d(new KProgressDialogPrivate(this))
66 {
67  setCaption(caption);
68  setButtons(KDialog::Cancel);
69 
70  d->mShowTimer = new QTimer(this);
71 
72  d->mCancelText = KDialog::buttonText(KDialog::Cancel);
73 
74  QWidget *mainWidget = new QWidget(this);
75  QVBoxLayout* layout = new QVBoxLayout(mainWidget);
76  layout->setMargin(10);
77 
78  d->mLabel = new QLabel(text, mainWidget);
79  layout->addWidget(d->mLabel);
80 
81  d->mProgressBar = new QProgressBar(mainWidget);
82  layout->addWidget(d->mProgressBar);
83 
84  setMainWidget(mainWidget);
85 
86  connect(d->mProgressBar, SIGNAL(valueChanged(int)),
87  this, SLOT(slotAutoActions(int)));
88  connect(d->mShowTimer, SIGNAL(timeout()), this, SLOT(slotAutoShow()));
89  d->mShowTimer->setSingleShot(true);
90  d->mShowTimer->start(d->mMinDuration);
91 }
92 
93 KProgressDialog::~KProgressDialog()
94 {
95  delete d;
96 }
97 
98 void KProgressDialog::KProgressDialogPrivate::slotAutoShow()
99 {
100  if (mShown || mCancelled)
101  {
102  return;
103  }
104 
105  q->show();
106 }
107 
108 void KProgressDialog::showEvent(QShowEvent *event)
109 {
110  d->mShown = true;
111  KDialog::showEvent(event);
112 }
113 
114 void KProgressDialog::reject()
115 {
116  d->mCancelled = true;
117 
118  if (d->mAllowCancel)
119  {
120  KDialog::reject();
121  }
122 }
123 
124 bool KProgressDialog::wasCancelled() const
125 {
126  return d->mCancelled;
127 }
128 
129 void KProgressDialog::ignoreCancel()
130 {
131  d->mCancelled = false;
132 }
133 
134 void KProgressDialog::setMinimumDuration(int ms)
135 {
136  d->mMinDuration = ms;
137  if (!d->mShown)
138  {
139  d->mShowTimer->stop();
140  d->mShowTimer->setSingleShot(true);
141  d->mShowTimer->start(d->mMinDuration);
142  }
143 }
144 
145 int KProgressDialog::minimumDuration() const
146 {
147  return d->mMinDuration;
148 }
149 
150 void KProgressDialog::setAllowCancel(bool allowCancel)
151 {
152  d->mAllowCancel = allowCancel;
153  showCancelButton(allowCancel);
154 }
155 
156 bool KProgressDialog::allowCancel() const
157 {
158  return d->mAllowCancel;
159 }
160 
161 QProgressBar* KProgressDialog::progressBar()
162 {
163  return d->mProgressBar;
164 }
165 
166 const QProgressBar* KProgressDialog::progressBar() const
167 {
168  return d->mProgressBar;
169 }
170 
171 void KProgressDialog::setLabelText(const QString& text)
172 {
173  d->mLabel->setText(text);
174 }
175 
176 QString KProgressDialog::labelText() const
177 {
178  return d->mLabel->text();
179 }
180 
181 void KProgressDialog::showCancelButton(bool show)
182 {
183  showButton(Cancel, show);
184 }
185 
186 bool KProgressDialog::autoClose() const
187 {
188  return d->mAutoClose;
189 }
190 
191 void KProgressDialog::setAutoClose(bool autoClose)
192 {
193  d->mAutoClose = autoClose;
194 }
195 
196 bool KProgressDialog::autoReset() const
197 {
198  return d->mAutoReset;
199 }
200 
201 void KProgressDialog::setAutoReset(bool autoReset)
202 {
203  d->mAutoReset = autoReset;
204 }
205 
206 void KProgressDialog::setButtonText(const QString& text)
207 {
208  d->mCancelText = text;
209  setButtonGuiItem(Cancel, KGuiItem(text));
210 }
211 
212 QString KProgressDialog::buttonText() const
213 {
214  return d->mCancelText;
215 }
216 
217 void KProgressDialog::KProgressDialogPrivate::slotAutoActions(int percentage)
218 {
219  if (percentage < mProgressBar->maximum() ||
220  (mProgressBar->minimum() == mProgressBar->maximum())) // progress dialogs with busy indicators (see #178648)
221  {
222  if (!cancelButtonShown)
223  {
224  q->setButtonGuiItem(KDialog::Cancel, KGuiItem(mCancelText));
225  cancelButtonShown = true;
226  }
227  return;
228  }
229 
230  mShowTimer->stop();
231 
232  if (mAutoReset)
233  {
234  mProgressBar->setValue(0);
235  }
236  else
237  {
238  q->setAllowCancel(true);
239  q->setButtonGuiItem(Cancel, KStandardGuiItem::close());
240  cancelButtonShown = false;
241  }
242 
243  if (mAutoClose)
244  {
245  if (mShown)
246  {
247  q->hide();
248  }
249  else
250  {
251  emit q->finished();
252  }
253  }
254 }
255 
256 #include "kprogressdialog.moc"
QWidget::layout
QLayout * layout() const
KProgressDialog::setMinimumDuration
void setMinimumDuration(int ms)
Set the minimum number of milliseconds to wait before actually showing the dialog.
Definition: kprogressdialog.cpp:134
QProgressBar
KProgressDialog::labelText
QString labelText() const
Returns the current dialog text.
Definition: kprogressdialog.cpp:176
KDialog::setButtonGuiItem
void setButtonGuiItem(ButtonCode id, const KGuiItem &item)
Sets the KGuiItem directly for the button instead of using 3 methods to set the text, tooltip and whatsthis strings.
Definition: kdialog.cpp:699
QWidget
KProgressDialog::buttonText
QString buttonText() const
Returns the text on the cancel button.
Definition: kprogressdialog.cpp:212
KProgressDialog::progressBar
QProgressBar * progressBar()
Returns the QProgressBar used in this dialog.
Definition: kprogressdialog.cpp:161
QDialog::reject
virtual void reject()
KProgressDialog::~KProgressDialog
~KProgressDialog()
Destructor.
Definition: kprogressdialog.cpp:93
KProgressDialog::ignoreCancel
void ignoreCancel()
Ignores the last cancel action if the cancel button was pressed.
Definition: kprogressdialog.cpp:129
timeout
int timeout
KProgressDialog::KProgressDialog
KProgressDialog(QWidget *parent=0, const QString &caption=QString(), const QString &text=QString(), Qt::WindowFlags flags=0)
Constructs a KProgressDialog.
Definition: kprogressdialog.cpp:62
KDialog::Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected) ...
Definition: kdialog.h:144
KProgressDialog::setButtonText
void setButtonText(const QString &text)
Sets the text to appear on the cancel button.
Definition: kprogressdialog.cpp:206
KDialog
A dialog base class with standard buttons and predefined layouts.
Definition: kdialog.h:128
KProgressDialog::autoClose
bool autoClose() const
Returns true if the dialog will close upon completion, or false otherwise.
Definition: kprogressdialog.cpp:186
KDialog::setCaption
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
Definition: kdialog.cpp:469
KDialog::buttonText
QString buttonText(ButtonCode id) const
Returns the text of any button.
Definition: kdialog.cpp:733
KProgressDialog::autoReset
bool autoReset() const
Returns true if the QProgressBar widget will be reset upon completion, or false otherwise.
Definition: kprogressdialog.cpp:196
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
Definition: kdialog.cpp:338
KProgressDialog::wasCancelled
bool wasCancelled() const
Returns true if the dialog was closed or canceled before completion.
Definition: kprogressdialog.cpp:124
KDialog::mainWidget
QWidget * mainWidget()
Definition: kdialog.cpp:351
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QTimer
QShowEvent
KGuiItem
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:36
KProgressDialog::allowCancel
bool allowCancel() const
Returns true if the dialog can be canceled, false otherwise.
Definition: kprogressdialog.cpp:156
QVBoxLayout
KProgressDialog::showCancelButton
void showCancelButton(bool show)
Sets whether the cancel button is visible.
Definition: kprogressdialog.cpp:181
KProgressDialog::setAutoReset
void setAutoReset(bool autoReset)
Sets whether the dialog should reset the QProgressBar dialog back to 0 steps compelete when all steps...
Definition: kprogressdialog.cpp:201
KProgressDialog::showEvent
virtual void showEvent(QShowEvent *event)
Definition: kprogressdialog.cpp:108
QString
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Definition: kdialog.cpp:206
QLayout::setMargin
void setMargin(int margin)
KProgressDialog::reject
virtual void reject()
Definition: kprogressdialog.cpp:114
kprogressdialog.h
kpushbutton.h
KStandardGuiItem::Cancel
Definition: kstandardguiitem.h:50
KStandardGuiItem::close
KGuiItem close()
Returns the 'Close' gui item.
Definition: kstandardguiitem.cpp:182
KDialog::showButton
void showButton(ButtonCode id, bool state)
Hide or display a general action button.
Definition: kdialog.cpp:692
KProgressDialog::minimumDuration
int minimumDuration() const
Returns the time that must pass before the dialog appears.
Definition: kprogressdialog.cpp:145
KProgressDialog
A dialog with a progress bar.
Definition: kprogressdialog.h:47
KProgressDialog::setAllowCancel
void setAllowCancel(bool allowCancel)
Sets whether or not the user can cancel the process.
Definition: kprogressdialog.cpp:150
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
QDialog::showEvent
virtual void showEvent(QShowEvent *event)
KProgressDialog::setLabelText
void setLabelText(const QString &text)
Sets the text in the dialog.
Definition: kprogressdialog.cpp:171
Qt::WindowFlags
typedef WindowFlags
KProgressDialog::setAutoClose
void setAutoClose(bool close)
Sets whether the dialog should close automagically when all the steps in the QProgressBar have been c...
Definition: kprogressdialog.cpp:191
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
kguiitem.h
KProgressDialog::KProgressDialogPrivate
friend class KProgressDialogPrivate
Definition: kprogressdialog.h:204
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal