From 0e3dcf362460a2e4457f7059343d9720638360b8 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 2 Aug 2012 14:14:15 +0200 Subject: Fix default font for X11. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Qt 5 X11 applications currently have differing fonts since they no longer read ~/.config/Trolltech.conf. Set the default font value 4.8 would return for XRender/FontConfig in the theme classes. Change-Id: Ie0a77e6781a47a68fd67895821ab1773c25e0470 Reviewed-by: Samuel Rødal Reviewed-by: hjk --- .../themes/genericunix/qgenericunixthemes.cpp | 35 +++++++++++++++++++++- .../themes/genericunix/qgenericunixthemes_p.h | 11 +++++-- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'src/platformsupport/themes') diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 970b57de63..a26592d6ac 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -82,6 +82,23 @@ void ResourceHelper::clear() const char *QGenericUnixTheme::name = "generic"; +// Default system font, corresponding to the value returned by 4.8 for +// XRender/FontConfig which we can now assume as default. +static const char defaultSystemFontNameC[] = "Sans Serif"; +enum { defaultSystemFontSize = 9 }; + +QGenericUnixTheme::QGenericUnixTheme() + : m_systemFont(QLatin1String(defaultSystemFontNameC), defaultSystemFontSize) +{ +} + +const QFont *QGenericUnixTheme::font(Font type) const +{ + if (type == QPlatformTheme::SystemFont) + return &m_systemFont; + return 0; +} + // Helper to return the icon theme paths from XDG. QStringList QGenericUnixTheme::xdgIconThemePaths() { @@ -250,7 +267,11 @@ void QKdeTheme::refresh() } // Read system font, ignore 'fixed' 'smallestReadableFont' - m_resources.fonts[SystemFont] = readKdeFontSetting(kdeSettings, QStringLiteral("font")); + 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 @@ -340,6 +361,11 @@ QPlatformTheme *QKdeTheme::createKdeTheme() const char *QGnomeTheme::name = "gnome"; +QGnomeTheme::QGnomeTheme() + : m_systemFont(QLatin1String(defaultSystemFontNameC), defaultSystemFontSize) +{ +} + QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const { switch (hint) { @@ -365,6 +391,13 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const return QPlatformTheme::themeHint(hint); } +const QFont *QGnomeTheme::font(Font type) const +{ + if (type == QPlatformTheme::SystemFont) + return &m_systemFont; + return 0; +} + /*! \brief Creates a UNIX theme according to the detected desktop environment. */ diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h index 64b2db0a10..215162945e 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h @@ -45,6 +45,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -65,16 +66,20 @@ public: class QGenericUnixTheme : public QPlatformTheme { public: - QGenericUnixTheme() {} + QGenericUnixTheme(); static QPlatformTheme *createUnixTheme(const QString &name); static QStringList themeNames(); + virtual const QFont *font(Font type) const; virtual QVariant themeHint(ThemeHint hint) const; static QStringList xdgIconThemePaths(); static const char *name; + +private: + const QFont m_systemFont; }; #ifndef QT_NO_SETTINGS @@ -113,12 +118,14 @@ private: class QGnomeTheme : public QPlatformTheme { public: - QGnomeTheme() {} + 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(); -- cgit v1.2.3