summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qdialogbuttonbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qdialogbuttonbox.cpp')
-rw-r--r--src/widgets/widgets/qdialogbuttonbox.cpp216
1 files changed, 37 insertions, 179 deletions
diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp
index 6b183d3759..e24247b02f 100644
--- a/src/widgets/widgets/qdialogbuttonbox.cpp
+++ b/src/widgets/widgets/qdialogbuttonbox.cpp
@@ -46,7 +46,9 @@
#include <QtWidgets/qdialog.h>
#include <QtWidgets/qapplication.h>
#include <private/qwidget_p.h>
+#include <private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformdialoghelper.h>
+#include <QtGui/qpa/qplatformtheme.h>
#include <QtWidgets/qaction.h>
#include "qdialogbuttonbox.h"
@@ -148,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)
@@ -246,7 +177,6 @@ public:
void _q_handleButtonClicked();
void addButtonsToLayout(const QList<QAbstractButton *> &buttonList, bool reverse);
void retranslateStrings();
- const char *standardButtonText(QDialogButtonBox::StandardButton sbutton) const;
};
QDialogButtonBoxPrivate::QDialogButtonBoxPrivate(Qt::Orientation orient)
@@ -322,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) {
@@ -335,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
@@ -360,7 +292,7 @@ void QDialogButtonBoxPrivate::layoutButtons()
button->show();
}
break;
- case AlternateRole:
+ case QPlatformDialogHelper::AlternateRole:
{
if (acceptRoleList.size() < 2)
break;
@@ -369,7 +301,7 @@ void QDialogButtonBoxPrivate::layoutButtons()
addButtonsToLayout(list, reverse);
}
break;
- case DestructiveRole:
+ case QPlatformDialogHelper::DestructiveRole:
{
const QList<QAbstractButton *> &list = buttonLists[role];
@@ -395,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;
@@ -428,7 +360,6 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut
bool doLayout)
{
Q_Q(QDialogButtonBox);
- const char *buttonText = 0;
int icon = 0;
switch (sbutton) {
@@ -477,17 +408,16 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut
return 0;
;
}
- buttonText = standardButtonText(sbutton);
-
- QPushButton *button = new QPushButton(QDialogButtonBox::tr(buttonText), q);
+ QPushButton *button = new QPushButton(QGuiApplicationPrivate::platformTheme()->standardButtonText(sbutton), q);
QStyle *style = q->style();
if (style->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q) && icon != 0)
button->setIcon(style->standardIcon(QStyle::StandardPixmap(icon), 0, q));
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");
}
@@ -525,87 +455,15 @@ void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardBu
layoutButtons();
}
-const char *QDialogButtonBoxPrivate::standardButtonText(QDialogButtonBox::StandardButton sbutton) const
-{
- const char *buttonText = 0;
- bool gnomeLayout = (layoutPolicy == QDialogButtonBox::GnomeLayout);
- switch (sbutton) {
- case QDialogButtonBox::Ok:
- buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&OK") : QT_TRANSLATE_NOOP("QDialogButtonBox", "OK");
- break;
- case QDialogButtonBox::Save:
- buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&Save") : QT_TRANSLATE_NOOP("QDialogButtonBox", "Save");
- break;
- case QDialogButtonBox::Open:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Open");
- break;
- case QDialogButtonBox::Cancel:
- buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&Cancel") : QT_TRANSLATE_NOOP("QDialogButtonBox", "Cancel");
- break;
- case QDialogButtonBox::Close:
- buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&Close") : QT_TRANSLATE_NOOP("QDialogButtonBox", "Close");
- break;
- case QDialogButtonBox::Apply:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Apply");
- break;
- case QDialogButtonBox::Reset:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Reset");
- break;
- case QDialogButtonBox::Help:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Help");
- break;
- case QDialogButtonBox::Discard:
- if (layoutPolicy == QDialogButtonBox::MacLayout)
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Don't Save");
- else if (layoutPolicy == QDialogButtonBox::GnomeLayout)
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Close without Saving");
- else
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Discard");
- break;
- case QDialogButtonBox::Yes:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "&Yes");
- break;
- case QDialogButtonBox::YesToAll:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Yes to &All");
- break;
- case QDialogButtonBox::No:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "&No");
- break;
- case QDialogButtonBox::NoToAll:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "N&o to All");
- break;
- case QDialogButtonBox::SaveAll:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Save All");
- break;
- case QDialogButtonBox::Abort:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Abort");
- break;
- case QDialogButtonBox::Retry:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Retry");
- break;
- case QDialogButtonBox::Ignore:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Ignore");
- break;
- case QDialogButtonBox::RestoreDefaults:
- buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Restore Defaults");
- break;
- case QDialogButtonBox::NoButton:
- ;
- } // switch
- return buttonText;
-}
-
void QDialogButtonBoxPrivate::retranslateStrings()
{
- const char *buttonText = 0;
- QHash<QPushButton *, QDialogButtonBox::StandardButton>::iterator it = standardButtonHash.begin();
- while (it != standardButtonHash.end()) {
- buttonText = standardButtonText(it.value());
- if (buttonText) {
- QPushButton *button = it.key();
- button->setText(QDialogButtonBox::tr(buttonText));
- }
- ++it;
+ typedef QHash<QPushButton *, QDialogButtonBox::StandardButton>::iterator Iterator;
+
+ const Iterator end = standardButtonHash.end();
+ for (Iterator it = standardButtonHash.begin(); it != end; ++it) {
+ const QString text = QGuiApplicationPrivate::platformTheme()->standardButtonText(it.value());
+ if (!text.isEmpty())
+ it.key()->setText(text);
}
}
@@ -1008,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: