summaryrefslogtreecommitdiffstats
path: root/kdeui/kprogressbox.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-19 02:52:15 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-19 02:52:15 +0000
commit9e6594d3aac90beca6b88ec752929c32eb212526 (patch)
tree515e0d1fac68b01a5542357549798180d3154d62 /kdeui/kprogressbox.cpp
parent2b3f464ab9d54d07697f3db7e5e445b8893e2ac0 (diff)
downloadtdelibs-9e6594d3aac90beca6b88ec752929c32eb212526.tar.gz
tdelibs-9e6594d3aac90beca6b88ec752929c32eb212526.zip
Added new kprogressbox dialog
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1104966 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdeui/kprogressbox.cpp')
-rw-r--r--kdeui/kprogressbox.cpp316
1 files changed, 316 insertions, 0 deletions
diff --git a/kdeui/kprogressbox.cpp b/kdeui/kprogressbox.cpp
new file mode 100644
index 000000000..965d8179b
--- /dev/null
+++ b/kdeui/kprogressbox.cpp
@@ -0,0 +1,316 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2010 Timothy Pearson
+ Copyright (C) 1996 Martynas Kunigelis
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+/**
+ * KProgressBox -- a progress indicator widget for KDE with an expandable textbox provided below the progress bar.
+ */
+
+#include <stdlib.h>
+#include <limits.h>
+
+#include <qpainter.h>
+#include <qpixmap.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qstring.h>
+#include <qregexp.h>
+#include <qstyle.h>
+#include <qtimer.h>
+
+#include "kprogress.h"
+#include "ktextedit.h"
+#include "kprogressbox.h"
+
+#include <kapplication.h>
+#include <klocale.h>
+#include <kwin.h>
+
+struct KProgressBoxDialog::KProgressBoxDialogPrivate
+{
+ KProgressBoxDialogPrivate() : cancelButtonShown(true)
+ {
+ }
+
+ bool cancelButtonShown;
+};
+
+/*
+ * KProgressBoxDialog implementation
+ */
+KProgressBoxDialog::KProgressBoxDialog(QWidget* parent, const char* name,
+ const QString& caption, const QString& text,
+ bool modal)
+ : KDialogBase(KDialogBase::Plain, caption, KDialogBase::Cancel,
+ KDialogBase::Cancel, parent, name, modal),
+ mAutoClose(true),
+ mAutoReset(false),
+ mCancelled(false),
+ mAllowCancel(true),
+ mAllowTextEdit(false),
+ mShown(false),
+ mMinDuration(2000),
+ d(new KProgressBoxDialogPrivate)
+{
+#ifdef Q_WS_X11
+ KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
+#endif
+ mShowTimer = new QTimer(this);
+
+ showButton(KDialogBase::Close, false);
+ mCancelText = actionButton(KDialogBase::Cancel)->text();
+
+ QFrame* mainWidget = plainPage();
+ QVBoxLayout* layout = new QVBoxLayout(mainWidget, 10);
+
+ mLabel = new QLabel(text, mainWidget);
+ layout->addWidget(mLabel);
+
+ mProgressBar = new KProgress(mainWidget);
+ layout->addWidget(mProgressBar);
+ mTextBox = new KTextEdit(mainWidget);
+ layout->addWidget(mTextBox);
+
+ connect(mProgressBar, SIGNAL(percentageChanged(int)),
+ this, SLOT(slotAutoActions(int)));
+ connect(mShowTimer, SIGNAL(timeout()), this, SLOT(slotAutoShow()));
+ mShowTimer->start(mMinDuration, true);
+}
+
+KProgressBoxDialog::~KProgressBoxDialog()
+{
+ delete d;
+}
+
+void KProgressBoxDialog::slotAutoShow()
+{
+ if (mShown || mCancelled)
+ {
+ return;
+ }
+
+ show();
+ kapp->processEvents();
+}
+
+void KProgressBoxDialog::slotCancel()
+{
+ mCancelled = true;
+
+ if (mAllowCancel)
+ {
+ KDialogBase::slotCancel();
+ }
+}
+
+bool KProgressBoxDialog::wasCancelled()
+{
+ return mCancelled;
+}
+
+void KProgressBoxDialog::ignoreCancel()
+{
+ mCancelled = false;
+}
+
+bool KProgressBoxDialog::wasCancelled() const
+{
+ return mCancelled;
+}
+
+void KProgressBoxDialog::setMinimumDuration(int ms)
+{
+ mMinDuration = ms;
+ if (!mShown)
+ {
+ mShowTimer->stop();
+ mShowTimer->start(mMinDuration, true);
+ }
+}
+
+int KProgressBoxDialog::minimumDuration()
+{
+ return mMinDuration;
+}
+
+int KProgressBoxDialog::minimumDuration() const
+{
+ return mMinDuration;
+}
+
+void KProgressBoxDialog::setAllowCancel(bool allowCancel)
+{
+ mAllowCancel = allowCancel;
+ showCancelButton(allowCancel);
+}
+
+void KProgressBoxDialog::setAllowTextEdit(bool allowTextEdit)
+{
+ mAllowTextEdit = allowTextEdit;
+ mTextBox->setReadOnly(!allowTextEdit);
+}
+
+// ### KDE 4 remove
+bool KProgressBoxDialog::allowCancel()
+{
+ return mAllowCancel;
+}
+
+bool KProgressBoxDialog::allowCancel() const
+{
+ return mAllowCancel;
+}
+
+KProgress* KProgressBoxDialog::progressBar()
+{
+ return mProgressBar;
+}
+
+KTextEdit* KProgressBoxDialog::textEdit()
+{
+ return mTextBox;
+}
+
+const KProgress* KProgressBoxDialog::progressBar() const
+{
+ return mProgressBar;
+}
+
+const KTextEdit* KProgressBoxDialog::textEdit() const
+{
+ return mTextBox;
+}
+
+void KProgressBoxDialog::setLabel(const QString& text)
+{
+ mLabel->setText(text);
+}
+
+// ### KDE 4 remove
+QString KProgressBoxDialog::labelText()
+{
+ return mLabel->text();
+}
+
+QString KProgressBoxDialog::labelText() const
+{
+ return mLabel->text();
+}
+
+void KProgressBoxDialog::showCancelButton(bool show)
+{
+ showButtonCancel(show);
+}
+
+// ### KDE 4 remove
+bool KProgressBoxDialog::autoClose()
+{
+ return mAutoClose;
+}
+
+bool KProgressBoxDialog::autoClose() const
+{
+ return mAutoClose;
+}
+
+void KProgressBoxDialog::setAutoClose(bool autoClose)
+{
+ mAutoClose = autoClose;
+}
+
+// ### KDE 4 remove
+bool KProgressBoxDialog::autoReset()
+{
+ return mAutoReset;
+}
+
+bool KProgressBoxDialog::autoReset() const
+{
+ return mAutoReset;
+}
+
+void KProgressBoxDialog::setAutoReset(bool autoReset)
+{
+ mAutoReset = autoReset;
+}
+
+void KProgressBoxDialog::setButtonText(const QString& text)
+{
+ mCancelText = text;
+ setButtonCancel(text);
+}
+
+// ### KDE 4 remove
+QString KProgressBoxDialog::buttonText()
+{
+ return mCancelText;
+}
+
+QString KProgressBoxDialog::buttonText() const
+{
+ return mCancelText;
+}
+
+void KProgressBoxDialog::slotAutoActions(int percentage)
+{
+ if (percentage < 100)
+ {
+ if (!d->cancelButtonShown)
+ {
+ setButtonCancel(mCancelText);
+ d->cancelButtonShown = true;
+ }
+ return;
+ }
+
+ mShowTimer->stop();
+
+ if (mAutoReset)
+ {
+ mProgressBar->setProgress(0);
+ }
+ else
+ {
+ setAllowCancel(true);
+ setButtonCancel(KStdGuiItem::close());
+ d->cancelButtonShown = false;
+ }
+
+ if (mAutoClose)
+ {
+ if (mShown)
+ {
+ hide();
+ }
+ else
+ {
+ emit finished();
+ }
+ }
+}
+
+void KProgressBoxDialog::show()
+{
+ KDialogBase::show();
+ mShown = true;
+}
+
+void KProgressBoxDialog::virtual_hook( int id, void* data )
+{ KDialogBase::virtual_hook( id, data ); }
+
+#include "kprogressbox.moc"