diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2014-02-07 14:04:37 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-15 10:43:20 +0100 |
commit | 760a771fce3758fe34b1f3ce8a22f283bb24b326 (patch) | |
tree | facfdedcfe17c21c8ae2de061ea79f6ff60f3fe1 /src/widgets | |
parent | f8dbed12266c42785c1e4758eed05833ec035f33 (diff) |
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 <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 12 | ||||
-rw-r--r-- | src/widgets/dialogs/qmessagebox.h | 7 | ||||
-rw-r--r-- | src/widgets/widgets/qdialogbuttonbox.cpp | 122 | ||||
-rw-r--r-- | src/widgets/widgets/qdialogbuttonbox.h | 5 |
4 files changed, 40 insertions, 106 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 1b64b0ba67..3080d5f1e8 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -209,7 +209,7 @@ public: void init(const QString &title = QString(), const QString &text = QString()); void setupLayout(); void _q_buttonClicked(QAbstractButton *); - void _q_clicked(QMessageDialogOptions::StandardButton button, QMessageDialogOptions::ButtonRole role); + void _q_clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role); QAbstractButton *findButton(int button0, int button1, int button2, int flags); void addOldButtons(int button0, int button1, int button2); @@ -524,7 +524,7 @@ void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button) } } -void QMessageBoxPrivate::_q_clicked(QMessageDialogOptions::StandardButton button, QMessageDialogOptions::ButtonRole role) +void QMessageBoxPrivate::_q_clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role) { Q_UNUSED(role); Q_Q(QMessageBox); @@ -2697,8 +2697,8 @@ QPixmap QMessageBoxPrivate::standardIcon(QMessageBox::Icon icon, QMessageBox *mb void QMessageBoxPrivate::initHelper(QPlatformDialogHelper *h) { Q_Q(QMessageBox); - QObject::connect(h, SIGNAL(clicked(QMessageDialogOptions::StandardButton, QMessageDialogOptions::ButtonRole)), - q, SLOT(_q_clicked(QMessageDialogOptions::StandardButton, QMessageDialogOptions::ButtonRole))); + QObject::connect(h, SIGNAL(clicked(QPlatformDialogHelper::StandardButton, QPlatformDialogHelper::ButtonRole)), + q, SLOT(_q_clicked(QPlatformDialogHelper::StandardButton, QPlatformDialogHelper::ButtonRole))); static_cast<QPlatformMessageDialogHelper *>(h)->setOptions(options); } @@ -2719,9 +2719,9 @@ static QMessageDialogOptions::Icon helperIcon(QMessageBox::Icon i) return QMessageDialogOptions::NoIcon; } -static QMessageDialogOptions::StandardButtons helperStandardButtons(QMessageBox * q) +static QPlatformDialogHelper::StandardButtons helperStandardButtons(QMessageBox * q) { - QMessageDialogOptions::StandardButtons buttons(int(q->standardButtons())); + QPlatformDialogHelper::StandardButtons buttons(int(q->standardButtons())); return buttons; } diff --git a/src/widgets/dialogs/qmessagebox.h b/src/widgets/dialogs/qmessagebox.h index c5598a8f1d..5fae174fe1 100644 --- a/src/widgets/dialogs/qmessagebox.h +++ b/src/widgets/dialogs/qmessagebox.h @@ -72,6 +72,7 @@ class Q_WIDGETS_EXPORT QMessageBox : public QDialog public: enum Icon { + // keep this in sync with QMessageDialogOptions::Icon NoIcon = 0, Information = 1, Warning = 2, @@ -80,7 +81,7 @@ public: }; enum ButtonRole { - // keep this in sync with QDialogButtonBox::ButtonRole + // keep this in sync with QDialogButtonBox::ButtonRole and QPlatformDialogHelper::ButtonRole InvalidRole = -1, AcceptRole, RejectRole, @@ -96,7 +97,7 @@ public: }; enum StandardButton { - // keep this in sync with QDialogButtonBox::StandardButton and QMessageDialogOptions::StandardButton + // keep this in sync with QDialogButtonBox::StandardButton and QPlatformDialogHelper::StandardButton NoButton = 0x00000000, Ok = 0x00000400, Save = 0x00000800, @@ -309,7 +310,7 @@ protected: private: Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked(QAbstractButton *)) - Q_PRIVATE_SLOT(d_func(), void _q_clicked(QMessageDialogOptions::StandardButton, QMessageDialogOptions::ButtonRole)) + Q_PRIVATE_SLOT(d_func(), void _q_clicked(QPlatformDialogHelper::StandardButton, QPlatformDialogHelper::ButtonRole)) Q_DISABLE_COPY(QMessageBox) Q_DECLARE_PRIVATE(QMessageBox) diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index d28fb66551..e24247b02f 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -150,77 +150,6 @@ QT_BEGIN_NAMESPACE \sa QMessageBox, QPushButton, QDialog */ -enum { - AcceptRole = QDialogButtonBox::AcceptRole, - RejectRole = QDialogButtonBox::RejectRole, - DestructiveRole = QDialogButtonBox::DestructiveRole, - ActionRole = QDialogButtonBox::ActionRole, - HelpRole = QDialogButtonBox::HelpRole, - YesRole = QDialogButtonBox::YesRole, - NoRole = QDialogButtonBox::NoRole, - ApplyRole = QDialogButtonBox::ApplyRole, - ResetRole = QDialogButtonBox::ResetRole, - - AlternateRole = 0x10000000, - Stretch = 0x20000000, - EOL = 0x40000000, - Reverse = 0x80000000 -}; - -static QDialogButtonBox::ButtonRole roleFor(QDialogButtonBox::StandardButton button) -{ - return static_cast<QDialogButtonBox::ButtonRole>(QMessageDialogOptions::buttonRole( - static_cast<QMessageDialogOptions::StandardButton>(button))); -} - -static const uint layouts[2][5][14] = -{ - // Qt::Horizontal - { - // WinLayout - { ResetRole, Stretch, YesRole, AcceptRole, AlternateRole, DestructiveRole, NoRole, ActionRole, RejectRole, ApplyRole, - HelpRole, EOL, EOL, EOL }, - - // MacLayout - { HelpRole, ResetRole, ApplyRole, ActionRole, Stretch, DestructiveRole | Reverse, - AlternateRole | Reverse, RejectRole | Reverse, AcceptRole | Reverse, NoRole | Reverse, YesRole | Reverse, EOL, EOL }, - - // KdeLayout - { HelpRole, ResetRole, Stretch, YesRole, NoRole, ActionRole, AcceptRole, AlternateRole, - ApplyRole, DestructiveRole, RejectRole, EOL }, - - // GnomeLayout - { HelpRole, ResetRole, Stretch, ActionRole, ApplyRole | Reverse, DestructiveRole | Reverse, - AlternateRole | Reverse, RejectRole | Reverse, AcceptRole | Reverse, NoRole | Reverse, YesRole | Reverse, EOL }, - - // Mac modeless - { ResetRole, ApplyRole, ActionRole, Stretch, HelpRole, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL } - }, - - // Qt::Vertical - { - // WinLayout - { ActionRole, YesRole, AcceptRole, AlternateRole, DestructiveRole, NoRole, RejectRole, ApplyRole, ResetRole, - HelpRole, Stretch, EOL, EOL, EOL }, - - // MacLayout - { YesRole, NoRole, AcceptRole, RejectRole, AlternateRole, DestructiveRole, Stretch, ActionRole, ApplyRole, - ResetRole, HelpRole, EOL, EOL }, - - // KdeLayout - { AcceptRole, AlternateRole, ApplyRole, ActionRole, YesRole, NoRole, Stretch, ResetRole, - DestructiveRole, RejectRole, HelpRole, EOL }, - - // GnomeLayout - { YesRole, NoRole, AcceptRole, RejectRole, AlternateRole, DestructiveRole, ApplyRole, ActionRole, Stretch, - ResetRole, HelpRole, EOL, EOL, EOL }, - - // Mac modeless - { ActionRole, ApplyRole, ResetRole, Stretch, HelpRole, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL } - } -}; - - class QDialogButtonBoxPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QDialogButtonBox) @@ -323,7 +252,8 @@ void QDialogButtonBoxPrivate::layoutButtons() int tmpPolicy = layoutPolicy; static const int M = 5; - static const int ModalRoles[M] = { AcceptRole, RejectRole, DestructiveRole, YesRole, NoRole }; + static const int ModalRoles[M] = { QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::RejectRole, + QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::YesRole, QPlatformDialogHelper::NoRole }; if (tmpPolicy == QDialogButtonBox::MacLayout) { bool hasModalButton = false; for (int i = 0; i < M; ++i) { @@ -336,23 +266,24 @@ void QDialogButtonBoxPrivate::layoutButtons() tmpPolicy = 4; // Mac modeless } - const uint *currentLayout = layouts[orientation == Qt::Vertical][tmpPolicy]; + const quint32 *currentLayout = QPlatformDialogHelper::buttonLayout( + orientation, static_cast<QPlatformDialogHelper::ButtonLayout>(tmpPolicy)); if (center) buttonLayout->addStretch(); - QList<QAbstractButton *> acceptRoleList = buttonLists[AcceptRole]; + QList<QAbstractButton *> acceptRoleList = buttonLists[QPlatformDialogHelper::AcceptRole]; - while (*currentLayout != EOL) { - int role = (*currentLayout & ~Reverse); - bool reverse = (*currentLayout & Reverse); + while (*currentLayout != QPlatformDialogHelper::EOL) { + int role = (*currentLayout & ~QPlatformDialogHelper::Reverse); + bool reverse = (*currentLayout & QPlatformDialogHelper::Reverse); switch (role) { - case Stretch: + case QPlatformDialogHelper::Stretch: if (!center) buttonLayout->addStretch(); break; - case AcceptRole: { + case QPlatformDialogHelper::AcceptRole: { if (acceptRoleList.isEmpty()) break; // Only the first one @@ -361,7 +292,7 @@ void QDialogButtonBoxPrivate::layoutButtons() button->show(); } break; - case AlternateRole: + case QPlatformDialogHelper::AlternateRole: { if (acceptRoleList.size() < 2) break; @@ -370,7 +301,7 @@ void QDialogButtonBoxPrivate::layoutButtons() addButtonsToLayout(list, reverse); } break; - case DestructiveRole: + case QPlatformDialogHelper::DestructiveRole: { const QList<QAbstractButton *> &list = buttonLists[role]; @@ -396,13 +327,13 @@ void QDialogButtonBoxPrivate::layoutButtons() buttonLayout->addSpacing(MacGap); } break; - case RejectRole: - case ActionRole: - case HelpRole: - case YesRole: - case NoRole: - case ApplyRole: - case ResetRole: + case QPlatformDialogHelper::RejectRole: + case QPlatformDialogHelper::ActionRole: + case QPlatformDialogHelper::HelpRole: + case QPlatformDialogHelper::YesRole: + case QPlatformDialogHelper::NoRole: + case QPlatformDialogHelper::ApplyRole: + case QPlatformDialogHelper::ResetRole: addButtonsToLayout(buttonLists[role], reverse); } ++currentLayout; @@ -484,8 +415,9 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut if (style != QApplication::style()) // Propagate style button->setStyle(style); standardButtonHash.insert(button, sbutton); - if (roleFor(sbutton) != QDialogButtonBox::InvalidRole) { - addButton(button, roleFor(sbutton), doLayout); + QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::buttonRole(static_cast<QPlatformDialogHelper::StandardButton>(sbutton)); + if (role != QPlatformDialogHelper::InvalidRole) { + addButton(button, static_cast<QDialogButtonBox::ButtonRole>(role), doLayout); } else { qWarning("QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); } @@ -934,15 +866,15 @@ void QDialogButtonBoxPrivate::_q_handleButtonClicked() emit q->clicked(button); switch (q->buttonRole(button)) { - case AcceptRole: - case YesRole: + case QPlatformDialogHelper::AcceptRole: + case QPlatformDialogHelper::YesRole: emit q->accepted(); break; - case RejectRole: - case NoRole: + case QPlatformDialogHelper::RejectRole: + case QPlatformDialogHelper::NoRole: emit q->rejected(); break; - case HelpRole: + case QPlatformDialogHelper::HelpRole: emit q->helpRequested(); break; default: diff --git a/src/widgets/widgets/qdialogbuttonbox.h b/src/widgets/widgets/qdialogbuttonbox.h index d8e1a997d4..5cd94f88b0 100644 --- a/src/widgets/widgets/qdialogbuttonbox.h +++ b/src/widgets/widgets/qdialogbuttonbox.h @@ -61,7 +61,7 @@ class Q_WIDGETS_EXPORT QDialogButtonBox : public QWidget public: enum ButtonRole { - // keep this in sync with QMessageBox::ButtonRole + // keep this in sync with QMessageBox::ButtonRole and QPlatformDialogHelper::ButtonRole InvalidRole = -1, AcceptRole, RejectRole, @@ -77,7 +77,7 @@ public: }; enum StandardButton { - // keep this in sync with QMessageBox::StandardButton + // keep this in sync with QMessageBox::StandardButton and QPlatformDialogHelper::StandardButton NoButton = 0x00000000, Ok = 0x00000400, Save = 0x00000800, @@ -107,6 +107,7 @@ public: Q_DECLARE_FLAGS(StandardButtons, StandardButton) enum ButtonLayout { + // keep this in sync with QMessageBox::ButtonLayout and QPlatformDialogHelper::ButtonLayout WinLayout, MacLayout, KdeLayout, |