From 2a33bfcfd174d503e2f98c66d8de0a68783015da Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 12 Aug 2014 16:59:18 +0200 Subject: GTK2 theme should use GTK configured font variant This patch makes the GTK2 theme read the font configuration and use that as the default system font. Task-number: QTBUG-39643 Change-Id: Ieacf8968e54f34c6d44669350d349c9a96ed6cc5 Reviewed-by: Shawn Rutledge --- .../themes/genericunix/qgenericunixthemes.cpp | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/platformsupport/themes/genericunix/qgenericunixthemes.cpp') diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index bf73d30871..dac417ad80 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -519,15 +519,23 @@ const char *QGnomeTheme::name = "gnome"; class QGnomeThemePrivate : public QPlatformThemePrivate { public: - QGnomeThemePrivate() - : systemFont(QLatin1Literal(defaultSystemFontNameC), defaultSystemFontSize) - , fixedFont(QStringLiteral("monospace"), systemFont.pointSize()) + QGnomeThemePrivate() : fontsConfigured(false) { } + void configureFonts(QString gtkFontName) const { + Q_ASSERT(!fontsConfigured); + const int split = gtkFontName.lastIndexOf(QChar::Space); + float size = gtkFontName.mid(split+1).toFloat(); + QString fontName = gtkFontName.left(split); + + systemFont = QFont(fontName, size); + fixedFont = QFont(QLatin1String("monospace"), systemFont.pointSize()); fixedFont.setStyleHint(QFont::TypeWriter); + fontsConfigured = true; } - const QFont systemFont; - QFont fixedFont; + mutable QFont systemFont; + mutable QFont fixedFont; + mutable bool fontsConfigured; }; QGnomeTheme::QGnomeTheme() @@ -565,9 +573,11 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const const QFont *QGnomeTheme::font(Font type) const { Q_D(const QGnomeTheme); + if (!d->fontsConfigured) + d->configureFonts(gtkFontName()); switch (type) { case QPlatformTheme::SystemFont: - return &d->systemFont; + return &d->systemFont; case QPlatformTheme::FixedFont: return &d->fixedFont; default: @@ -575,6 +585,11 @@ const QFont *QGnomeTheme::font(Font type) const } } +QString QGnomeTheme::gtkFontName() const +{ + return QStringLiteral("%1 %2").arg(QLatin1String(defaultSystemFontNameC)).arg(defaultSystemFontSize); +} + QString QGnomeTheme::standardButtonText(int button) const { switch (button) { -- cgit v1.2.3