From kde-commits Mon Feb 29 21:05:53 2016 From: Weng Xuetian Date: Mon, 29 Feb 2016 21:05:53 +0000 To: kde-commits Subject: [plasma-framework] /: Fix svg iconPath resolving in IconItem Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=145677996627012 Git commit 066cf0a0d7b46c60fccb945dbc0e9f858c4d6967 by Weng Xuetian. Committed on 29/02/2016 at 21:05. Pushed by xuetianweng into branch 'master'. Fix svg iconPath resolving in IconItem This fixes iconPath is not correctly set when its size changes. REVIEW: 127201 C +0 -0 autotests/data/bug359388/hicolor/22x22/apps/bug359388.svg [f= rom: autotests/data/icons/hicolor/22x22/apps/bug359388.svg - 100% similarit= y] R +0 -0 autotests/data/icons/test-theme/apps/22/tst-plasma-framework= -test-icon.svg [from: autotests/data/icons/hicolor/22x22/apps/bug359388.svg= - 100% similarity] A +763 -0 autotests/data/icons/test-theme/apps/32/tst-plasma-framework= -test-icon.svg A +317 -0 autotests/data/icons/test-theme/apps/48/konversation.svg A +39 -0 autotests/data/icons/test-theme/index.theme M +54 -5 autotests/iconitemtest.cpp M +7 -0 autotests/iconitemtest.h M +4 -4 src/declarativeimports/core/iconitem.cpp http://commits.kde.org/plasma-framework/066cf0a0d7b46c60fccb945dbc0e9f858c4= d6967 diff --git a/autotests/data/icons/hicolor/22x22/apps/bug359388.svg b/autote= sts/data/bug359388/hicolor/22x22/apps/bug359388.svg similarity index 100% copy from autotests/data/icons/hicolor/22x22/apps/bug359388.svg copy to autotests/data/bug359388/hicolor/22x22/apps/bug359388.svg diff --git a/autotests/data/icons/hicolor/22x22/apps/bug359388.svg b/autote= sts/data/icons/test-theme/apps/22/tst-plasma-framework-test-icon.svg similarity index 100% rename from autotests/data/icons/hicolor/22x22/apps/bug359388.svg rename to autotests/data/icons/test-theme/apps/22/tst-plasma-framework-test= -icon.svg diff --git a/autotests/data/icons/test-theme/apps/32/tst-plasma-framework-t= est-icon.svg b/autotests/data/icons/test-theme/apps/32/tst-plasma-framework= -test-icon.svg new file mode 100644 index 0000000..940d46d --- /dev/null +++ b/autotests/data/icons/test-theme/apps/32/tst-plasma-framework-test-ico= n.svg @@ -0,0 +1,763 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Plasm + + + + + + + + + + diff --git a/autotests/data/icons/test-theme/apps/48/konversation.svg b/aut= otests/data/icons/test-theme/apps/48/konversation.svg new file mode 100644 index 0000000..68027b8 --- /dev/null +++ b/autotests/data/icons/test-theme/apps/48/konversation.svg @@ -0,0 +1,317 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/autotests/data/icons/test-theme/index.theme b/autotests/data/i= cons/test-theme/index.theme new file mode 100644 index 0000000..52a7275 --- /dev/null +++ b/autotests/data/icons/test-theme/index.theme @@ -0,0 +1,39 @@ +[Icon Theme] +Name=3DUnittest Theme + +DisplayDepth=3D32 + +Inherits=3Dbreeze + +DesktopDefault=3D48 +DesktopSizes=3D16,22,32,48,64,128,256 +ToolbarDefault=3D22 +ToolbarSizes=3D16,22,32,48 +MainToolbarDefault=3D22 +MainToolbarSizes=3D16,22,32,48 +SmallDefault=3D16 +SmallSizes=3D16,22,32,48 +PanelDefault=3D32 +PanelSizes=3D16,22,32,48,64,128,256 +DialogDefault=3D32 +DialogSizes=3D16,22,32,48,64,128,256 + +########## Directories +########## ordered by category and alphabetically + +Directories=3Dapps/22,apps/32 + +[apps/22] +Size=3D22 +Context=3DApplications +Type=3DFixed + +[apps/32] +Size=3D32 +Context=3DApplications +Type=3DFixed + +[apps/48] +Size=3D48 +Context=3DApplications +Type=3DFixed diff --git a/autotests/iconitemtest.cpp b/autotests/iconitemtest.cpp index ea98c9d..9b36670 100644 --- a/autotests/iconitemtest.cpp +++ b/autotests/iconitemtest.cpp @@ -46,6 +46,26 @@ static bool imageIsEmpty(const QImage &img) = void IconItemTest::initTestCase() { + // make our theme in search path + qputenv("XDG_DATA_DIRS", + qgetenv("XDG_DATA_DIRS") + ":" + QFINDTESTDATA("data").toLocal= 8Bit()); + + // set default icon theme to test-theme + QStandardPaths::setTestModeEnabled(true); + + QString configPath =3D QStandardPaths::writableLocation(QStandardPaths= ::GenericConfigLocation); + + if(!QDir(configPath).mkpath(QStringLiteral("."))) { + qFatal("Failed to create test configuration directory."); + } + + QFile::remove(configPath); + + KConfigGroup cg(KSharedConfig::openConfig(), "Icons"); + cg.writeEntry("Theme", "test-theme"); + KConfigGroup plasmaConfig(KSharedConfig::openConfig("plasmarc"), "Them= e"); + plasmaConfig.writeEntry("name", "default"); + m_view =3D new QQuickView(); m_view->setSource(QUrl::fromLocalFile(QFINDTESTDATA("data/view.qml"))); m_view->show(); @@ -88,6 +108,11 @@ QImage IconItemTest::grabImage(QQuickItem *item) return grab->image(); } = +Plasma::Svg *IconItemTest::findPlasmaSvg(QQuickItem *item) +{ + return item->findChild(); +} + // ------ Tests void IconItemTest::invalidIcon() { @@ -106,7 +131,7 @@ void IconItemTest::invalidIcon() void IconItemTest::usesPlasmaTheme() { Plasma::Theme theme; - if (!theme.themeName().startsWith("breeze")) { + if (!theme.themeName().startsWith("default")) { QSKIP("Current Plasma theme is not Breeze."); } = @@ -132,7 +157,7 @@ void IconItemTest::usesPlasmaTheme() = img1 =3D grabImage(item2); // This depends on konversation icon being different in Plasma Breeze = theme - // and normal Breeze icon theme + // and our test icon theme QVERIFY(img1 !=3D img2); } = @@ -191,23 +216,47 @@ void IconItemTest::bug_359388() { QString name("bug359388"); KIconLoader iconLoader("tst_plasma-framework"); + QIcon customThemeIcon(new KIconEngine(name, &iconLoader)); if (iconLoader.hasIcon(name)) { QSKIP("Current icon theme has 'bug359388' icon."); } = - iconLoader.addAppDir("tst_plasma-framework", QFINDTESTDATA("data/icons= ")); - QIcon customThemeIcon(new KIconEngine(name, &iconLoader)); + iconLoader.addAppDir("tst_plasma-framework", QFINDTESTDATA("data/bug35= 9388")); = QQuickItem *item1 =3D createIconItem(); item1->setProperty("source", customThemeIcon); QVERIFY(item1->property("valid").toBool()); = QQuickItem *item2 =3D createIconItem(); - item2->setProperty("source", QIcon(QFINDTESTDATA("data/icons/hicolor/2= 2x22/apps/" + name + ".svg"))); + item2->setProperty("source", QIcon(QFINDTESTDATA("data/bug359388/hicol= or/22x22/apps/" + name + ".svg"))); QVERIFY(item2->property("valid").toBool()); = QCOMPARE(grabImage(item1), grabImage(item2)); } = +void IconItemTest::loadSvg() +{ + QString name("tst-plasma-framework-test-icon"); + + QQuickItem *item =3D createIconItem(); + item->setProperty("animated", false); + item->setSize(QSize(22, 22)); + item->setProperty("source", name); + QVERIFY(item->property("valid").toBool()); + + Plasma::Svg *svg; + svg =3D findPlasmaSvg(item); + Q_ASSERT(svg); + QCOMPARE(svg->imagePath(), QFINDTESTDATA("data/icons/test-theme/apps/2= 2/" + name + ".svg")); + + // we only have 32x32 and 22x22 version in the theme, thus 32x32 is a = better match. + item->setSize(QSize(64, 64)); + // just to update the icon + grabImage(item); + svg =3D findPlasmaSvg(item); + Q_ASSERT(svg); + QCOMPARE(svg->imagePath(), QFINDTESTDATA("data/icons/test-theme/apps/3= 2/" + name + ".svg")); +} + QTEST_MAIN(IconItemTest) = diff --git a/autotests/iconitemtest.h b/autotests/iconitemtest.h index 9fd3063..b27680a 100644 --- a/autotests/iconitemtest.h +++ b/autotests/iconitemtest.h @@ -23,6 +23,11 @@ #include #include = +namespace Plasma +{ +class Svg; +} + class IconItemTest : public QObject { Q_OBJECT @@ -36,10 +41,12 @@ private Q_SLOTS: void animation(); void animationAfterHide(); void bug_359388(); + void loadSvg(); = private: QQuickItem *createIconItem(); QImage grabImage(QQuickItem *item); + Plasma::Svg *findPlasmaSvg(QQuickItem *item); = QQuickView *m_view; }; diff --git a/src/declarativeimports/core/iconitem.cpp b/src/declarativeimpo= rts/core/iconitem.cpp index c65a9a7..9552847 100644 --- a/src/declarativeimports/core/iconitem.cpp +++ b/src/declarativeimports/core/iconitem.cpp @@ -134,9 +134,9 @@ void IconItem::setSource(const QVariant &source) const auto *iconTheme =3D KIconLoader::global()->theme(); QString iconPath; if (iconTheme) { - iconTheme->iconPath(sourceString + QLatin1String(".svg= "), qMin(width(), height()), KIconLoader::MatchBest); + iconPath =3D iconTheme->iconPath(sourceString + QLatin= 1String(".svg"), qMin(width(), height()), KIconLoader::MatchBest); if (iconPath.isEmpty()) { - iconPath =3D iconTheme->iconPath(sourceString + QL= atin1String(".svg"), qMin(width(), height()), KIconLoader::MatchBest); + iconPath =3D iconTheme->iconPath(sourceString + QL= atin1String(".svgz"), qMin(width(), height()), KIconLoader::MatchBest); } } else { qWarning() << "KIconLoader has no theme set"; @@ -412,9 +412,9 @@ void IconItem::loadPixmap() const auto *iconTheme =3D KIconLoader::global()->theme(); QString iconPath; if (iconTheme) { - QString iconPath =3D iconTheme->iconPath(source().toString= () + QLatin1String(".svg"), qMin(width(), height()), KIconLoader::MatchBest= ); + iconPath =3D iconTheme->iconPath(source().toString() + QLa= tin1String(".svg"), qMin(width(), height()), KIconLoader::MatchBest); if (iconPath.isEmpty()) { - iconPath =3D iconTheme->iconPath(source().toString() += QLatin1String(".svg"), qMin(width(), height()), KIconLoader::MatchBest); + iconPath =3D iconTheme->iconPath(source().toString() += QLatin1String(".svgz"), qMin(width(), height()), KIconLoader::MatchBest); } } else { qWarning() << "KIconLoader has no theme set";