diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qplatformdialoghelper.cpp | 42 | ||||
-rw-r--r-- | src/gui/kernel/qplatformdialoghelper.h | 20 | ||||
-rw-r--r-- | src/widgets/widgets/qdialogbuttonbox.cpp | 43 |
3 files changed, 64 insertions, 41 deletions
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index fe5db27117..5ddd718e69 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -693,6 +693,48 @@ QMessageDialogOptions::StandardButtons QMessageDialogOptions::standardButtons() return d->buttons; } +QMessageDialogOptions::ButtonRole QMessageDialogOptions::buttonRole(QMessageDialogOptions::StandardButton button) +{ + switch (button) { + case Ok: + case Save: + case Open: + case SaveAll: + case Retry: + case Ignore: + return AcceptRole; + + case Cancel: + case Close: + case Abort: + return RejectRole; + + case Discard: + return DestructiveRole; + + case Help: + return HelpRole; + + case Apply: + return ApplyRole; + + case Yes: + case YesToAll: + return YesRole; + + case No: + case NoToAll: + return NoRole; + + case RestoreDefaults: + case Reset: + return ResetRole; + + default: + break; + } + return InvalidRole; +} /*! \class QPlatformMessageDialogHelper diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index ad818c8644..eb461e3ab3 100644 --- a/src/gui/kernel/qplatformdialoghelper.h +++ b/src/gui/kernel/qplatformdialoghelper.h @@ -361,6 +361,21 @@ public: Q_DECLARE_FLAGS(StandardButtons, StandardButton) + enum ButtonRole { + InvalidRole = -1, + AcceptRole, + RejectRole, + DestructiveRole, + ActionRole, + HelpRole, + YesRole, + NoRole, + ResetRole, + ApplyRole, + + NRoles + }; + QMessageDialogOptions(); QMessageDialogOptions(const QMessageDialogOptions &rhs); QMessageDialogOptions &operator=(const QMessageDialogOptions &rhs); @@ -386,6 +401,8 @@ public: void setStandardButtons(StandardButtons buttons); StandardButtons standardButtons() const; + static ButtonRole buttonRole(StandardButton button); + private: QSharedDataPointer<QMessageDialogOptionsPrivate> d; }; @@ -400,7 +417,8 @@ public: void setOptions(const QSharedPointer<QMessageDialogOptions> &options); Q_SIGNALS: - void clicked(QMessageDialogOptions::StandardButton button); + void clicked(QMessageDialogOptions::StandardButton button); // TODO remove before 5.2 + void clicked(QMessageDialogOptions::StandardButton button, QMessageDialogOptions::ButtonRole role); private: QSharedPointer<QMessageDialogOptions> m_options; diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 9789c453f3..6b183d3759 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -46,6 +46,7 @@ #include <QtWidgets/qdialog.h> #include <QtWidgets/qapplication.h> #include <private/qwidget_p.h> +#include <QtGui/qpa/qplatformdialoghelper.h> #include <QtWidgets/qaction.h> #include "qdialogbuttonbox.h" @@ -166,46 +167,8 @@ enum { static QDialogButtonBox::ButtonRole roleFor(QDialogButtonBox::StandardButton button) { - switch (button) { - case QDialogButtonBox::Ok: - case QDialogButtonBox::Save: - case QDialogButtonBox::Open: - case QDialogButtonBox::SaveAll: - case QDialogButtonBox::Retry: - case QDialogButtonBox::Ignore: - return QDialogButtonBox::AcceptRole; - - case QDialogButtonBox::Cancel: - case QDialogButtonBox::Close: - case QDialogButtonBox::Abort: - return QDialogButtonBox::RejectRole; - - case QDialogButtonBox::Discard: - return QDialogButtonBox::DestructiveRole; - - case QDialogButtonBox::Help: - return QDialogButtonBox::HelpRole; - - case QDialogButtonBox::Apply: - return QDialogButtonBox::ApplyRole; - - case QDialogButtonBox::Yes: - case QDialogButtonBox::YesToAll: - return QDialogButtonBox::YesRole; - - case QDialogButtonBox::No: - case QDialogButtonBox::NoToAll: - return QDialogButtonBox::NoRole; - - case QDialogButtonBox::RestoreDefaults: - case QDialogButtonBox::Reset: - return QDialogButtonBox::ResetRole; - - case QDialogButtonBox::NoButton: // NoButton means zero buttons, not "No" button - ; - } - - return QDialogButtonBox::InvalidRole; + return static_cast<QDialogButtonBox::ButtonRole>(QMessageDialogOptions::buttonRole( + static_cast<QMessageDialogOptions::StandardButton>(button))); } static const uint layouts[2][5][14] = |