From 760a771fce3758fe34b1f3ce8a22f283bb24b326 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 7 Feb 2014 14:04:37 +0100 Subject: Consolidate StandardButton, ButtonRole and related static functions Moving them into QPlatformDialogHelper for the convenience of both widgets and QtQuick.Dialogs. The main reason is to ensure that QtQuick.Dialogs does not need to depend on the widgets module, in order to re-implement the button box concept in a generic dialog. Change-Id: If400d215338d7cb6dade39d9de60e50b5e7515ef Reviewed-by: Friedemann Kleint --- src/gui/kernel/qplatformdialoghelper.cpp | 88 +++++++++++++++++++++-- src/gui/kernel/qplatformdialoghelper.h | 120 ++++++++++++++++++------------- src/gui/kernel/qplatformtheme.cpp | 38 +++++----- 3 files changed, 173 insertions(+), 73 deletions(-) (limited to 'src/gui') diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index 5ddd718e69..c119b90001 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -62,6 +62,70 @@ QT_BEGIN_NAMESPACE */ +static const quint32 buttonRoleLayouts[2][5][14] = +{ + // Qt::Horizontal + { + // WinLayout + { QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::YesRole, QPlatformDialogHelper::AcceptRole, + QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::NoRole, + QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::RejectRole, QPlatformDialogHelper::ApplyRole, + QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }, + + // MacLayout + { QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole, + QPlatformDialogHelper::Stretch, QPlatformDialogHelper::DestructiveRole | QPlatformDialogHelper::Reverse, + QPlatformDialogHelper::AlternateRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::RejectRole | QPlatformDialogHelper::Reverse, + QPlatformDialogHelper::AcceptRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::NoRole | QPlatformDialogHelper::Reverse, + QPlatformDialogHelper::YesRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }, + + // KdeLayout + { QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::YesRole, + QPlatformDialogHelper::NoRole, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::AlternateRole, + QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::RejectRole, QPlatformDialogHelper::EOL }, + + // GnomeLayout + { QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::ActionRole, + QPlatformDialogHelper::ApplyRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::DestructiveRole | QPlatformDialogHelper::Reverse, + QPlatformDialogHelper::AlternateRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::RejectRole | QPlatformDialogHelper::Reverse, + QPlatformDialogHelper::AcceptRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::NoRole | QPlatformDialogHelper::Reverse, + QPlatformDialogHelper::YesRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::EOL }, + + // MacModelessLayout + { QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::Stretch, + QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, + QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL } + }, + + // Qt::Vertical + { + // WinLayout + { QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::YesRole, QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::AlternateRole, + QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::NoRole, QPlatformDialogHelper::RejectRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ResetRole, + QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }, + + // MacLayout + { QPlatformDialogHelper::YesRole, QPlatformDialogHelper::NoRole, QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::RejectRole, + QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::ApplyRole, + QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }, + + // KdeLayout + { QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole, + QPlatformDialogHelper::YesRole, QPlatformDialogHelper::NoRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::ResetRole, + QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::RejectRole, QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL }, + + // GnomeLayout + { QPlatformDialogHelper::YesRole, QPlatformDialogHelper::NoRole, QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::RejectRole, + QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::Stretch, + QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }, + + // MacModelessLayout + { QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch, + QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, + QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL } + } +}; + QPlatformDialogHelper::QPlatformDialogHelper() { } @@ -603,7 +667,7 @@ class QMessageDialogOptionsPrivate : public QSharedData public: QMessageDialogOptionsPrivate() : icon(QMessageDialogOptions::NoIcon), - buttons(QMessageDialogOptions::Ok) + buttons(QPlatformDialogHelper::Ok) {} QString windowTitle; @@ -611,7 +675,7 @@ public: QString text; QString informativeText; QString detailedText; - QMessageDialogOptions::StandardButtons buttons; + QPlatformDialogHelper::StandardButtons buttons; }; QMessageDialogOptions::QMessageDialogOptions() : d(new QMessageDialogOptionsPrivate) @@ -683,17 +747,17 @@ void QMessageDialogOptions::setDetailedText(const QString &detailedText) d->detailedText = detailedText; } -void QMessageDialogOptions::setStandardButtons(StandardButtons buttons) +void QMessageDialogOptions::setStandardButtons(QPlatformDialogHelper::StandardButtons buttons) { d->buttons = buttons; } -QMessageDialogOptions::StandardButtons QMessageDialogOptions::standardButtons() const +QPlatformDialogHelper::StandardButtons QMessageDialogOptions::standardButtons() const { return d->buttons; } -QMessageDialogOptions::ButtonRole QMessageDialogOptions::buttonRole(QMessageDialogOptions::StandardButton button) +QPlatformDialogHelper::ButtonRole QPlatformDialogHelper::buttonRole(QPlatformDialogHelper::StandardButton button) { switch (button) { case Ok: @@ -736,6 +800,20 @@ QMessageDialogOptions::ButtonRole QMessageDialogOptions::buttonRole(QMessageDial return InvalidRole; } +const quint32 *QPlatformDialogHelper::buttonLayout(Qt::Orientation orientation, ButtonLayout policy) +{ + if (policy == UnknownLayout) { +#if defined (Q_OS_OSX) + policy = MacLayout; +#elif defined (Q_OS_LINUX) || defined (Q_OS_UNIX) + policy = KdeLayout; +#else + policy = WinLayout; +#endif + } + return buttonRoleLayouts[orientation == Qt::Vertical][policy]; +} + /*! \class QPlatformMessageDialogHelper \since 5.0 diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index 9eeb0a6da4..87fac83d50 100644 --- a/src/gui/kernel/qplatformdialoghelper.h +++ b/src/gui/kernel/qplatformdialoghelper.h @@ -82,6 +82,71 @@ public: }; enum DialogCode { Rejected, Accepted }; + enum StandardButton { + // keep this in sync with QDialogButtonBox::StandardButton and QMessageBox::StandardButton + NoButton = 0x00000000, + Ok = 0x00000400, + Save = 0x00000800, + SaveAll = 0x00001000, + Open = 0x00002000, + Yes = 0x00004000, + YesToAll = 0x00008000, + No = 0x00010000, + NoToAll = 0x00020000, + Abort = 0x00040000, + Retry = 0x00080000, + Ignore = 0x00100000, + Close = 0x00200000, + Cancel = 0x00400000, + Discard = 0x00800000, + Help = 0x01000000, + Apply = 0x02000000, + Reset = 0x04000000, + RestoreDefaults = 0x08000000, + + + FirstButton = Ok, // internal + LastButton = RestoreDefaults, // internal + LowestBit = 10, // internal: log2(FirstButton) + HighestBit = 27 // internal: log2(LastButton) + }; + + Q_DECLARE_FLAGS(StandardButtons, StandardButton) + + enum ButtonRole { + // keep this in sync with QDialogButtonBox::ButtonRole and QMessageBox::ButtonRole + // TODO Qt 6: make the enum copies explicit, and make InvalidRole == 0 so that + // AcceptRole can be or'ed with flags, and EOL can be the same as InvalidRole (null-termination) + InvalidRole = -1, + AcceptRole, + RejectRole, + DestructiveRole, + ActionRole, + HelpRole, + YesRole, + NoRole, + ResetRole, + ApplyRole, + + NRoles, + + RoleMask = 0x0FFFFFFF, + AlternateRole = 0x10000000, + Stretch = 0x20000000, + EOL = 0x40000000, + Reverse = 0x80000000 + }; + + enum ButtonLayout { + // keep this in sync with QDialogButtonBox::ButtonLayout and QMessageBox::ButtonLayout + UnknownLayout = -1, + WinLayout, + MacLayout, + KdeLayout, + GnomeLayout, + MacModelessLayout + }; + QPlatformDialogHelper(); virtual ~QPlatformDialogHelper(); @@ -95,6 +160,9 @@ public: static QVariant defaultStyleHint(QPlatformDialogHelper::StyleHint hint); + static const quint32 *buttonLayout(Qt::Orientation orientation = Qt::Horizontal, ButtonLayout policy = UnknownLayout); + static ButtonRole buttonRole(StandardButton button); + Q_SIGNALS: void accept(); void reject(); @@ -332,50 +400,6 @@ public: // Keep in sync with QMessageBox::Icon enum Icon { NoIcon, Information, Warning, Critical, Question }; - enum StandardButton { - // keep this in sync with QDialogButtonBox::StandardButton and QMessageBox::StandardButton - NoButton = 0x00000000, - Ok = 0x00000400, - Save = 0x00000800, - SaveAll = 0x00001000, - Open = 0x00002000, - Yes = 0x00004000, - YesToAll = 0x00008000, - No = 0x00010000, - NoToAll = 0x00020000, - Abort = 0x00040000, - Retry = 0x00080000, - Ignore = 0x00100000, - Close = 0x00200000, - Cancel = 0x00400000, - Discard = 0x00800000, - Help = 0x01000000, - Apply = 0x02000000, - Reset = 0x04000000, - RestoreDefaults = 0x08000000, - - - FirstButton = Ok, // internal - LastButton = RestoreDefaults // internal - }; - - 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); @@ -398,10 +422,8 @@ public: void setDetailedText(const QString &text); QString detailedText() const; - void setStandardButtons(StandardButtons buttons); - StandardButtons standardButtons() const; - - static ButtonRole buttonRole(StandardButton button); + void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons); + QPlatformDialogHelper::StandardButtons standardButtons() const; private: QSharedDataPointer d; @@ -417,7 +439,7 @@ public: void setOptions(const QSharedPointer &options); Q_SIGNALS: - void clicked(QMessageDialogOptions::StandardButton button, QMessageDialogOptions::ButtonRole role); + void clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role); private: QSharedPointer m_options; diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 90edf4c49f..e12eb318dc 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -632,7 +632,7 @@ QList QPlatformTheme::keyBindings(QKeySequence::StandardKey key) c Returns the text of a standard \a button. \since 5.3 - \sa QMessageDialogOptions::StandardButton + \sa QPlatformDialogHelper::StandardButton */ QString QPlatformTheme::standardButtonText(int button) const @@ -643,41 +643,41 @@ QString QPlatformTheme::standardButtonText(int button) const QString QPlatformTheme::defaultStandardButtonText(int button) { switch (button) { - case QMessageDialogOptions::Ok: + case QPlatformDialogHelper::Ok: return QCoreApplication::translate("QPlatformTheme", "OK"); - case QMessageDialogOptions::Save: + case QPlatformDialogHelper::Save: return QCoreApplication::translate("QPlatformTheme", "Save"); - case QMessageDialogOptions::SaveAll: + case QPlatformDialogHelper::SaveAll: return QCoreApplication::translate("QPlatformTheme", "Save All"); - case QMessageDialogOptions::Open: + case QPlatformDialogHelper::Open: return QCoreApplication::translate("QPlatformTheme", "Open"); - case QMessageDialogOptions::Yes: + case QPlatformDialogHelper::Yes: return QCoreApplication::translate("QPlatformTheme", "&Yes"); - case QMessageDialogOptions::YesToAll: + case QPlatformDialogHelper::YesToAll: return QCoreApplication::translate("QPlatformTheme", "Yes to &All"); - case QMessageDialogOptions::No: + case QPlatformDialogHelper::No: return QCoreApplication::translate("QPlatformTheme", "&No"); - case QMessageDialogOptions::NoToAll: + case QPlatformDialogHelper::NoToAll: return QCoreApplication::translate("QPlatformTheme", "N&o to All"); - case QMessageDialogOptions::Abort: + case QPlatformDialogHelper::Abort: return QCoreApplication::translate("QPlatformTheme", "Abort"); - case QMessageDialogOptions::Retry: + case QPlatformDialogHelper::Retry: return QCoreApplication::translate("QPlatformTheme", "Retry"); - case QMessageDialogOptions::Ignore: + case QPlatformDialogHelper::Ignore: return QCoreApplication::translate("QPlatformTheme", "Ignore"); - case QMessageDialogOptions::Close: + case QPlatformDialogHelper::Close: return QCoreApplication::translate("QPlatformTheme", "Close"); - case QMessageDialogOptions::Cancel: + case QPlatformDialogHelper::Cancel: return QCoreApplication::translate("QPlatformTheme", "Cancel"); - case QMessageDialogOptions::Discard: + case QPlatformDialogHelper::Discard: return QCoreApplication::translate("QPlatformTheme", "Discard"); - case QMessageDialogOptions::Help: + case QPlatformDialogHelper::Help: return QCoreApplication::translate("QPlatformTheme", "Help"); - case QMessageDialogOptions::Apply: + case QPlatformDialogHelper::Apply: return QCoreApplication::translate("QPlatformTheme", "Apply"); - case QMessageDialogOptions::Reset: + case QPlatformDialogHelper::Reset: return QCoreApplication::translate("QPlatformTheme", "Reset"); - case QMessageDialogOptions::RestoreDefaults: + case QPlatformDialogHelper::RestoreDefaults: return QCoreApplication::translate("QPlatformTheme", "Restore Defaults"); default: break; -- cgit v1.2.3