From a5f25771a2887c90fa72460f5323c68b6d7e1008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Thu, 19 Jun 2014 03:12:27 +0200 Subject: [PATCH] Reduce Units footprint - internally, smallSpacing, largeSpacing and gridUnit are entangled, and all use the font's rendered size. This means we can save a QFontMetrics construction by merging the updating of these three props. - A wanted side-effect is that the updating of spacing and gridunit now happens at the same time, so they're updated consistently in the UI. - Also, use compile-time connects for the Plasma::Theme::themeChanged connection --- src/declarativeimports/core/units.cpp | 39 +++++++++++---------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/declarativeimports/core/units.cpp b/src/declarativeimports/core/units.cpp index 07c451313..a08b773e0 100644 --- a/src/declarativeimports/core/units.cpp +++ b/src/declarativeimports/core/units.cpp @@ -45,16 +45,11 @@ Units::Units(QObject *parent) m_longDuration(defaultLongDuration) // default base value for animations { m_iconSizes = new QQmlPropertyMap(this); - updateDevicePixelRatio(); - updateSpacing(); - - //iconLoaderSettingsChanged(); + updateDevicePixelRatio(); // also updates icon sizes + updateSpacing(); // updates gridUnit and *Spacing properties connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), this, SLOT(iconLoaderSettingsChanged())); - - themeChanged(); - connect(&m_theme, SIGNAL(themeChanged()), - this, SLOT(themeChanged())); + connect(&m_theme, &Plasma::Theme::themeChanged, this, &Units::updateSpacing); QCoreApplication::instance()->installEventFilter(this); const QString configFile = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + plasmarc; @@ -166,18 +161,6 @@ int Units::gridUnit() const return m_gridUnit; } -void Units::themeChanged() -{ - int gridUnit = QFontMetrics(QGuiApplication::font()).boundingRect("M").height(); - if (gridUnit % 2 != 0) { - gridUnit++; - } - if (gridUnit != m_gridUnit) { - m_gridUnit = gridUnit; - emit gridUnitChanged(); - } -} - int Units::smallSpacing() const { return m_smallSpacing; @@ -190,10 +173,18 @@ int Units::largeSpacing() const void Units::updateSpacing() { - const int _s = QFontMetrics(QGuiApplication::font()).boundingRect("M").size().height(); - if (_s != m_largeSpacing) { - m_smallSpacing = qMax(2, (int)(_s / 4)); // 1/4 of gridUnit, at least 2 - m_largeSpacing = _s; // msize.height + int gridUnit = QFontMetrics(QGuiApplication::font()).boundingRect("M").height();; + if (gridUnit % 2 != 0) { + gridUnit++; + } + if (gridUnit != m_gridUnit) { + m_gridUnit = gridUnit; + emit gridUnitChanged(); + } + + if (gridUnit != m_largeSpacing) { + m_smallSpacing = qMax(2, (int)(gridUnit / 4)); // 1/4 of gridUnit, at least 2 + m_largeSpacing = gridUnit; // msize.height emit spacingChanged(); } }