From 859e2ce352600d762ad47a99fab8a810747d929d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Mon, 11 Nov 2013 22:51:34 +0100 Subject: [PATCH] theme.smallSpacing and theme.largeSpacing Accessors to allow centralized control of spacing in a DPI-friendly way. Will be used to unify spacing across default widget to make them look more consistent. Currently, smallSpacing is font height / 10, large is font height / 2. --- src/declarativeimports/core/theme.cpp | 20 +++++++++++++++++++- src/declarativeimports/core/theme.h | 10 ++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/declarativeimports/core/theme.cpp b/src/declarativeimports/core/theme.cpp index 91256bee4..1aba4b9f7 100644 --- a/src/declarativeimports/core/theme.cpp +++ b/src/declarativeimports/core/theme.cpp @@ -26,7 +26,7 @@ #include #include - +#include //********** Theme ************* @@ -46,6 +46,7 @@ ThemeProxy::ThemeProxy(QQmlEngine *parent) connect(this, &Plasma::Theme::themeChanged, this, &ThemeProxy::themeChanged); connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), this, SLOT(iconLoaderSettingsChanged())); + updateSpacing(); installEventFilter(qApp); } @@ -57,6 +58,7 @@ bool ThemeProxy::eventFilter(QObject *watched, QEvent *event) { if (watched == QCoreApplication::instance()) { if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) { + //updateSpacing(); defaultFontChanged(); smallestFontChanged(); } @@ -64,6 +66,13 @@ bool ThemeProxy::eventFilter(QObject *watched, QEvent *event) return QObject::eventFilter(watched, event); } +void ThemeProxy::updateSpacing() +{ + const int _s = mSize().height(); + m_smallSpacing = (int)(_s / 10); + m_largeSpacing = (int)(_s / 2); +} + QString ThemeProxy::themeName() const { return Plasma::Theme::themeName(); @@ -84,6 +93,15 @@ 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; +} bool ThemeProxy::useGlobalSettings() const { diff --git a/src/declarativeimports/core/theme.h b/src/declarativeimports/core/theme.h index 5936be7a4..a4b30eb20 100644 --- a/src/declarativeimports/core/theme.h +++ b/src/declarativeimports/core/theme.h @@ -85,6 +85,10 @@ class ThemeProxy : public Plasma::Theme */ Q_PROPERTY(QQmlPropertyMap *iconSizes READ iconSizes NOTIFY iconSizesChanged) + // layout hints + Q_PROPERTY(int smallSpacing READ smallSpacing CONSTANT) + Q_PROPERTY(int largeSpacing READ largeSpacing CONSTANT) + public: ThemeProxy(QQmlEngine *parent = 0); ~ThemeProxy(); @@ -125,6 +129,9 @@ public: int defaultIconSize() const; QQmlPropertyMap *iconSizes() const; + int smallSpacing() const; + int largeSpacing() const; + private Q_SLOTS: void iconLoaderSettingsChanged(); @@ -137,6 +144,9 @@ Q_SIGNALS: private: bool eventFilter(QObject *watched, QEvent *event); + void updateSpacing(); + int m_smallSpacing; + int m_largeSpacing; int m_defaultIconSize; QQmlPropertyMap *m_iconSizes; QQmlEngine *m_engine;