From ab2c90cc525f499f0061a5042e7370bb8db2af94 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 8 Jan 2014 15:12:43 +0100 Subject: Introduce function for standard button texts to QPlatformTheme. Change-Id: I91eec04a95b5047d893490a70152237b2991f662 Reviewed-by: Shawn Rutledge --- src/widgets/widgets/qdialogbuttonbox.cpp | 94 ++++---------------------------- 1 file changed, 10 insertions(+), 84 deletions(-) (limited to 'src/widgets/widgets/qdialogbuttonbox.cpp') diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 6b183d3759..d28fb66551 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -46,7 +46,9 @@ #include #include #include +#include #include +#include #include #include "qdialogbuttonbox.h" @@ -246,7 +248,6 @@ public: void _q_handleButtonClicked(); void addButtonsToLayout(const QList &buttonList, bool reverse); void retranslateStrings(); - const char *standardButtonText(QDialogButtonBox::StandardButton sbutton) const; }; QDialogButtonBoxPrivate::QDialogButtonBoxPrivate(Qt::Orientation orient) @@ -428,7 +429,6 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut bool doLayout) { Q_Q(QDialogButtonBox); - const char *buttonText = 0; int icon = 0; switch (sbutton) { @@ -477,9 +477,7 @@ 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)); @@ -525,87 +523,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::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::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); } } -- cgit v1.2.3