diff options
author | Jason Barron <jbarron@trolltech.com> | 2009-09-19 17:21:36 (GMT) |
---|---|---|
committer | Jason Barron <jbarron@trolltech.com> | 2009-09-21 08:07:44 (GMT) |
commit | 63b38ba77b4a5603bec9f8e6d63425eb8a8f5d15 (patch) | |
tree | a9b98415612c952ea24e29526461043dcd3c2a29 /src/gui/dialogs | |
parent | db96727a9f890aa86a4ffb7093623c8236c566a5 (diff) | |
download | Qt-63b38ba77b4a5603bec9f8e6d63425eb8a8f5d15.zip Qt-63b38ba77b4a5603bec9f8e6d63425eb8a8f5d15.tar.gz Qt-63b38ba77b4a5603bec9f8e6d63425eb8a8f5d15.tar.bz2 |
Change QProgressDialog to use the new soft key API.
The previous version created a new QAction every time setCancelButton
was called without deleting the previous instance. This version
stores the action pointer in the d-ptr, but still recreates it
everytime the button is changed.
Also, make sure the text is updated if setCancelText is called by
the user.
Reviewed-by: Alessandro Portale
Diffstat (limited to 'src/gui/dialogs')
-rw-r--r-- | src/gui/dialogs/qprogressdialog.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/gui/dialogs/qprogressdialog.cpp b/src/gui/dialogs/qprogressdialog.cpp index 0a4c730..292e950 100644 --- a/src/gui/dialogs/qprogressdialog.cpp +++ b/src/gui/dialogs/qprogressdialog.cpp @@ -57,10 +57,13 @@ #include <private/qdialog_p.h> #include <limits.h> -#if defined(Q_WS_S60) -#include <QtGui/qdesktopwidget.h> +#if defined(QT_SOFTKEYS_ENABLED) #include <qaction.h> #endif +#ifdef Q_WS_S60 +#include <QtGui/qdesktopwidget.h> +#endif + QT_BEGIN_NAMESPACE @@ -82,6 +85,9 @@ public: #ifndef QT_NO_SHORTCUT escapeShortcut(0), #endif +#ifdef QT_SOFTKEYS_ENABLED + cancelAction(0), +#endif useDefaultCancelText(false) { } @@ -108,6 +114,9 @@ public: #ifndef QT_NO_SHORTCUT QShortcut *escapeShortcut; #endif +#ifdef QT_SOFTKEYS_ENABLED + QAction *cancelAction; +#endif bool useDefaultCancelText; QPointer<QObject> receiverToDisconnectOnClose; QByteArray memberToDisconnectOnClose; @@ -415,6 +424,10 @@ void QProgressDialog::setCancelButton(QPushButton *cancelButton) { Q_D(QProgressDialog); delete d->cancel; +#ifdef QT_SOFTKEYS_ENABLED + delete d->cancelAction; + d->cancelAction = 0; +#endif d->cancel = cancelButton; if (cancelButton) { if (cancelButton->parentWidget() == this) { @@ -436,14 +449,14 @@ void QProgressDialog::setCancelButton(QPushButton *cancelButton) int h = qMax(isVisible() ? height() : 0, sizeHint().height()); resize(w, h); if (cancelButton) -#ifndef Q_WS_S60 +#if !defined(QT_SOFTKEYS_ENABLED) cancelButton->show(); #else { - QAction *cancelAction = new QAction(cancelButton->text(), this); - cancelAction->setSoftKeyRole(QAction::CancelSoftKey); - QObject::connect(cancelAction, SIGNAL(triggered()), this, SIGNAL(canceled())); - setSoftKey(cancelAction); + d->cancelAction = new QAction(cancelButton->text(), this); + d->cancelAction->setSoftKeyRole(QAction::CancelSoftKey); + connect(d->cancelAction, SIGNAL(triggered()), this, SIGNAL(canceled())); + addAction(d->cancelAction); } #endif } @@ -462,10 +475,14 @@ void QProgressDialog::setCancelButtonText(const QString &cancelButtonText) d->useDefaultCancelText = false; if (!cancelButtonText.isNull()) { - if (d->cancel) + if (d->cancel) { d->cancel->setText(cancelButtonText); - else +#ifdef QT_SOFTKEYS_ENABLED + d->cancelAction->setText(cancelButtonText); +#endif + } else { setCancelButton(new QPushButton(cancelButtonText, this)); + } } else { setCancelButton(0); } |