IconItem: Fix changing color of svg icons loaded from icon theme
Connect to repaintNeeded when creating Plasma::Svg. REVIEW: 127207
This commit is contained in:
parent
066cf0a0d7
commit
30368e1d45
@ -113,6 +113,15 @@ Plasma::Svg *IconItemTest::findPlasmaSvg(QQuickItem *item)
|
||||
return item->findChild<Plasma::Svg *>();
|
||||
}
|
||||
|
||||
void IconItemTest::changeTheme(Plasma::Theme *theme, const QString &themeName)
|
||||
{
|
||||
if (theme->themeName() != themeName) {
|
||||
QSignalSpy spy(theme, SIGNAL(themeChanged()));
|
||||
theme->setThemeName(themeName);
|
||||
spy.wait();
|
||||
}
|
||||
}
|
||||
|
||||
// ------ Tests
|
||||
void IconItemTest::invalidIcon()
|
||||
{
|
||||
@ -258,5 +267,32 @@ void IconItemTest::loadSvg()
|
||||
QCOMPARE(svg->imagePath(), QFINDTESTDATA("data/icons/test-theme/apps/32/" + name + ".svg"));
|
||||
}
|
||||
|
||||
void IconItemTest::themeChange()
|
||||
{
|
||||
// Icon from Plasma theme
|
||||
QQuickItem *item1 = createIconItem();
|
||||
item1->setProperty("animated", false);
|
||||
item1->setProperty("source", "zoom-fit-height");
|
||||
Plasma::Svg *svg1 = item1->findChild<Plasma::Svg*>();
|
||||
changeTheme(svg1->theme(), "breeze-light");
|
||||
QImage img1 = grabImage(item1);
|
||||
changeTheme(svg1->theme(), "breeze-dark");
|
||||
QImage img2 = grabImage(item1);
|
||||
QVERIFY(img1 != img2);
|
||||
|
||||
// Icon from icon theme
|
||||
QQuickItem *item2 = createIconItem();
|
||||
item2->setProperty("animated", false);
|
||||
item2->setProperty("width", 22);
|
||||
item2->setProperty("height", 22);
|
||||
item2->setProperty("source", "tst-plasma-framework-test-icon");
|
||||
Plasma::Svg *svg2 = item2->findChild<Plasma::Svg*>();
|
||||
changeTheme(svg2->theme(), "breeze-light");
|
||||
img1 = grabImage(item2);
|
||||
changeTheme(svg2->theme(), "breeze-dark");
|
||||
img2 = grabImage(item2);
|
||||
QVERIFY(img1 != img2);
|
||||
}
|
||||
|
||||
QTEST_MAIN(IconItemTest)
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
namespace Plasma
|
||||
{
|
||||
class Svg;
|
||||
class Theme;
|
||||
}
|
||||
|
||||
class IconItemTest : public QObject
|
||||
@ -42,11 +43,13 @@ private Q_SLOTS:
|
||||
void animationAfterHide();
|
||||
void bug_359388();
|
||||
void loadSvg();
|
||||
void themeChange();
|
||||
|
||||
private:
|
||||
QQuickItem *createIconItem();
|
||||
QImage grabImage(QQuickItem *item);
|
||||
Plasma::Svg *findPlasmaSvg(QQuickItem *item);
|
||||
void changeTheme(Plasma::Theme *theme, const QString &themeName);
|
||||
|
||||
QQuickView *m_view;
|
||||
};
|
||||
|
@ -115,6 +115,7 @@ void IconItem::setSource(const QVariant &source)
|
||||
m_svgIcon = new Plasma::Svg(this);
|
||||
m_svgIcon->setColorGroup(m_colorGroup);
|
||||
m_svgIcon->setDevicePixelRatio((window() ? window()->devicePixelRatio() : qApp->devicePixelRatio()));
|
||||
connect(m_svgIcon, &Plasma::Svg::repaintNeeded, this, &IconItem::schedulePixmapUpdate);
|
||||
}
|
||||
|
||||
if (m_usesPlasmaTheme) {
|
||||
@ -126,7 +127,6 @@ void IconItem::setSource(const QVariant &source)
|
||||
//success?
|
||||
if (m_svgIcon->isValid() && m_svgIcon->hasElement(sourceString)) {
|
||||
m_icon = QIcon();
|
||||
connect(m_svgIcon, SIGNAL(repaintNeeded()), this, SLOT(schedulePixmapUpdate()));
|
||||
|
||||
//ok, svg not available from the plasma theme
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user