diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 628b2c9d12..90edf4c49f 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -51,6 +51,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -627,6 +628,63 @@ QList QPlatformTheme::keyBindings(QKeySequence::StandardKey key) c return list; } +/*! + Returns the text of a standard \a button. + + \since 5.3 + \sa QMessageDialogOptions::StandardButton + */ + +QString QPlatformTheme::standardButtonText(int button) const +{ + return QPlatformTheme::defaultStandardButtonText(button); +} + +QString QPlatformTheme::defaultStandardButtonText(int button) +{ + switch (button) { + case QMessageDialogOptions::Ok: + return QCoreApplication::translate("QPlatformTheme", "OK"); + case QMessageDialogOptions::Save: + return QCoreApplication::translate("QPlatformTheme", "Save"); + case QMessageDialogOptions::SaveAll: + return QCoreApplication::translate("QPlatformTheme", "Save All"); + case QMessageDialogOptions::Open: + return QCoreApplication::translate("QPlatformTheme", "Open"); + case QMessageDialogOptions::Yes: + return QCoreApplication::translate("QPlatformTheme", "&Yes"); + case QMessageDialogOptions::YesToAll: + return QCoreApplication::translate("QPlatformTheme", "Yes to &All"); + case QMessageDialogOptions::No: + return QCoreApplication::translate("QPlatformTheme", "&No"); + case QMessageDialogOptions::NoToAll: + return QCoreApplication::translate("QPlatformTheme", "N&o to All"); + case QMessageDialogOptions::Abort: + return QCoreApplication::translate("QPlatformTheme", "Abort"); + case QMessageDialogOptions::Retry: + return QCoreApplication::translate("QPlatformTheme", "Retry"); + case QMessageDialogOptions::Ignore: + return QCoreApplication::translate("QPlatformTheme", "Ignore"); + case QMessageDialogOptions::Close: + return QCoreApplication::translate("QPlatformTheme", "Close"); + case QMessageDialogOptions::Cancel: + return QCoreApplication::translate("QPlatformTheme", "Cancel"); + case QMessageDialogOptions::Discard: + return QCoreApplication::translate("QPlatformTheme", "Discard"); + case QMessageDialogOptions::Help: + return QCoreApplication::translate("QPlatformTheme", "Help"); + case QMessageDialogOptions::Apply: + return QCoreApplication::translate("QPlatformTheme", "Apply"); + case QMessageDialogOptions::Reset: + return QCoreApplication::translate("QPlatformTheme", "Reset"); + case QMessageDialogOptions::RestoreDefaults: + return QCoreApplication::translate("QPlatformTheme", "Restore Defaults"); + default: + break; + } + return QString(); +} + unsigned QPlatformThemePrivate::currentKeyPlatforms() { const uint keyboardScheme = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt(); diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 2ab8cef760..205a5bab69 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -296,7 +296,10 @@ public: virtual QList keyBindings(QKeySequence::StandardKey key) const; + virtual QString standardButtonText(int button) const; + static QVariant defaultThemeHint(ThemeHint hint); + static QString defaultStandardButtonText(int button); protected: explicit QPlatformTheme(QPlatformThemePrivate *priv); diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index ee295afe6c..42b3d64a47 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include @@ -533,6 +534,25 @@ const QFont *QGnomeTheme::font(Font type) const } } +QString QGnomeTheme::standardButtonText(int button) const +{ + switch (button) { + case QMessageDialogOptions::Ok: + return QCoreApplication::translate("QGnomeTheme", "&OK"); + case QMessageDialogOptions::Save: + return QCoreApplication::translate("QGnomeTheme", "&Save"); + case QMessageDialogOptions::Cancel: + return QCoreApplication::translate("QGnomeTheme", "&Cancel"); + case QMessageDialogOptions::QMessageDialogOptions::Close: + return QCoreApplication::translate("QGnomeTheme", "&Close"); + case QMessageDialogOptions::Discard: + return QCoreApplication::translate("QGnomeTheme", "Close without Saving"); + default: + break; + } + return QPlatformTheme::standardButtonText(button); +} + /*! \brief Creates a UNIX theme according to the detected desktop environment. */ diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h index de53874941..36fcdd8dce 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h @@ -109,6 +109,7 @@ public: QGnomeTheme(); virtual QVariant themeHint(ThemeHint hint) const; virtual const QFont *font(Font type) const; + QString standardButtonText(int button) const Q_DECL_OVERRIDE; static const char *name; }; diff --git a/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp index 4c91e76e0f..4b99f2ce73 100644 --- a/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp +++ b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp @@ -43,6 +43,8 @@ #include #include "qandroidplatformdialoghelpers.h" #include "androidjnimain.h" +#include +#include namespace QtAndroidDialogHelpers { static jclass g_messageDialogHelperClass = 0; @@ -61,49 +63,6 @@ void QAndroidPlatformMessageDialogHelper::exec() m_loop.exec(); } -static QString standardButtonText(int sbutton) -{ - switch (sbutton) { - case QMessageDialogOptions::Ok: - return QAndroidPlatformMessageDialogHelper::tr("OK"); - case QMessageDialogOptions::Save: - return QAndroidPlatformMessageDialogHelper::tr("Save"); - case QMessageDialogOptions::Open: - return QAndroidPlatformMessageDialogHelper::tr("Open"); - case QMessageDialogOptions::Cancel: - return QAndroidPlatformMessageDialogHelper::tr("Cancel"); - case QMessageDialogOptions::Close: - return QAndroidPlatformMessageDialogHelper::tr("Close"); - case QMessageDialogOptions::Apply: - return QAndroidPlatformMessageDialogHelper::tr("Apply"); - case QMessageDialogOptions::Reset: - return QAndroidPlatformMessageDialogHelper::tr("Reset"); - case QMessageDialogOptions::Help: - return QAndroidPlatformMessageDialogHelper::tr("Help"); - case QMessageDialogOptions::Discard: - return QAndroidPlatformMessageDialogHelper::tr("Discard"); - case QMessageDialogOptions::Yes: - return QAndroidPlatformMessageDialogHelper::tr("Yes"); - case QMessageDialogOptions::YesToAll: - return QAndroidPlatformMessageDialogHelper::tr("Yes to All"); - case QMessageDialogOptions::No: - return QAndroidPlatformMessageDialogHelper::tr("No"); - case QMessageDialogOptions::NoToAll: - return QAndroidPlatformMessageDialogHelper::tr("No to All"); - case QMessageDialogOptions::SaveAll: - return QAndroidPlatformMessageDialogHelper::tr("Save All"); - case QMessageDialogOptions::Abort: - return QAndroidPlatformMessageDialogHelper::tr("Abort"); - case QMessageDialogOptions::Retry: - return QAndroidPlatformMessageDialogHelper::tr("Retry"); - case QMessageDialogOptions::Ignore: - return QAndroidPlatformMessageDialogHelper::tr("Ignore"); - case QMessageDialogOptions::RestoreDefaults: - return QAndroidPlatformMessageDialogHelper::tr("Restore Defaults"); - } // switch - return QString(); -} - bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags , Qt::WindowModality windowModality , QWindow *parent) @@ -134,8 +93,10 @@ bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags m_javaMessageDialog.callMethod("setDetailedText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); for (int i = QMessageDialogOptions::FirstButton; i < QMessageDialogOptions::LastButton; i<<=1) { - if ( opt->standardButtons() & i ) - m_javaMessageDialog.callMethod("addButton", "(ILjava/lang/String;)V", i, QJNIObjectPrivate::fromString(standardButtonText(i)).object()); + if ( opt->standardButtons() & i ) { + const QString text = QGuiApplicationPrivate::platformTheme()->standardButtonText(i); + m_javaMessageDialog.callMethod("addButton", "(ILjava/lang/String;)V", i, QJNIObjectPrivate::fromString(text).object()); + } } m_javaMessageDialog.callMethod("show", "(J)V", jlong(static_cast(this))); diff --git a/src/plugins/platforms/android/qandroidplatformtheme.cpp b/src/plugins/platforms/android/qandroidplatformtheme.cpp index 308bb70faf..ab29541f15 100644 --- a/src/plugins/platforms/android/qandroidplatformtheme.cpp +++ b/src/plugins/platforms/android/qandroidplatformtheme.cpp @@ -46,6 +46,7 @@ #include "qandroidplatformdialoghelpers.h" #include #include +#include #include QAndroidPlatformTheme::QAndroidPlatformTheme(QAndroidPlatformNativeInterface *androidPlatformNativeInterface) @@ -152,6 +153,21 @@ QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const } } +QString QAndroidPlatformTheme::standardButtonText(int button) const +{ + switch (button) { + case QMessageDialogOptions::Yes: + return QCoreApplication::translate("QAndroidPlatformTheme", "Yes"); + case QMessageDialogOptions::YesToAll: + return QCoreApplication::translate("QAndroidPlatformTheme", "Yes to All"); + case QMessageDialogOptions::No: + return QCoreApplication::translate("QAndroidPlatformTheme", "No"); + case QMessageDialogOptions::NoToAll: + return QCoreApplication::translate("QAndroidPlatformTheme", "No to All"); + } + return QPlatformTheme::standardButtonText(button); +} + bool QAndroidPlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const { if (type == MessageDialog) diff --git a/src/plugins/platforms/android/qandroidplatformtheme.h b/src/plugins/platforms/android/qandroidplatformtheme.h index ec259a9b0a..544061a7a2 100644 --- a/src/plugins/platforms/android/qandroidplatformtheme.h +++ b/src/plugins/platforms/android/qandroidplatformtheme.h @@ -54,6 +54,7 @@ public: virtual const QPalette *palette(Palette type = SystemPalette) const; virtual const QFont *font(Font type = SystemFont) const; virtual QVariant themeHint(ThemeHint hint) const; + QString standardButtonText(int button) const Q_DECL_OVERRIDE; virtual bool usePlatformNativeDialog(DialogType type) const; virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const; diff --git a/src/plugins/platforms/cocoa/messages.cpp b/src/plugins/platforms/cocoa/messages.cpp index 3db1618a50..1fe80b28b1 100644 --- a/src/plugins/platforms/cocoa/messages.cpp +++ b/src/plugins/platforms/cocoa/messages.cpp @@ -93,4 +93,9 @@ QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption) return QPlatformMenuItem::NoRole; } +QString msgDialogButtonDiscard() +{ + return QCoreApplication::translate("QCocoaTheme", "Don't Save"); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/messages.h b/src/plugins/platforms/cocoa/messages.h index 09705c1e21..97f3ea7009 100644 --- a/src/plugins/platforms/cocoa/messages.h +++ b/src/plugins/platforms/cocoa/messages.h @@ -53,6 +53,8 @@ QString qt_mac_applicationmenu_string(int type); QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption); +QString msgDialogButtonDiscard(); + QT_END_NAMESPACE #endif // MESSAGES_H diff --git a/src/plugins/platforms/cocoa/qcocoatheme.h b/src/plugins/platforms/cocoa/qcocoatheme.h index e4237c9b3e..d60cdf10d1 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.h +++ b/src/plugins/platforms/cocoa/qcocoatheme.h @@ -73,6 +73,7 @@ public: QPlatformTheme::IconOptions options = 0) const; QVariant themeHint(ThemeHint hint) const; + QString standardButtonText(int button) const Q_DECL_OVERRIDE; static const char *name; diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 1484ae2ba3..bf6c47f273 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -42,6 +42,7 @@ #import #include "qcocoatheme.h" +#include "messages.h" #include @@ -292,6 +293,11 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const return QPlatformTheme::themeHint(hint); } +QString QCocoaTheme::standardButtonText(int button) const +{ + return button == QMessageDialogOptions::Discard ? msgDialogButtonDiscard() : QPlatformTheme::standardButtonText(button); +} + QPlatformMenuItem *QCocoaTheme::createPlatformMenuItem() const { return new QCocoaMenuItem(); 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); } } diff --git a/tests/auto/other/languagechange/tst_languagechange.cpp b/tests/auto/other/languagechange/tst_languagechange.cpp index cc01d70454..16c3d56385 100644 --- a/tests/auto/other/languagechange/tst_languagechange.cpp +++ b/tests/auto/other/languagechange/tst_languagechange.cpp @@ -188,11 +188,11 @@ void tst_languageChange::retranslatability_data() //next we fill it with data QTest::newRow( "QInputDialog" ) << int(InputDialog) << (QSet() - << "QDialogButtonBox::Cancel"); + << "QPlatformTheme::Cancel"); QTest::newRow( "QColorDialog" ) << int(ColorDialog) << (QSet() - << "QDialogButtonBox::Cancel" + << "QPlatformTheme::Cancel" << "QColorDialog::&Sat:" << "QColorDialog::&Add to Custom Colors" << "QColorDialog::&Green:" @@ -237,8 +237,8 @@ void tst_languageChange::retranslatability_data() << "QFileSystemModel::Type::All other platforms" #endif // << "QFileSystemModel::%1 KB" - << "QDialogButtonBox::Cancel" - << "QDialogButtonBox::Open" + << "QPlatformTheme::Cancel" + << "QPlatformTheme::Open" << "QFileDialog::File &name:"); }