summaryrefslogtreecommitdiffstats
path: root/src/platformsupport
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-03-07 08:56:41 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-07 12:43:32 +0100
commit83cabda862dced9477d155c84df9440047c856cf (patch)
tree9f39de378bfeed923d2a35e433481e4da1dc0f32 /src/platformsupport
parent7439fb47cd7c5731dd1aadeaf10c46b58aa59798 (diff)
Add fonts to QPlatformTheme.
- Remove QPlatformFontDatabase::defaultFonts() returning a hash containing widget name ->font and the Windows implementation. - Add enumeration and font accessor to QPlatformTheme. The value returned for the enumeration value overwrites the default font of the font database. - Implement for Windows, Mac and KDE. - Add more Windows palettes. Task-number: QTBUG-23686 Change-Id: I8a2abdfd216df23daa7c9630c54264cdf61295db Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/platformsupport')
-rw-r--r--src/platformsupport/themes/genericunix/qgenericunixthemes.cpp51
-rw-r--r--src/platformsupport/themes/genericunix/qgenericunixthemes_p.h23
2 files changed, 64 insertions, 10 deletions
diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp
index 257fe9156f..602dd6264a 100644
--- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp
+++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp
@@ -43,6 +43,7 @@
#include "../../services/genericunix/qgenericunixservices_p.h"
#include <QtGui/QPalette>
+#include <QtGui/QFont>
#include <QtGui/QGuiApplication>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
@@ -54,6 +55,20 @@
QT_BEGIN_NAMESPACE
+ResourceHelper::ResourceHelper()
+{
+ qFill(palettes, palettes + QPlatformTheme::NPalettes, static_cast<QPalette *>(0));
+ qFill(fonts, fonts + QPlatformTheme::NFonts, static_cast<QFont *>(0));
+}
+
+void ResourceHelper::clear()
+{
+ qDeleteAll(palettes, palettes + QPlatformTheme::NPalettes);
+ qDeleteAll(fonts, fonts + QPlatformTheme::NFonts);
+ qFill(palettes, palettes + QPlatformTheme::NPalettes, static_cast<QPalette *>(0));
+ qFill(fonts, fonts + QPlatformTheme::NFonts, static_cast<QFont *>(0));
+}
+
/*!
\class QGenericX11ThemeQKdeTheme
\brief QGenericX11Theme is a generic theme implementation for X11.
@@ -148,19 +163,40 @@ QKdeTheme::QKdeTheme(const QString &kdeHome, int kdeVersion) :
m_kdeHome(kdeHome), m_kdeVersion(kdeVersion),
m_toolButtonStyle(Qt::ToolButtonTextBesideIcon), m_toolBarIconSize(0)
{
- qFill(m_palettes, m_palettes + NPalettes, static_cast<QPalette *>(0));
refresh();
}
-void QKdeTheme::clearPalettes()
+static inline QFont *readKdeFontSetting(const QSettings &settings, const QString &key)
{
- qDeleteAll(m_palettes, m_palettes + NPalettes);
- qFill(m_palettes, m_palettes + NPalettes, static_cast<QPalette *>(0));
+ const QVariant fontValue = settings.value(key);
+ if (fontValue.isValid()) {
+ // Read font value: Might be a QStringList as KDE stores fonts without quotes.
+ // Also retrieve the family for the constructor since we cannot use the
+ // default constructor of QFont, which accesses QGuiApplication::systemFont()
+ // causing recursion.
+ QString fontDescription;
+ QString fontFamily;
+ if (fontValue.type() == QVariant::StringList) {
+ const QStringList list = fontValue.toStringList();
+ if (!list.isEmpty()) {
+ fontFamily = list.first();
+ fontDescription = list.join(QStringLiteral(","));
+ }
+ } else {
+ fontDescription = fontFamily = fontValue.toString();
+ }
+ if (!fontDescription.isEmpty()) {
+ QFont font(fontFamily);
+ if (font.fromString(fontDescription))
+ return new QFont(font);
+ }
+ }
+ return 0;
}
void QKdeTheme::refresh()
{
- clearPalettes();
+ m_resources.clear();
m_toolButtonStyle = Qt::ToolButtonTextBesideIcon;
m_toolBarIconSize = 0;
@@ -177,7 +213,7 @@ void QKdeTheme::refresh()
QPalette systemPalette;
if (readKdeSystemPalette(kdeSettings, &systemPalette))
- m_palettes[SystemPalette] = new QPalette(systemPalette);
+ m_resources.palettes[SystemPalette] = new QPalette(systemPalette);
//## TODO tooltip color
const QVariant styleValue = kdeSettings.value(QStringLiteral("widgetStyle"));
@@ -205,6 +241,9 @@ void QKdeTheme::refresh()
else if (toolBarStyle == QStringLiteral("TextUnderIcon"))
m_toolButtonStyle = Qt::ToolButtonTextUnderIcon;
}
+
+ // Read system font, ignore 'fixed' 'smallestReadableFont'
+ m_resources.fonts[SystemFont] = readKdeFontSetting(kdeSettings, QStringLiteral("font"));
}
QString QKdeTheme::globalSettingsFile() const
diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h
index 12937a205f..a9db29e8cd 100644
--- a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h
+++ b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h
@@ -50,6 +50,18 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
+class ResourceHelper
+{
+public:
+ ResourceHelper();
+ ~ResourceHelper() { clear(); }
+
+ void clear();
+
+ QPalette *palettes[QPlatformTheme::NPalettes];
+ QFont *fonts[QPlatformTheme::NFonts];
+};
+
class QGenericUnixTheme : public QPlatformTheme
{
public:
@@ -66,21 +78,24 @@ class QKdeTheme : public QPlatformTheme
{
QKdeTheme(const QString &kdeHome, int kdeVersion);
public:
- ~QKdeTheme() { clearPalettes(); }
static QPlatformTheme *createKdeTheme();
virtual QVariant themeHint(ThemeHint hint) const;
+
virtual const QPalette *palette(Palette type = SystemPalette) const
- { return m_palettes[type]; }
+ { return m_resources.palettes[type]; }
+
+ virtual const QFont *font(Font type) const
+ { return m_resources.fonts[type]; }
private:
QString globalSettingsFile() const;
- void clearPalettes();
void refresh();
const QString m_kdeHome;
const int m_kdeVersion;
- QPalette *m_palettes[NPalettes];
+
+ ResourceHelper m_resources;
QString m_iconThemeName;
QString m_iconFallbackThemeName;
QStringList m_styleNames;