diff --git a/src/declarativeimports/core/units.cpp b/src/declarativeimports/core/units.cpp index a8953fcbc..65ee94028 100644 --- a/src/declarativeimports/core/units.cpp +++ b/src/declarativeimports/core/units.cpp @@ -39,6 +39,8 @@ Units::Units (QObject *parent) m_dpi = QApplication::desktop()->physicalDpiX(); m_dpiScale = (qreal)m_dpi / (qreal)96; + updateSpacing(); + m_iconSizes = new QQmlPropertyMap(this); iconLoaderSettingsChanged(); @@ -47,6 +49,7 @@ Units::Units (QObject *parent) themeChanged(); connect(&m_theme, SIGNAL(themeChanged()), this, SLOT(themeChanged())); + installEventFilter(qApp); } Units::~Units() @@ -158,7 +161,35 @@ void Units::printScreenInfo(QQuickItem* item) qDebug() << " gridUnit: " << QFontMetrics(QApplication::font()).boundingRect("M").size().height(); } +int Units::smallSpacing() const +{ + return m_smallSpacing; +} +int Units::largeSpacing() const +{ + return m_largeSpacing; +} + +void Units::updateSpacing() +{ + const int _s = QFontMetrics(QApplication::font()).boundingRect("M").size().height(); + if (_s != m_largeSpacing) { + m_smallSpacing = qMax(2, (int)(_s / 8)); // 1/8 of msize.height, at least 2 + m_largeSpacing = _s; // msize.height + emit spacingChanged(); + } +} + +bool Units::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == QCoreApplication::instance()) { + if (event->type() == QEvent::ApplicationFontChange || event->type() == QEvent::FontChange) { + updateSpacing(); + } + } + return QObject::eventFilter(watched, event); +} #include "units.moc" diff --git a/src/declarativeimports/core/units.h b/src/declarativeimports/core/units.h index 55a638a04..9f3581115 100644 --- a/src/declarativeimports/core/units.h +++ b/src/declarativeimports/core/units.h @@ -60,11 +60,18 @@ class Units : public QObject */ Q_PROPERTY(QQmlPropertyMap *iconSizes READ iconSizes NOTIFY iconSizesChanged) + // layout hints + Q_PROPERTY(int smallSpacing READ smallSpacing NOTIFY spacingChanged) + Q_PROPERTY(int largeSpacing READ largeSpacing NOTIFY spacingChanged) + Q_PROPERTY(qreal dpiScale READ dpiScale WRITE setDpiScale NOTIFY dpiScaleChanged) + public: Units(QObject *parent = 0); ~Units(); + bool eventFilter(QObject *watched, QEvent *event); + qreal gridUnit() const; void setDpiScale(const qreal scale); @@ -72,6 +79,10 @@ public: QQmlPropertyMap *iconSizes() const; + int smallSpacing() const; + int largeSpacing() const; + + /** * @returns the number of pixels value density independent pixels correspond to. */ @@ -93,17 +104,22 @@ Q_SIGNALS: void dpiScaleChanged(); void gridUnitChanged(); void iconSizesChanged(); + void spacingChanged(); private Q_SLOTS: void themeChanged(); void iconLoaderSettingsChanged(); private: + void updateSpacing(); + int m_gridUnit; Plasma::Theme m_theme; qreal m_dpiScale; qreal m_dpi; QQmlPropertyMap *m_iconSizes; + int m_smallSpacing; + int m_largeSpacing; }; #endif //UNITS_H diff --git a/src/plasma/theme.cpp b/src/plasma/theme.cpp index cb006cc4f..ee3a38e1e 100644 --- a/src/plasma/theme.cpp +++ b/src/plasma/theme.cpp @@ -545,17 +545,6 @@ 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 8b89cb770..2defacff9 100644 --- a/src/plasma/theme.h +++ b/src/plasma/theme.h @@ -83,10 +83,6 @@ class PLASMA_EXPORT Theme : public QObject Q_PROPERTY(int defaultIconSize READ defaultIconSize NOTIFY defaultIconSizeChanged) - // layout hints - Q_PROPERTY(int smallSpacing READ smallSpacing NOTIFY defaultFontChanged) - Q_PROPERTY(int largeSpacing READ largeSpacing NOTIFY defaultFontChanged) - public: enum ColorRole { TextColor = 0, /**< the text color to be used by items resting on the background */ @@ -336,7 +332,16 @@ class PLASMA_EXPORT Theme : public QObject */ KPluginInfo pluginInfo() const; + /** + * @return The default application font + * @since 5.0 + */ QFont defaultFont() const; + + /** + * @return The smallest readable font + * @since 5.0 + */ QFont smallestFont() const; QColor textColor() const; @@ -355,9 +360,6 @@ class PLASMA_EXPORT Theme : public QObject int defaultIconSize() const; - int smallSpacing() const; - int largeSpacing() const; - Q_INVOKABLE QSizeF mSize(const QFont &font = QApplication::font()) const; Q_SIGNALS: