diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-03-07 08:56:41 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-07 12:43:32 +0100 |
commit | 83cabda862dced9477d155c84df9440047c856cf (patch) | |
tree | 9f39de378bfeed923d2a35e433481e4da1dc0f32 /src/platformsupport/themes/genericunix/qgenericunixthemes.cpp | |
parent | 7439fb47cd7c5731dd1aadeaf10c46b58aa59798 (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/themes/genericunix/qgenericunixthemes.cpp')
-rw-r--r-- | src/platformsupport/themes/genericunix/qgenericunixthemes.cpp | 51 |
1 files changed, 45 insertions, 6 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 |