From db96727a9f890aa86a4ffb7093623c8236c566a5 Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Sat, 19 Sep 2009 17:45:57 +0200 Subject: Change QErrorMessage to use the new soft key API. With the new softkey API it is not necessaery to call setSoftKeys with the actions you want and then to set it to 0 to clear them. The way to use the API is just call addAction() and this soft key will be valid while this is the active window. Also make sure that the text of the action is updated when retranslateUi() is called. Reviewed-by: Alessandro Portale --- src/gui/dialogs/qerrormessage.cpp | 45 +++++++++++++-------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/src/gui/dialogs/qerrormessage.cpp b/src/gui/dialogs/qerrormessage.cpp index 3fbfce7..78b5529 100644 --- a/src/gui/dialogs/qerrormessage.cpp +++ b/src/gui/dialogs/qerrormessage.cpp @@ -68,10 +68,12 @@ extern bool qt_wince_is_high_dpi(); //defined in qguifunctions_wince.cpp #include "qguifunctions_wince.h" #endif -#if defined(Q_WS_S60) +#if defined(QT_SOFTKEYS_ENABLED) #include +#ifdef Q_WS_S60 #include "private/qt_s60_p.h" #endif +#endif QT_BEGIN_NAMESPACE @@ -83,6 +85,9 @@ public: QCheckBox * again; QTextEdit * errors; QLabel * icon; +#ifdef QT_SOFTKEYS_ENABLED + QAction *okAction; +#endif QQueue > pending; QSet doNotShow; QSet doNotShowType; @@ -91,7 +96,6 @@ public: bool nextPending(); void retranslateStrings(); - void enableSoftKey(bool enable); }; class QErrorMessageTextView : public QTextEdit @@ -241,6 +245,12 @@ QErrorMessage::QErrorMessage(QWidget * parent) Q_D(QErrorMessage); QGridLayout * grid = new QGridLayout(this); d->icon = new QLabel(this); +#ifdef QT_SOFTKEYS_ENABLED + d->okAction = new QAction(this); + d->okAction->setSoftKeyRole(QAction::OkSoftKey); + connect(d->okAction, SIGNAL(triggered()), this, SLOT(accept())); + addAction(d->okAction); +#endif #ifndef QT_NO_MESSAGEBOX d->icon->setPixmap(QMessageBox::standardIcon(QMessageBox::Information)); d->icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop); @@ -286,7 +296,6 @@ QErrorMessage::~QErrorMessage() void QErrorMessage::done(int a) { Q_D(QErrorMessage); - d->enableSoftKey(false); if (!d->again->isChecked() && !d->currentMessage.isEmpty() && d->currentType.isEmpty()) { d->doNotShow.insert(d->currentMessage); } @@ -361,10 +370,6 @@ void QErrorMessage::showMessage(const QString &message) d->pending.enqueue(qMakePair(message,QString())); if (!isVisible() && d->nextPending()) show(); - -#ifdef Q_WS_S60 - d->enableSoftKey(true); -#endif } /*! @@ -389,31 +394,8 @@ void QErrorMessage::showMessage(const QString &message, const QString &type) d->pending.push_back(qMakePair(message,type)); if (!isVisible() && d->nextPending()) show(); - -#ifdef Q_WS_S60 - d->enableSoftKey(true); -#endif } -/*! \internal */ -void QErrorMessagePrivate::enableSoftKey(bool enable) -{ -#ifdef Q_WS_S60 - Q_Q(QErrorMessage); - if (enable) { - QAction *okAction = new QAction(ok->text(), q); - okAction->setSoftKeyRole(QAction::OkSoftKey); - QObject::connect(okAction, SIGNAL(triggered()), q, SLOT(accept())); - q->setSoftKey(okAction); - } else { - q->setSoftKey(0); - } -#else - Q_UNUSED(enable); -#endif -} - - /*! \reimp */ @@ -430,6 +412,9 @@ void QErrorMessagePrivate::retranslateStrings() { again->setText(QErrorMessage::tr("&Show this message again")); ok->setText(QErrorMessage::tr("&OK")); +#ifdef QT_SOFTKEYS_ENABLED + okAction->setText(ok->text()); +#endif } /*! -- cgit v0.12