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
This commit is contained in:
Marco Martin 2015-10-20 11:44:52 +02:00
parent 1a4c1d7eeb
commit c1065ccf39
5 changed files with 67 additions and 8 deletions

View File

@ -31,6 +31,7 @@
#include <kiconloader.h>
#include <kiconeffect.h>
#include <KIconTheme>
#include "fadingnode_p.h"
#include <QuickAddons/ManagedTextureNode>
@ -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()) {

View File

@ -101,6 +101,8 @@ private:
bool m_textureChanged;
bool m_sizeChanged;
bool m_svgFromIconLoader;
QPixmap m_iconPixmap;
QPixmap m_oldIconPixmap;

View File

@ -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;

View File

@ -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()) {

View File

@ -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.
*