From ea2a4db7ab813a0effbb416b887a0a86bd4525a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Mon, 13 Jan 2014 01:31:46 +0100 Subject: [PATCH] Move spacing, stylesheet and mSize into Plasma::Theme --- src/declarativeimports/core/theme.cpp | 30 --------------------------- src/declarativeimports/core/theme.h | 11 ---------- src/plasma/private/theme_p.cpp | 10 ++++++++- src/plasma/private/theme_p.h | 5 +++++ src/plasma/theme.cpp | 17 ++++++++++++++- src/plasma/theme.h | 12 ++++++++++- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/src/declarativeimports/core/theme.cpp b/src/declarativeimports/core/theme.cpp index 9db454f26..284154db0 100644 --- a/src/declarativeimports/core/theme.cpp +++ b/src/declarativeimports/core/theme.cpp @@ -42,47 +42,17 @@ ThemeProxy::ThemeProxy(QQmlEngine *parent) connect(this, &Plasma::Theme::themeChanged, this, &ThemeProxy::themeChanged); connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), this, SLOT(iconLoaderSettingsChanged())); - - updateSpacing(); } ThemeProxy::~ThemeProxy() { } -void ThemeProxy::updateSpacing() -{ - const int _s = mSize().height(); - m_smallSpacing = qMax(2, (int)(_s / 8)); - m_largeSpacing = _s; -} - -QSizeF ThemeProxy::mSize(const QFont &font) const -{ - return QFontMetrics(font).boundingRect("M").size(); -} - -int ThemeProxy::smallSpacing() const -{ - return m_smallSpacing; -} - -int ThemeProxy::largeSpacing() const -{ - return m_largeSpacing; -} - QString ThemeProxy::wallpaperPathForSize(int width, int height) const { return Plasma::Theme::wallpaperPath(QSize(width, height)); } -QString ThemeProxy::styleSheet() const -{ - return Plasma::Theme::styleSheet(QString()); -} - - void ThemeProxy::iconLoaderSettingsChanged() { m_iconSizes->insert("desktop", QVariant(KIconLoader::global()->currentSize(KIconLoader::Desktop))); diff --git a/src/declarativeimports/core/theme.h b/src/declarativeimports/core/theme.h index 76c3ad869..8c5841bc2 100644 --- a/src/declarativeimports/core/theme.h +++ b/src/declarativeimports/core/theme.h @@ -59,20 +59,10 @@ public: ThemeProxy(QQmlEngine *parent = 0); ~ThemeProxy(); - /** - * @return The size of an uppercase M in a font, defaultFont() by default - */ - Q_INVOKABLE QSizeF mSize(const QFont &font = QApplication::font()) const; - Q_INVOKABLE QString wallpaperPathForSize(int width=-1, int height=-1) const; - QString styleSheet() const; - QQmlPropertyMap *iconSizes() const; - int smallSpacing() const; - int largeSpacing() const; - private Q_SLOTS: void iconLoaderSettingsChanged(); @@ -81,7 +71,6 @@ Q_SIGNALS: void iconSizesChanged(); private: - void updateSpacing(); int m_smallSpacing; int m_largeSpacing; QQmlPropertyMap *m_iconSizes; diff --git a/src/plasma/private/theme_p.cpp b/src/plasma/private/theme_p.cpp index 97d19599c..93fc266ec 100644 --- a/src/plasma/private/theme_p.cpp +++ b/src/plasma/private/theme_p.cpp @@ -52,7 +52,6 @@ ThemePrivate::ThemePrivate(QObject *parent) colorScheme(QPalette::Active, KColorScheme::Window, KSharedConfigPtr(0)), buttonColorScheme(QPalette::Active, KColorScheme::Button, KSharedConfigPtr(0)), viewColorScheme(QPalette::Active, KColorScheme::View, KSharedConfigPtr(0)), - defaultIconSize(KIconLoader::global()->currentSize(KIconLoader::Desktop)), defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME), defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX), defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH), @@ -60,6 +59,7 @@ ThemePrivate::ThemePrivate(QObject *parent) pixmapCache(0), cacheSize(0), cachesToDiscard(NoCache), + defaultIconSize(KIconLoader::global()->currentSize(KIconLoader::Desktop)), locolor(false), compositingActive(KWindowSystem::self()->compositingActive()), blurActive(false), @@ -91,6 +91,7 @@ ThemePrivate::ThemePrivate(QObject *parent) #endif } installEventFilter(qApp); + updateSpacing(); } ThemePrivate::~ThemePrivate() @@ -585,6 +586,13 @@ bool ThemePrivate::eventFilter(QObject *watched, QEvent *event) return QObject::eventFilter(watched, event); } +void ThemePrivate::updateSpacing() +{ + const int _s = QFontMetrics(QApplication::font()).boundingRect("M").size().height(); + smallSpacing = qMax(2, (int)(_s / 8)); + largeSpacing = _s; +} + } #include "moc_theme_p.cpp" diff --git a/src/plasma/private/theme_p.h b/src/plasma/private/theme_p.h index 25fc1cd08..6c490d7c5 100644 --- a/src/plasma/private/theme_p.h +++ b/src/plasma/private/theme_p.h @@ -77,6 +77,7 @@ public: bool useCache(); void setThemeName(const QString &themeName, bool writeSettings); void processWallpaperSettings(KConfigBase *metadata); + void updateSpacing(); const QString processStyleSheet(const QString &css); const QString svgStyleSheet(); @@ -137,6 +138,8 @@ public: CacheTypes cachesToDiscard; int defaultIconSize; + int smallSpacing; + int largeSpacing; bool locolor : 1; bool compositingActive : 1; @@ -150,3 +153,5 @@ public: } #endif + +extern const QString s; diff --git a/src/plasma/theme.cpp b/src/plasma/theme.cpp index 55b820a8c..799d122ac 100644 --- a/src/plasma/theme.cpp +++ b/src/plasma/theme.cpp @@ -20,7 +20,6 @@ #include "theme.h" #include "private/theme_p.h" -#include #include #include #include @@ -566,6 +565,22 @@ int Theme::enormousIconSize() const return KIconLoader::SizeEnormous; } +QSizeF Theme::mSize(const QFont &font) const +{ + return QFontMetrics(font).boundingRect("M").size(); +} + +int Theme::smallSpacing() const +{ + return d->smallSpacing; +} + +int Theme::largeSpacing() const +{ + return d->largeSpacing; +} + + } diff --git a/src/plasma/theme.h b/src/plasma/theme.h index db62484b3..b718232c8 100644 --- a/src/plasma/theme.h +++ b/src/plasma/theme.h @@ -21,6 +21,8 @@ #ifndef PLASMA_THEME_H #define PLASMA_THEME_H +#include +#include #include #include @@ -60,6 +62,9 @@ class PLASMA_EXPORT Theme : public QObject Q_PROPERTY(QFont defaultFont READ defaultFont NOTIFY defaultFontChanged) Q_PROPERTY(QFont smallestFont READ smallestFont NOTIFY smallestFontChanged) + // stylesheet + Q_PROPERTY(QString styleSheet READ styleSheet NOTIFY themeChanged) + // colors Q_PROPERTY(QColor textColor READ textColor NOTIFY themeChanged) Q_PROPERTY(QColor highlightColor READ highlightColor NOTIFY themeChanged) @@ -349,7 +354,6 @@ class PLASMA_EXPORT Theme : public QObject QColor viewBackgroundColor() const; QColor viewHoverColor() const; QColor viewFocusColor() const; - QString styleSheet() const; int smallIconSize() const; int smallMediumIconSize() const; @@ -359,6 +363,12 @@ class PLASMA_EXPORT Theme : public QObject int enormousIconSize() const; int defaultIconSize() const; + int smallSpacing() const; + int largeSpacing() const; + + Q_INVOKABLE QSizeF mSize(const QFont &font = QApplication::font()) const; + + Q_SIGNALS: /** * Emitted when the user changes the theme. Stylesheet usage, colors, etc. should