From 8aab8ccc0ffba504078deb7b4371d2f98c834df3 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 7 Nov 2013 13:43:02 +0100 Subject: Dialogs: provide the StandardButton->ButtonRole mapping in QPA As the QPlatformMessageDialogHelper will be implemented repeatedly, it's useful to have this mapping in one place for reuse. Also, since we do not guarantee that either accepted() or rejected() will be emitted for every possible button on a QtQuick MessageDialog, it's useful for the QtQuick.Dialogs module to have access to this mapping to interpret individual button presses and emit the role-specific signals such as yes(), apply(), help(), etc. Change-Id: I7be753080794adabb784df9b95ac04aa1c29151c Reviewed-by: BogDan Vatra --- src/gui/kernel/qplatformdialoghelper.cpp | 42 ++++++++++++++++++++++++++++++++ src/gui/kernel/qplatformdialoghelper.h | 20 ++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) (limited to 'src/gui') 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 d; }; @@ -400,7 +417,8 @@ public: void setOptions(const QSharedPointer &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 m_options; -- cgit v1.2.3