From c1065ccf399877c0738ab50a110e35b12a34c390 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 20 Oct 2015 11:44:52 +0200 Subject: [PATCH] Theme breeze icons when loaded trough IconItem This makes IconItem try to load global icons from the theme with Plasma::Svg as well, making it assign the colors from the stylesheet if the breeze monochrome icons are treated, that should be scriptable, from some attempts i did the script seems to convert them correctly, without any change in rendering. This will automatically color monochrome breeze icons only in plasmashell, and more specifically only those that use IconItem, not QIconItem (iconitem should probably have an animation-less mode to be able to be used in taskmanager and stuff) perhaps in the future we'll be able somehow to hook all this stuff in QIconEngine to be able to use it in QWidget applications, but since QIcon does have any idea where it is, is not usable yet for things like the fullscreen fixed-dark gwenview view. Change-Id: I28e5fedabafbe8ed82a9df7614f8e2af18c6a24d REVIEW:125657 --- src/declarativeimports/core/iconitem.cpp | 39 +++++++++++++++++++----- src/declarativeimports/core/iconitem.h | 2 ++ src/plasma/private/svg_p.h | 1 + src/plasma/svg.cpp | 18 ++++++++++- src/plasma/svg.h | 15 +++++++++ 5 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/declarativeimports/core/iconitem.cpp b/src/declarativeimports/core/iconitem.cpp index 692cd8db8..f32b3d10e 100644 --- a/src/declarativeimports/core/iconitem.cpp +++ b/src/declarativeimports/core/iconitem.cpp @@ -31,6 +31,7 @@ #include #include +#include #include "fadingnode_p.h" #include @@ -43,6 +44,7 @@ IconItem::IconItem(QQuickItem *parent) m_active(false), m_textureChanged(false), m_sizeChanged(false), + m_svgFromIconLoader(false), m_colorGroup(Plasma::Theme::NormalColorGroup), m_animValue(0) { @@ -129,14 +131,25 @@ void IconItem::setSource(const QVariant &source) m_icon = QIcon(); connect(m_svgIcon, SIGNAL(repaintNeeded()), this, SLOT(loadPixmap())); - //ok, svg not available + //ok, svg not available from the plasma theme } else { - m_icon = QIcon::fromTheme(source.toString()); - delete m_svgIcon; - m_svgIcon = 0; - m_imageIcon = QImage(); - m_pixmapIcon = QPixmap(); + //try to load from iconloader an svg with Plasma::Svg + QString iconPath = KIconLoader::global()->theme()->iconPath(source.toString() + ".svg", qMin(width(), height()), KIconLoader::MatchBest); + if (iconPath.isEmpty()) { + iconPath = KIconLoader::global()->theme()->iconPath(source.toString() + ".svgz", qMin(width(), height()), KIconLoader::MatchBest); + } + m_svgFromIconLoader = !iconPath.isEmpty(); + if (m_svgFromIconLoader) { + m_svgIcon->setImagePath(iconPath); + //fail, use QIcon + } else { + m_icon = QIcon::fromTheme(source.toString()); + delete m_svgIcon; + m_svgIcon = 0; + m_imageIcon = QImage(); + m_pixmapIcon = QPixmap(); + } } } @@ -323,7 +336,19 @@ void IconItem::loadPixmap() return; } else if (m_svgIcon) { m_svgIcon->resize(size, size); - result = m_svgIcon->pixmap(m_source.toString()); + if (m_svgIcon->hasElement(m_source.toString())) { + result = m_svgIcon->pixmap(m_source.toString()); + } else if (m_svgFromIconLoader) { + QString iconPath = KIconLoader::global()->theme()->iconPath(source().toString() + ".svg", qMin(width(), height()), KIconLoader::MatchBest); + if (iconPath.isEmpty()) { + iconPath = KIconLoader::global()->theme()->iconPath(source().toString() + ".svgz", qMin(width(), height()), KIconLoader::MatchBest); + } + + if (!iconPath.isEmpty()) { + m_svgIcon->setImagePath(iconPath); + } + result = m_svgIcon->pixmap(); + } } else if (!m_icon.isNull()) { result = m_icon.pixmap(QSize(size, size) * (window() ? window()->devicePixelRatio() : qApp->devicePixelRatio())); } else if (!m_pixmapIcon.isNull()) { diff --git a/src/declarativeimports/core/iconitem.h b/src/declarativeimports/core/iconitem.h index 3ef0306fe..3abef4005 100644 --- a/src/declarativeimports/core/iconitem.h +++ b/src/declarativeimports/core/iconitem.h @@ -101,6 +101,8 @@ private: bool m_textureChanged; bool m_sizeChanged; + bool m_svgFromIconLoader; + QPixmap m_iconPixmap; QPixmap m_oldIconPixmap; diff --git a/src/plasma/private/svg_p.h b/src/plasma/private/svg_p.h index ab91c42fd..597465ebe 100644 --- a/src/plasma/private/svg_p.h +++ b/src/plasma/private/svg_p.h @@ -112,6 +112,7 @@ public: qreal scaleFactor; bool multipleImages : 1; bool themed : 1; + bool useSystemColors : 1; bool fromCurrentTheme : 1; bool applyColors : 1; bool usesColors : 1; diff --git a/src/plasma/svg.cpp b/src/plasma/svg.cpp index 37ced2284..bcceaf7ec 100644 --- a/src/plasma/svg.cpp +++ b/src/plasma/svg.cpp @@ -142,6 +142,7 @@ SvgPrivate::SvgPrivate(Svg *svg) scaleFactor(1.0), multipleImages(false), themed(false), + useSystemColors(false), fromCurrentTheme(false), applyColors(false), usesColors(false), @@ -268,7 +269,7 @@ Theme *SvgPrivate::actualTheme() Theme *SvgPrivate::cacheAndColorsTheme() { - if (themed) { + if (themed || !useSystemColors) { return actualTheme(); } else { // use a separate cache source for unthemed svg's @@ -940,6 +941,21 @@ bool Svg::fromCurrentTheme() const return d->fromCurrentTheme; } +void Svg::setUseSystemColors(bool system) +{ + if (d->useSystemColors == system) { + return; + } + + d->useSystemColors = system; + emit repaintNeeded(); +} + +bool Svg::useSystemColors() const +{ + return d->useSystemColors; +} + void Svg::setTheme(Plasma::Theme *theme) { if (!theme || theme == d->theme.data()) { diff --git a/src/plasma/svg.h b/src/plasma/svg.h index 3ad21ceca..3a4ca1d0f 100644 --- a/src/plasma/svg.h +++ b/src/plasma/svg.h @@ -395,6 +395,21 @@ public: */ bool fromCurrentTheme() const; + /** + * Sets wether the Svg uses the global system theme for its colors or + * the Plasma theme. Default is False. + * + * @since 5.16 + */ + void setUseSystemColors(bool system); + + /** + * @returns True if colors from the system theme are used. + * Default is False + * @since 5.16 + */ + bool useSystemColors() const; + /** * Sets the Plasma::Theme to use with this Svg object. *