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

KDEUI

kprogressdialog.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 1996 Martynas Kunigelis // krazy:exclude=copyright (email unknown)
00003    Copyright (C) 2006-2007 Urs Wolfer <uwolfer at kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kprogressdialog.h"
00021 
00022 #include <QLabel>
00023 #include <QLayout>
00024 #include <QProgressBar>
00025 #include <QTimer>
00026 
00027 #include <kguiitem.h>
00028 #include <kpushbutton.h>
00029 
00030 class KProgressDialog::KProgressDialogPrivate
00031 {
00032 public:
00033     KProgressDialogPrivate(KProgressDialog *q)
00034         : q(q),
00035           cancelButtonShown(true),
00036           mAutoClose(true),
00037           mAutoReset(false),
00038           mCancelled(false),
00039           mAllowCancel(true),
00040           mShown(false),
00041           mMinDuration(2000)
00042     {
00043     }
00044 
00045     void slotAutoShow();
00046     void slotAutoActions(int percentage);
00047 
00048     KProgressDialog *q;
00049     bool          cancelButtonShown : 1;
00050     bool          mAutoClose : 1;
00051     bool          mAutoReset : 1;
00052     bool          mCancelled : 1;
00053     bool          mAllowCancel : 1;
00054     bool          mShown : 1;
00055     QString       mCancelText;
00056     QLabel*       mLabel;
00057     QProgressBar* mProgressBar;
00058     QTimer*       mShowTimer;
00059     int           mMinDuration;
00060 };
00061 
00062 KProgressDialog::KProgressDialog(QWidget* parent, const QString& caption,
00063                                  const QString& text, Qt::WFlags flags)
00064   : KDialog(parent, flags),
00065     d(new KProgressDialogPrivate(this))
00066 {
00067     setCaption(caption);
00068     setButtons(KDialog::Cancel);
00069 
00070     d->mShowTimer = new QTimer(this);
00071 
00072     d->mCancelText = KDialog::buttonText(KDialog::Cancel);
00073 
00074     QWidget *mainWidget = new QWidget(this);
00075     QVBoxLayout* layout = new QVBoxLayout(mainWidget);
00076     layout->setMargin(10);
00077 
00078     d->mLabel = new QLabel(text, mainWidget);
00079     layout->addWidget(d->mLabel);
00080 
00081     d->mProgressBar = new QProgressBar(mainWidget);
00082     layout->addWidget(d->mProgressBar);
00083 
00084     setMainWidget(mainWidget);
00085 
00086     connect(d->mProgressBar, SIGNAL(valueChanged(int)),
00087             this, SLOT(slotAutoActions(int)));
00088     connect(d->mShowTimer, SIGNAL(timeout()), this, SLOT(slotAutoShow()));
00089     d->mShowTimer->setSingleShot(true);
00090     d->mShowTimer->start(d->mMinDuration);
00091 }
00092 
00093 KProgressDialog::~KProgressDialog()
00094 {
00095     delete d;
00096 }
00097 
00098 void KProgressDialog::KProgressDialogPrivate::slotAutoShow()
00099 {
00100     if (mShown || mCancelled)
00101     {
00102         return;
00103     }
00104 
00105     q->show();
00106 }
00107 
00108 void KProgressDialog::showEvent(QShowEvent *event)
00109 {
00110     d->mShown = true;
00111     KDialog::showEvent(event);
00112 }
00113 
00114 void KProgressDialog::reject()
00115 {
00116     d->mCancelled = true;
00117 
00118     if (d->mAllowCancel)
00119     {
00120         KDialog::reject();
00121     }
00122 }
00123 
00124 bool KProgressDialog::wasCancelled() const
00125 {
00126     return d->mCancelled;
00127 }
00128 
00129 void KProgressDialog::ignoreCancel()
00130 {
00131     d->mCancelled = false;
00132 }
00133 
00134 void KProgressDialog::setMinimumDuration(int ms)
00135 {
00136     d->mMinDuration = ms;
00137     if (!d->mShown)
00138     {
00139         d->mShowTimer->stop();
00140         d->mShowTimer->setSingleShot(true);
00141         d->mShowTimer->start(d->mMinDuration);
00142     }
00143 }
00144 
00145 int KProgressDialog::minimumDuration() const
00146 {
00147     return d->mMinDuration;
00148 }
00149 
00150 void KProgressDialog::setAllowCancel(bool allowCancel)
00151 {
00152     d->mAllowCancel = allowCancel;
00153     showCancelButton(allowCancel);
00154 }
00155 
00156 bool KProgressDialog::allowCancel() const
00157 {
00158     return d->mAllowCancel;
00159 }
00160 
00161 QProgressBar* KProgressDialog::progressBar()
00162 {
00163     return d->mProgressBar;
00164 }
00165 
00166 const QProgressBar* KProgressDialog::progressBar() const
00167 {
00168     return d->mProgressBar;
00169 }
00170 
00171 void KProgressDialog::setLabelText(const QString& text)
00172 {
00173     d->mLabel->setText(text);
00174 }
00175 
00176 QString KProgressDialog::labelText() const
00177 {
00178     return d->mLabel->text();
00179 }
00180 
00181 void KProgressDialog::showCancelButton(bool show)
00182 {
00183     showButton(Cancel, show);
00184 }
00185 
00186 bool KProgressDialog::autoClose() const
00187 {
00188     return d->mAutoClose;
00189 }
00190 
00191 void KProgressDialog::setAutoClose(bool autoClose)
00192 {
00193     d->mAutoClose = autoClose;
00194 }
00195 
00196 bool KProgressDialog::autoReset() const
00197 {
00198     return d->mAutoReset;
00199 }
00200 
00201 void KProgressDialog::setAutoReset(bool autoReset)
00202 {
00203     d->mAutoReset = autoReset;
00204 }
00205 
00206 void KProgressDialog::setButtonText(const QString& text)
00207 {
00208     d->mCancelText = text;
00209     setButtonGuiItem(Cancel, KGuiItem(text));
00210 }
00211 
00212 QString KProgressDialog::buttonText() const
00213 {
00214     return d->mCancelText;
00215 }
00216 
00217 void KProgressDialog::KProgressDialogPrivate::slotAutoActions(int percentage)
00218 {
00219     if (percentage < mProgressBar->maximum())
00220     {
00221         if (!cancelButtonShown)
00222         {
00223             q->setButtonGuiItem(KDialog::Cancel, KGuiItem(mCancelText));
00224             cancelButtonShown = true;
00225         }
00226         return;
00227     }
00228 
00229     mShowTimer->stop();
00230 
00231     if (mAutoReset)
00232     {
00233         mProgressBar->setValue(0);
00234     }
00235     else
00236     {
00237         q->setAllowCancel(true);
00238         q->setButtonGuiItem(Cancel, KStandardGuiItem::close());
00239         cancelButtonShown = false;
00240     }
00241 
00242     if (mAutoClose)
00243     {
00244         if (mShown)
00245         {
00246             q->hide();
00247         }
00248         else
00249         {
00250             emit q->finished();
00251         }
00252     }
00253 }
00254 
00255 #include "kprogressdialog.moc"

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal