Introduce function for standard button texts to QPlatformTheme.

Change-Id: I91eec04a95b5047d893490a70152237b2991f662
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
Friedemann Kleint 2014-01-08 15:12:43 +01:00 committed by The Qt Project
parent d5912b2a47
commit ab2c90cc52
13 changed files with 133 additions and 133 deletions

View File

@ -51,6 +51,7 @@
#include <private/qiconloader_p.h>
#include <private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformdialoghelper.h>
QT_BEGIN_NAMESPACE
@ -627,6 +628,63 @@ QList<QKeySequence> 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();

View File

@ -296,7 +296,10 @@ public:
virtual QList<QKeySequence> 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);

View File

@ -57,6 +57,7 @@
#include <private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformservices.h>
#include <qpa/qplatformdialoghelper.h>
#include <algorithm>
@ -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.
*/

View File

@ -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;
};

View File

@ -43,6 +43,8 @@
#include <QtWidgets/QStyle>
#include "qandroidplatformdialoghelpers.h"
#include "androidjnimain.h"
#include <private/qguiapplication_p.h>
#include <qpa/qplatformtheme.h>
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<void>("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<void>("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<void>("addButton", "(ILjava/lang/String;)V", i, QJNIObjectPrivate::fromString(text).object());
}
}
m_javaMessageDialog.callMethod<void>("show", "(J)V", jlong(static_cast<QObject*>(this)));

View File

@ -46,6 +46,7 @@
#include "qandroidplatformdialoghelpers.h"
#include <QVariant>
#include <QFileInfo>
#include <QCoreApplication>
#include <qandroidplatformintegration.h>
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)

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -42,6 +42,7 @@
#import <Cocoa/Cocoa.h>
#include "qcocoatheme.h"
#include "messages.h"
#include <QtCore/QVariant>
@ -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();

View File

@ -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"
@ -246,7 +248,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)
@ -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<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);
}
}

View File

@ -188,11 +188,11 @@ void tst_languageChange::retranslatability_data()
//next we fill it with data
QTest::newRow( "QInputDialog" )
<< int(InputDialog) << (QSet<QByteArray>()
<< "QDialogButtonBox::Cancel");
<< "QPlatformTheme::Cancel");
QTest::newRow( "QColorDialog" )
<< int(ColorDialog) << (QSet<QByteArray>()
<< "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:");
}