Fix default font for X11.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Thu, 2 Aug 2012 12:14:15 +0000 (14:14 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 2 Aug 2012 18:38:54 +0000 (20:38 +0200)
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 <samuel.rodal@nokia.com>
Reviewed-by: hjk <qthjk@ovi.com>
src/platformsupport/themes/genericunix/qgenericunixthemes.cpp
src/platformsupport/themes/genericunix/qgenericunixthemes_p.h

index 970b57d..a26592d 100644 (file)
@@ -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.
 */
index 64b2db0..2151629 100644 (file)
@@ -45,6 +45,7 @@
 #include <qpa/qplatformtheme.h>
 #include <QtCore/QString>
 #include <QtCore/QStringList>
+#include <QtGui/QFont>
 
 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();