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

tdeui

kprogressbox.cpp
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2010 Timothy Pearson
00003    Copyright (C) 1996 Martynas Kunigelis
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 */
00023 #include <stdlib.h>
00024 #include <limits.h>
00025 
00026 #include <tqpainter.h>
00027 #include <tqpixmap.h>
00028 #include <tqlabel.h>
00029 #include <tqlayout.h>
00030 #include <tqpushbutton.h>
00031 #include <tqstring.h>
00032 #include <tqregexp.h>
00033 #include <tqstyle.h>
00034 #include <tqtimer.h>
00035 
00036 #include "kprogress.h"
00037 #include "ktextedit.h"
00038 #include "kprogressbox.h"
00039 
00040 #include <tdeapplication.h>
00041 #include <tdelocale.h>
00042 #include <twin.h>
00043 
00044 struct KProgressBoxDialog::KProgressBoxDialogPrivate
00045 {
00046     KProgressBoxDialogPrivate() : cancelButtonShown(true)
00047     {
00048     }
00049 
00050     bool cancelButtonShown;
00051 };
00052 
00053 /*
00054  * KProgressBoxDialog implementation
00055  */
00056 KProgressBoxDialog::KProgressBoxDialog(TQWidget* parent, const char* name,
00057                                  const TQString& caption, const TQString& text,
00058                                  bool modal)
00059     : KDialogBase(KDialogBase::Plain, caption, KDialogBase::Cancel,
00060                   KDialogBase::Cancel, parent, name, modal),
00061       mAutoClose(true),
00062       mAutoReset(false),
00063       mCancelled(false),
00064       mAllowCancel(true),
00065       mAllowTextEdit(false),
00066       mShown(false),
00067       mMinDuration(2000),
00068       d(new KProgressBoxDialogPrivate)
00069 {
00070 #ifdef Q_WS_X11
00071     KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
00072 #endif
00073     mShowTimer = new TQTimer(this);
00074     
00075     showButton(KDialogBase::Close, false);
00076     mCancelText = actionButton(KDialogBase::Cancel)->text();
00077 
00078     TQFrame* mainWidget = plainPage();
00079     TQVBoxLayout* layout = new TQVBoxLayout(mainWidget, 10);
00080 
00081     mLabel = new TQLabel(text, mainWidget);
00082     layout->addWidget(mLabel);
00083 
00084     mProgressBar = new KProgress(mainWidget);
00085     layout->addWidget(mProgressBar);
00086     mTextBox = new KTextEdit(mainWidget);
00087     layout->addWidget(mTextBox);
00088 
00089     connect(mProgressBar, TQT_SIGNAL(percentageChanged(int)),
00090             this, TQT_SLOT(slotAutoActions(int)));
00091     connect(mShowTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotAutoShow()));
00092     mShowTimer->start(mMinDuration, true);
00093 }
00094 
00095 KProgressBoxDialog::~KProgressBoxDialog()
00096 {
00097     delete d;
00098 }
00099 
00100 void KProgressBoxDialog::slotAutoShow()
00101 {
00102     if (mShown || mCancelled)
00103     {
00104         return;
00105     }
00106 
00107     show();
00108     kapp->processEvents();
00109 }
00110 
00111 void KProgressBoxDialog::slotCancel()
00112 {
00113     mCancelled = true;
00114 
00115     if (mAllowCancel)
00116     {
00117         KDialogBase::slotCancel();
00118     }
00119 }
00120 
00121 bool KProgressBoxDialog::wasCancelled()
00122 {
00123     return mCancelled;
00124 }
00125 
00126 void KProgressBoxDialog::ignoreCancel()
00127 {
00128     mCancelled = false;
00129 }
00130 
00131 bool KProgressBoxDialog::wasCancelled() const
00132 {
00133     return mCancelled;
00134 }
00135 
00136 void KProgressBoxDialog::setMinimumDuration(int ms)
00137 {
00138     mMinDuration = ms;
00139     if (!mShown)
00140     {
00141         mShowTimer->stop();
00142         mShowTimer->start(mMinDuration, true);
00143     }
00144 }
00145 
00146 int KProgressBoxDialog::minimumDuration()
00147 {
00148     return mMinDuration;
00149 }
00150 
00151 int KProgressBoxDialog::minimumDuration() const
00152 {
00153     return mMinDuration;
00154 }
00155 
00156 void KProgressBoxDialog::setAllowCancel(bool allowCancel)
00157 {
00158     mAllowCancel = allowCancel;
00159     showCancelButton(allowCancel);
00160 }
00161 
00162 void KProgressBoxDialog::setAllowTextEdit(bool allowTextEdit)
00163 {
00164     mAllowTextEdit = allowTextEdit;
00165     mTextBox->setReadOnly(!allowTextEdit);
00166 }
00167 
00168 // ### KDE 4 remove
00169 bool KProgressBoxDialog::allowCancel()
00170 {
00171     return mAllowCancel;
00172 }
00173 
00174 bool KProgressBoxDialog::allowCancel() const
00175 {
00176     return mAllowCancel;
00177 }
00178 
00179 KProgress* KProgressBoxDialog::progressBar()
00180 {
00181     return mProgressBar;
00182 }
00183 
00184 KTextEdit* KProgressBoxDialog::textEdit()
00185 {
00186     return mTextBox;
00187 }
00188 
00189 const KProgress* KProgressBoxDialog::progressBar() const
00190 {
00191     return mProgressBar;
00192 }
00193 
00194 const KTextEdit* KProgressBoxDialog::textEdit() const
00195 {
00196     return mTextBox;
00197 }
00198 
00199 void KProgressBoxDialog::setLabel(const TQString& text)
00200 {
00201     mLabel->setText(text);
00202 }
00203 
00204 // ### KDE 4 remove
00205 TQString KProgressBoxDialog::labelText()
00206 {
00207     return mLabel->text();
00208 }
00209 
00210 TQString KProgressBoxDialog::labelText() const
00211 {
00212     return mLabel->text();
00213 }
00214 
00215 void KProgressBoxDialog::showCancelButton(bool show)
00216 {
00217     showButtonCancel(show);
00218 }
00219 
00220 // ### KDE 4 remove
00221 bool KProgressBoxDialog::autoClose()
00222 {
00223     return mAutoClose;
00224 }
00225 
00226 bool KProgressBoxDialog::autoClose() const
00227 {
00228     return mAutoClose;
00229 }
00230 
00231 void KProgressBoxDialog::setAutoClose(bool autoClose)
00232 {
00233     mAutoClose = autoClose;
00234 }
00235 
00236 // ### KDE 4 remove
00237 bool KProgressBoxDialog::autoReset()
00238 {
00239     return mAutoReset;
00240 }
00241 
00242 bool KProgressBoxDialog::autoReset() const
00243 {
00244     return mAutoReset;
00245 }
00246 
00247 void KProgressBoxDialog::setAutoReset(bool autoReset)
00248 {
00249     mAutoReset = autoReset;
00250 }
00251 
00252 void KProgressBoxDialog::setButtonText(const TQString& text)
00253 {
00254     mCancelText = text;
00255     setButtonCancel(text);
00256 }
00257 
00258 // ### KDE 4 remove
00259 TQString KProgressBoxDialog::buttonText()
00260 {
00261     return mCancelText;
00262 }
00263 
00264 TQString KProgressBoxDialog::buttonText() const
00265 {
00266     return mCancelText;
00267 }
00268 
00269 void KProgressBoxDialog::slotAutoActions(int percentage)
00270 {
00271     if (percentage < 100)
00272     {
00273         if (!d->cancelButtonShown)
00274         {
00275             setButtonCancel(mCancelText);
00276             d->cancelButtonShown = true;
00277         }
00278         return;
00279     }
00280 
00281     mShowTimer->stop();
00282 
00283     if (mAutoReset)
00284     {
00285         mProgressBar->setProgress(0);
00286     }
00287     else
00288     {
00289         setAllowCancel(true);
00290         setButtonCancel(KStdGuiItem::close());
00291         d->cancelButtonShown = false;
00292     }
00293 
00294     if (mAutoClose)
00295     {
00296         if (mShown)
00297         {
00298             hide();
00299         }
00300         else
00301         {
00302             emit finished();
00303         }
00304     }
00305 }
00306 
00307 void KProgressBoxDialog::show()
00308 {
00309     KDialogBase::show();
00310     mShown = true;
00311 }
00312 
00313 void KProgressBoxDialog::virtual_hook( int id, void* data )
00314 { KDialogBase::virtual_hook( id, data ); }
00315 
00316 #include "kprogressbox.moc"

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.7.6.1
This website is maintained by Timothy Pearson.