Skip to content

Commit

Permalink
Introduce function for standard button texts to QPlatformTheme.
Browse files Browse the repository at this point in the history
Change-Id: I91eec04a95b5047d893490a70152237b2991f662
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
  • Loading branch information
Friedemann Kleint authored and The Qt Project committed Jan 18, 2014
1 parent d5912b2 commit ab2c90c
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 133 deletions.
58 changes: 58 additions & 0 deletions src/gui/kernel/qplatformtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/gui/kernel/qplatformtheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ class Q_GUI_EXPORT QPlatformTheme

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);
Expand Down
20 changes: 20 additions & 0 deletions src/platformsupport/themes/genericunix/qgenericunixthemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformservices.h>
#include <qpa/qplatformdialoghelper.h>

#include <algorithm>

Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class QGnomeTheme : public QPlatformTheme
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;
};
Expand Down
51 changes: 6 additions & 45 deletions src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)));
Expand Down
16 changes: 16 additions & 0 deletions src/plugins/platforms/android/qandroidplatformtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "qandroidplatformdialoghelpers.h"
#include <QVariant>
#include <QFileInfo>
#include <QCoreApplication>
#include <qandroidplatformintegration.h>

QAndroidPlatformTheme::QAndroidPlatformTheme(QAndroidPlatformNativeInterface *androidPlatformNativeInterface)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/platforms/android/qandroidplatformtheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class QAndroidPlatformTheme: public QPlatformTheme
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;

Expand Down
5 changes: 5 additions & 0 deletions src/plugins/platforms/cocoa/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/plugins/platforms/cocoa/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/plugins/platforms/cocoa/qcocoatheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class QCocoaTheme : public QPlatformTheme
QPlatformTheme::IconOptions options = 0) const;

QVariant themeHint(ThemeHint hint) const;
QString standardButtonText(int button) const Q_DECL_OVERRIDE;

static const char *name;

Expand Down
6 changes: 6 additions & 0 deletions src/plugins/platforms/cocoa/qcocoatheme.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#import <Cocoa/Cocoa.h>

#include "qcocoatheme.h"
#include "messages.h"

#include <QtCore/QVariant>

Expand Down Expand Up @@ -292,6 +293,11 @@ QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height)
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();
Expand Down
Loading

0 comments on commit ab2c90c

Please sign in to comment.