From 13242c8a5f34f7dc8e8c52dd631cb0ecdaca6ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Sun, 12 Jan 2014 19:33:56 +0100 Subject: [PATCH] Move smallestFont and defaultFont properties into Plasma::Theme --- src/declarativeimports/core/theme.cpp | 23 ----------------------- src/declarativeimports/core/theme.h | 11 ----------- src/plasma/private/theme_p.cpp | 5 +++++ src/plasma/private/theme_p.h | 2 ++ src/plasma/theme.cpp | 14 ++++++++++++++ src/plasma/theme.h | 9 +++++++++ 6 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/declarativeimports/core/theme.cpp b/src/declarativeimports/core/theme.cpp index 8ae726e53..454ea93f8 100644 --- a/src/declarativeimports/core/theme.cpp +++ b/src/declarativeimports/core/theme.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -47,24 +46,12 @@ ThemeProxy::ThemeProxy(QQmlEngine *parent) connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), this, SLOT(iconLoaderSettingsChanged())); updateSpacing(); - installEventFilter(qApp); } ThemeProxy::~ThemeProxy() { } -bool ThemeProxy::eventFilter(QObject *watched, QEvent *event) -{ - if (watched == QCoreApplication::instance()) { - if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) { - defaultFontChanged(); - smallestFontChanged(); - } - } - return QObject::eventFilter(watched, event); -} - void ThemeProxy::updateSpacing() { const int _s = mSize().height(); @@ -72,16 +59,6 @@ void ThemeProxy::updateSpacing() m_largeSpacing = _s; } -QFont ThemeProxy::defaultFont() const -{ - return QApplication::font(); -} - -QFont ThemeProxy::smallestFont() const -{ - return QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); -} - QSizeF ThemeProxy::mSize(const QFont &font) const { return QFontMetrics(font).boundingRect("M").size(); diff --git a/src/declarativeimports/core/theme.h b/src/declarativeimports/core/theme.h index 18274ce68..e2912e907 100644 --- a/src/declarativeimports/core/theme.h +++ b/src/declarativeimports/core/theme.h @@ -40,10 +40,6 @@ class ThemeProxy : public Plasma::Theme { Q_OBJECT - //fonts - Q_PROPERTY(QFont defaultFont READ defaultFont NOTIFY defaultFontChanged) - Q_PROPERTY(QFont smallestFont READ smallestFont NOTIFY smallestFontChanged) - // colors Q_PROPERTY(QColor textColor READ textColor NOTIFY themeChanged) Q_PROPERTY(QColor highlightColor READ highlightColor NOTIFY themeChanged) @@ -90,15 +86,11 @@ public: ~ThemeProxy(); QString themeName() const; - QFont defaultFont() const; - QFont smallestFont() const; /** * @return The size of an uppercase M in a font, defaultFont() by default */ Q_INVOKABLE QSizeF mSize(const QFont &font = QApplication::font()) const; - bool useGlobalSettings() const; - QString wallpaperPath() const; Q_INVOKABLE QString wallpaperPathForSize(int width=-1, int height=-1) const; QColor textColor() const; @@ -135,11 +127,8 @@ Q_SIGNALS: void themeChanged(); void defaultIconSizeChanged(); void iconSizesChanged(); - void defaultFontChanged(); - void smallestFontChanged(); private: - bool eventFilter(QObject *watched, QEvent *event); void updateSpacing(); int m_smallSpacing; int m_largeSpacing; diff --git a/src/plasma/private/theme_p.cpp b/src/plasma/private/theme_p.cpp index 7b77cb2fb..dc1a8690f 100644 --- a/src/plasma/private/theme_p.cpp +++ b/src/plasma/private/theme_p.cpp @@ -88,6 +88,7 @@ ThemePrivate::ThemePrivate(QObject *parent) QObject::connect(s_blurEffectWatcher, SIGNAL(effectChanged(bool)), this, SLOT(blurBehindChanged(bool))); #endif } + installEventFilter(qApp); } ThemePrivate::~ThemePrivate() @@ -574,6 +575,10 @@ bool ThemePrivate::eventFilter(QObject *watched, QEvent *event) if (event->type() == QEvent::ApplicationPaletteChange) { colorsChanged(); } + if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) { + defaultFontChanged(); + smallestFontChanged(); + } } return QObject::eventFilter(watched, event); } diff --git a/src/plasma/private/theme_p.h b/src/plasma/private/theme_p.h index 408546ecf..3bdb9615f 100644 --- a/src/plasma/private/theme_p.h +++ b/src/plasma/private/theme_p.h @@ -94,6 +94,8 @@ public Q_SLOTS: Q_SIGNALS: void themeChanged(); + void defaultFontChanged(); + void smallestFontChanged(); public: static const char *defaultTheme; diff --git a/src/plasma/theme.cpp b/src/plasma/theme.cpp index f4a1d7d5f..9f3b786e4 100644 --- a/src/plasma/theme.cpp +++ b/src/plasma/theme.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,8 @@ Theme::Theme(QObject *parent) d, SLOT(onAppExitCleanup())); } connect(d, &ThemePrivate::themeChanged, this, &Theme::themeChanged); + connect(d, &ThemePrivate::defaultFontChanged, this, &Theme::defaultFontChanged); + connect(d, &ThemePrivate::smallestFontChanged, this, &Theme::smallestFontChanged); } Theme::Theme(const QString &themeName, QObject *parent) @@ -452,6 +455,17 @@ KPluginInfo Theme::pluginInfo() const return d->pluginInfo; } +QFont Theme::defaultFont() const +{ + return QApplication::font(); +} + +QFont Theme::smallestFont() const +{ + return QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); +} + + } #include "moc_theme.cpp" diff --git a/src/plasma/theme.h b/src/plasma/theme.h index bd46e87cb..3367f0658 100644 --- a/src/plasma/theme.h +++ b/src/plasma/theme.h @@ -56,6 +56,9 @@ class PLASMA_EXPORT Theme : public QObject Q_PROPERTY(bool useGlobalSettings READ useGlobalSettings NOTIFY themeChanged) Q_PROPERTY(QString wallpaperPath READ wallpaperPath NOTIFY themeChanged) + //fonts + Q_PROPERTY(QFont defaultFont READ defaultFont NOTIFY defaultFontChanged) + Q_PROPERTY(QFont smallestFont READ smallestFont NOTIFY smallestFontChanged) public: enum ColorRole { @@ -304,6 +307,9 @@ class PLASMA_EXPORT Theme : public QObject */ KPluginInfo pluginInfo() const; + QFont defaultFont() const; + QFont smallestFont() const; + Q_SIGNALS: /** * Emitted when the user changes the theme. Stylesheet usage, colors, etc. should @@ -315,6 +321,9 @@ class PLASMA_EXPORT Theme : public QObject */ void themeChanged(); + void defaultFontChanged(); + void smallestFontChanged(); + private: friend class SvgPrivate; friend class ThemePrivate;