diff options
author | Jørgen Lind <jorgen.lind@digia.com> | 2013-04-08 14:12:43 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-17 07:43:11 +0200 |
commit | 3ae271523ff7fb951df16cfccfaf84c0aa298e16 (patch) | |
tree | 446402cb007ac348c67ea35b44baedb4f8c3681e /src/platformsupport/themes | |
parent | d42e54c8626ee0d42d4df40e8f2a83df0698190a (diff) |
Move Fusion styles palette into QtGui
So that it can be used as the standard palette for QtGui
applications instead of the absolutely useless black palette.
Change-Id: Ie001439fcd8840a66275009c9f42cbf8bab4864a
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/platformsupport/themes')
-rw-r--r-- | src/platformsupport/themes/genericunix/qgenericunixthemes.cpp | 219 | ||||
-rw-r--r-- | src/platformsupport/themes/genericunix/qgenericunixthemes_p.h | 35 |
2 files changed, 153 insertions, 101 deletions
diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 6ea68397b6..4fc542c39a 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -42,6 +42,8 @@ #include "qgenericunixthemes_p.h" #include "../../services/genericunix/qgenericunixservices_p.h" +#include "qpa/qplatformtheme_p.h" + #include <QtGui/QPalette> #include <QtGui/QFont> #include <QtGui/QGuiApplication> @@ -87,15 +89,27 @@ const char *QGenericUnixTheme::name = "generic"; static const char defaultSystemFontNameC[] = "Sans Serif"; enum { defaultSystemFontSize = 9 }; +class QGenericUnixThemePrivate : public QPlatformThemePrivate +{ +public: + QGenericUnixThemePrivate() + : QPlatformThemePrivate() + , systemFont(QLatin1String(defaultSystemFontNameC), defaultSystemFontSize) + { } + + const QFont systemFont; +}; + QGenericUnixTheme::QGenericUnixTheme() - : m_systemFont(QLatin1String(defaultSystemFontNameC), defaultSystemFontSize) + : QPlatformTheme(new QGenericUnixThemePrivate()) { } const QFont *QGenericUnixTheme::font(Font type) const { + Q_D(const QGenericUnixTheme); if (type == QPlatformTheme::SystemFont) - return &m_systemFont; + return &d->systemFont; return 0; } @@ -142,6 +156,93 @@ QVariant QGenericUnixTheme::themeHint(ThemeHint hint) const } #ifndef QT_NO_SETTINGS +class QKdeThemePrivate : public QPlatformThemePrivate +{ +public: + QKdeThemePrivate(const QString &kdeHome, int kdeVersion) + : kdeHome(kdeHome) + , kdeVersion(kdeVersion) + , toolButtonStyle(Qt::ToolButtonTextBesideIcon) + , toolBarIconSize(0) + { } + + QString globalSettingsFile() const + { + return kdeHome + QStringLiteral("/share/config/kdeglobals"); + } + + void refresh(); + static void readKdeSystemPalette(const QSettings &kdeSettings, QPalette *pal); + static QFont *readKdeFontSetting(const QSettings &settings, const QString &key); + static QStringList kdeIconThemeSearchPaths(const QString &kdeHome); + + + const QString kdeHome; + const int kdeVersion; + + ResourceHelper resources; + QString iconThemeName; + QString iconFallbackThemeName; + QStringList styleNames; + int toolButtonStyle; + int toolBarIconSize; +}; + +void QKdeThemePrivate::refresh() +{ + resources.clear(); + + toolButtonStyle = Qt::ToolButtonTextBesideIcon; + toolBarIconSize = 0; + styleNames.clear(); + styleNames << QStringLiteral("Oxygen") << QStringLiteral("fusion") << QStringLiteral("windows"); + iconFallbackThemeName = iconThemeName = QStringLiteral("oxygen"); + + // Read settings file. + const QString settingsFile = globalSettingsFile(); + if (!QFileInfo(settingsFile).isReadable()) + return; + + const QSettings kdeSettings(settingsFile, QSettings::IniFormat); + + QPalette systemPalette = QPalette(); + readKdeSystemPalette(kdeSettings, &systemPalette); + resources.palettes[QPlatformTheme::SystemPalette] = new QPalette(systemPalette); + //## TODO tooltip color + + const QVariant styleValue = kdeSettings.value(QStringLiteral("widgetStyle")); + if (styleValue.isValid()) { + const QString style = styleValue.toString(); + if (style != styleNames.front()) + styleNames.push_front(style); + } + + const QVariant themeValue = kdeSettings.value(QStringLiteral("Icons/Theme")); + if (themeValue.isValid()) + iconThemeName = themeValue.toString(); + + const QVariant toolBarIconSizeValue = kdeSettings.value(QStringLiteral("ToolbarIcons/Size")); + if (toolBarIconSizeValue.isValid()) + toolBarIconSize = toolBarIconSizeValue.toInt(); + + const QVariant toolbarStyleValue = kdeSettings.value(QStringLiteral("ToolButtonStyle")); + if (toolbarStyleValue.isValid()) { + const QString toolBarStyle = toolbarStyleValue.toString(); + if (toolBarStyle == QStringLiteral("TextBesideIcon")) + toolButtonStyle = Qt::ToolButtonTextBesideIcon; + else if (toolBarStyle == QStringLiteral("TextOnly")) + toolButtonStyle = Qt::ToolButtonTextOnly; + else if (toolBarStyle == QStringLiteral("TextUnderIcon")) + toolButtonStyle = Qt::ToolButtonTextUnderIcon; + } + + // Read system font, ignore 'fixed' 'smallestReadableFont' + if (QFont *systemFont = readKdeFontSetting(kdeSettings, QStringLiteral("font"))) { + resources.fonts[QPlatformTheme::SystemFont] = systemFont; + } else { + resources.fonts[QPlatformTheme::SystemFont] = new QFont(QLatin1String(defaultSystemFontNameC), defaultSystemFontSize); + } +} // Reads the color from the KDE configuration, and store it in the // palette with the given color role if found. @@ -158,7 +259,7 @@ static inline bool kdeColor(QPalette *pal, QPalette::ColorRole role, return true; } -static inline void readKdeSystemPalette(const QSettings &kdeSettings, QPalette *pal) +void QKdeThemePrivate::readKdeSystemPalette(const QSettings &kdeSettings, QPalette *pal) { kdeColor(pal, QPalette::Button, kdeSettings, QStringLiteral("Colors:Button/BackgroundNormal")); kdeColor(pal, QPalette::Window, kdeSettings, QStringLiteral("Colors:Window/BackgroundNormal")); @@ -183,14 +284,13 @@ static inline void readKdeSystemPalette(const QSettings &kdeSettings, QPalette * const char *QKdeTheme::name = "kde"; -QKdeTheme::QKdeTheme(const QString &kdeHome, int kdeVersion) : - m_kdeHome(kdeHome), m_kdeVersion(kdeVersion), - m_toolButtonStyle(Qt::ToolButtonTextBesideIcon), m_toolBarIconSize(0) +QKdeTheme::QKdeTheme(const QString &kdeHome, int kdeVersion) + : QPlatformTheme(new QKdeThemePrivate(kdeHome,kdeVersion)) { - refresh(); + d_func()->refresh(); } -static inline QFont *readKdeFontSetting(const QSettings &settings, const QString &key) +QFont *QKdeThemePrivate::readKdeFontSetting(const QSettings &settings, const QString &key) { const QVariant fontValue = settings.value(key); if (fontValue.isValid()) { @@ -218,68 +318,8 @@ static inline QFont *readKdeFontSetting(const QSettings &settings, const QString return 0; } -void QKdeTheme::refresh() -{ - m_resources.clear(); - - m_toolButtonStyle = Qt::ToolButtonTextBesideIcon; - m_toolBarIconSize = 0; - m_styleNames.clear(); - m_styleNames << QStringLiteral("Oxygen") << QStringLiteral("fusion") << QStringLiteral("windows"); - m_iconFallbackThemeName = m_iconThemeName = QStringLiteral("oxygen"); - - // Read settings file. - const QString settingsFile = globalSettingsFile(); - if (!QFileInfo(settingsFile).isReadable()) - return; - - const QSettings kdeSettings(settingsFile, QSettings::IniFormat); - - QPalette systemPalette = QPalette(); - readKdeSystemPalette(kdeSettings, &systemPalette); - m_resources.palettes[SystemPalette] = new QPalette(systemPalette); - //## TODO tooltip color - - const QVariant styleValue = kdeSettings.value(QStringLiteral("widgetStyle")); - if (styleValue.isValid()) { - const QString style = styleValue.toString(); - if (style != m_styleNames.front()) - m_styleNames.push_front(style); - } - - const QVariant themeValue = kdeSettings.value(QStringLiteral("Icons/Theme")); - if (themeValue.isValid()) - m_iconThemeName = themeValue.toString(); - - const QVariant toolBarIconSizeValue = kdeSettings.value(QStringLiteral("ToolbarIcons/Size")); - if (toolBarIconSizeValue.isValid()) - m_toolBarIconSize = toolBarIconSizeValue.toInt(); - - const QVariant toolbarStyleValue = kdeSettings.value(QStringLiteral("ToolButtonStyle")); - if (toolbarStyleValue.isValid()) { - const QString toolBarStyle = toolbarStyleValue.toString(); - if (toolBarStyle == QStringLiteral("TextBesideIcon")) - m_toolButtonStyle = Qt::ToolButtonTextBesideIcon; - else if (toolBarStyle == QStringLiteral("TextOnly")) - m_toolButtonStyle = Qt::ToolButtonTextOnly; - else if (toolBarStyle == QStringLiteral("TextUnderIcon")) - m_toolButtonStyle = Qt::ToolButtonTextUnderIcon; - } - - // Read system font, ignore 'fixed' 'smallestReadableFont' - if (QFont *systemFont = readKdeFontSetting(kdeSettings, QStringLiteral("font"))) { - m_resources.fonts[SystemFont] = systemFont; - } else { - m_resources.fonts[SystemFont] = new QFont(QLatin1String(defaultSystemFontNameC), defaultSystemFontSize); - } -} - -QString QKdeTheme::globalSettingsFile() const -{ - return m_kdeHome + QStringLiteral("/share/config/kdeglobals"); -} -static QStringList kdeIconThemeSearchPaths(const QString &kdeHome) +QStringList QKdeThemePrivate::kdeIconThemeSearchPaths(const QString &kdeHome) { QStringList candidates = QStringList(kdeHome); const QString kdeDirs = QFile::decodeName(qgetenv("KDEDIRS")); @@ -298,6 +338,7 @@ static QStringList kdeIconThemeSearchPaths(const QString &kdeHome) QVariant QKdeTheme::themeHint(QPlatformTheme::ThemeHint hint) const { + Q_D(const QKdeTheme); switch (hint) { case QPlatformTheme::UseFullScreenForPopupMenu: return QVariant(true); @@ -306,17 +347,17 @@ QVariant QKdeTheme::themeHint(QPlatformTheme::ThemeHint hint) const case QPlatformTheme::DialogButtonBoxLayout: return QVariant(2); // QDialogButtonBox::KdeLayout case QPlatformTheme::ToolButtonStyle: - return QVariant(m_toolButtonStyle); + return QVariant(d->toolButtonStyle); case QPlatformTheme::ToolBarIconSize: - return QVariant(m_toolBarIconSize); + return QVariant(d->toolBarIconSize); case QPlatformTheme::SystemIconThemeName: - return QVariant(m_iconThemeName); + return QVariant(d->iconThemeName); case QPlatformTheme::SystemIconFallbackThemeName: - return QVariant(m_iconFallbackThemeName); + return QVariant(d->iconFallbackThemeName); case QPlatformTheme::IconThemeSearchPaths: - return QVariant(kdeIconThemeSearchPaths(m_kdeHome)); + return QVariant(d->kdeIconThemeSearchPaths(d->kdeHome)); case QPlatformTheme::StyleNames: - return QVariant(m_styleNames); + return QVariant(d->styleNames); case QPlatformTheme::KeyboardScheme: return QVariant(int(KdeKeyboardScheme)); default: @@ -325,6 +366,18 @@ QVariant QKdeTheme::themeHint(QPlatformTheme::ThemeHint hint) const return QPlatformTheme::themeHint(hint); } +const QPalette *QKdeTheme::palette(Palette type) const +{ + Q_D(const QKdeTheme); + return d->resources.palettes[type]; +} + +const QFont *QKdeTheme::font(Font type) const +{ + Q_D(const QKdeTheme); + return d->resources.fonts[type]; +} + QPlatformTheme *QKdeTheme::createKdeTheme() { // Check for version >= 4 and determine home folder from environment, @@ -361,8 +414,18 @@ QPlatformTheme *QKdeTheme::createKdeTheme() const char *QGnomeTheme::name = "gnome"; +class QGnomeThemePrivate : public QPlatformThemePrivate +{ +public: + QGnomeThemePrivate() + : systemFont(QLatin1Literal(defaultSystemFontNameC), defaultSystemFontSize) + {} + + const QFont systemFont; +}; + QGnomeTheme::QGnomeTheme() - : m_systemFont(QLatin1String(defaultSystemFontNameC), defaultSystemFontSize) + : QPlatformTheme(new QGnomeThemePrivate()) { } @@ -393,8 +456,10 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const const QFont *QGnomeTheme::font(Font type) const { + Q_D(const QGnomeTheme); if (type == QPlatformTheme::SystemFont) - return &m_systemFont; + return &d->systemFont; + return 0; } diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h index b0ac13efe4..03445776f4 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h @@ -61,8 +61,11 @@ public: QFont *fonts[QPlatformTheme::NFonts]; }; +class QGenericUnixThemePrivate; + class QGenericUnixTheme : public QPlatformTheme { + Q_DECLARE_PRIVATE(QGenericUnixTheme) public: QGenericUnixTheme(); @@ -75,55 +78,39 @@ public: static QStringList xdgIconThemePaths(); static const char *name; - -private: - const QFont m_systemFont; }; #ifndef QT_NO_SETTINGS +class QKdeThemePrivate; + class QKdeTheme : public QPlatformTheme { + Q_DECLARE_PRIVATE(QKdeTheme) QKdeTheme(const QString &kdeHome, int kdeVersion); public: static QPlatformTheme *createKdeTheme(); virtual QVariant themeHint(ThemeHint hint) const; - virtual const QPalette *palette(Palette type = SystemPalette) const - { return m_resources.palettes[type]; } + virtual const QPalette *palette(Palette type = SystemPalette) const; - virtual const QFont *font(Font type) const - { return m_resources.fonts[type]; } + virtual const QFont *font(Font type) const; static const char *name; - -private: - QString globalSettingsFile() const; - void refresh(); - - const QString m_kdeHome; - const int m_kdeVersion; - - ResourceHelper m_resources; - QString m_iconThemeName; - QString m_iconFallbackThemeName; - QStringList m_styleNames; - int m_toolButtonStyle; - int m_toolBarIconSize; }; #endif // QT_NO_SETTINGS +class QGnomeThemePrivate; + class QGnomeTheme : public QPlatformTheme { + Q_DECLARE_PRIVATE(QGnomeTheme) public: QGnomeTheme(); virtual QVariant themeHint(ThemeHint hint) const; virtual const QFont *font(Font type) const; static const char *name; - -private: - const QFont m_systemFont; }; QPlatformTheme *qt_createUnixTheme(); |