From 639e8684e3b39b43238e1812c1d7f430f86366e3 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 15 Jan 2018 10:22:18 +0100 Subject: [PATCH] [Icon Item] Treat sources starting with a slash as local file We have a special case for sources starting with "file://" but a "/" also represents an absolute path and shouldn't conflict with icon theme names. Kicker sets a custom image as local path and then we would end up trying to load it as a QIcon::fromTheme eventually. This will cause the implicit size of the icon item to stay at its default as we only check a custom implicit size for a source QImage or an SVG. Moreover, this potentially introduces scaling artefacts. Differential Revision: https://phabricator.kde.org/D9812 --- autotests/data/test_nonsquare.png | Bin 0 -> 2827 bytes autotests/iconitemtest.cpp | 18 ++++++++++++++++++ autotests/iconitemtest.h | 1 + src/declarativeimports/core/iconitem.cpp | 12 +++++++++--- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 autotests/data/test_nonsquare.png diff --git a/autotests/data/test_nonsquare.png b/autotests/data/test_nonsquare.png new file mode 100644 index 0000000000000000000000000000000000000000..55e8729437567fbc71c292b8de1204cc33eecdcb GIT binary patch literal 2827 zcmV+m3-t7fP)u6uo>EPnf+Hs0fTS~1`SGzMV6>V_}v?^}pQN;2n_`vd#ghxyW zBoMNHIA(hd!Gzp<1Ks=i@BDJk`Tc&$H|N~^&b_h0JJ5lFfn;p09RS0h6Gm7Jl)wm! zff5*DF;D^{ECxzogvCG!Y-J4}O&-@QZN}-g(vWbsy0?ZB9vG(PeWgWNutV*&PJqH zBot}|ww~E)k@r#l@E{BHAaKV3(`qC~hc5d3!lpWGxsT8wQWfgEP+= zfv$lFofnE#eyflmNq~SO003OWI)XXFmSuGAi<;GQ)b8b zXTsX~(^kid6UPzSpVob9vZ!W4N^lBgbI%2=oj)xrmV=!G9PJzlwuZh2%KSx&BH`!k zN7?)Uz+>~^!gGOuBY;Aq!0^~GG+GU%J^{eT$p>zHH)ymP$W$^&RZ@dKbmadqXb~36 zhDC=P1iA)dN9+!~5dH$e?!D%j1uE*f$puRodVLo!>a*-CAhWQTj z31jz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cO6c`yFnX>Ps zZj#V8r!?^3ouL5GCTlZ!yn~$sB191;_oo6&@+XTqBdqkWbVB=b*JY!96>0^c?ZkC5 zxLwB>+DXIukvWy~&5@gDbaNk>Sdu?k&>}36gUF(9&8CP=c-;SSg6*5;Z;bYT@Xte7 zHY~*X#u@27{aE1Mxuq!txdmZQ{2r6~Qi&z`lLalp+7Y`0x3=9vUSb|rh*y~W?Qyho zL|$SZijs-fIM;`+qolFK=(rYXi@`Se_R6Z&<*q`dI+}ND|SEhf_$0xGE_WY zF)J?IEyLkR)Y(-FX;Q0G?w7ae~`IVos_lLbW*Ktn&Jfyq89Wg#J$Xt|(b&swC z%Z3FVbSP~qHQ2i8#M1o9z$yh&0Y`v%Nj%~u@n(%vYt>kHVx38kD&<|sL+Yccgw-+8 zKM{%ki3WZ5UED`_WAiWOBRwpg@aH9gu7UVE^=kn4>S}f@JFsmH-@e?6TogAHTUA(q zW%-ithXxP!m5&0D5@($i>$@uLgT>b0FGWg zid7}6u=0zQXd5v7XFmWG|5A+AC96@>Rb#Zz#N-6J?;0LvH%ptb_|Re$)D%qnY~aw? z5RP6witxg4!t;64`J@X=^0yS)|9B0!cZlrg;s=RP0(XHs_#8fXY#zq7EH<-n}^}CVYCmlqrSHu3XNjgv34vwM2aF2>>dnfo-@>1 zHDoFoewY7_D?L}HeFA5;U`hTn!79RH`13Po3Zx8k3r1KBl)wm!ff5*DF;D^{ECxzo dgvCG!{{?zt0GL$iPRalP002ovPDHLkV1m=&aCHCx literal 0 HcmV?d00001 diff --git a/autotests/iconitemtest.cpp b/autotests/iconitemtest.cpp index 50c3b6ab2..d1cc7a95d 100644 --- a/autotests/iconitemtest.cpp +++ b/autotests/iconitemtest.cpp @@ -514,6 +514,24 @@ void IconItemTest::implicitSize() QCOMPARE(item->implicitHeight(), qreal(64)); } +void IconItemTest::nonSquareImplicitSize() +{ + QQuickItem *item1 = createIconItem(); + + // Both file:///foo and /foo must behave the same + item1->setProperty("source", QFINDTESTDATA("data/test_nonsquare.png")); + + QCOMPARE(item1->implicitWidth(), qreal(150)); + QCOMPARE(item1->implicitHeight(), qreal(50)); + + QQuickItem *item2 = createIconItem(); + + item2->setProperty("source", QUrl::fromLocalFile(QFINDTESTDATA("data/test_nonsquare.png"))); + + QCOMPARE(item2->implicitWidth(), item1->implicitWidth()); + QCOMPARE(item2->implicitHeight(), item1->implicitHeight()); +} + void IconItemTest::roundToIconSize() { QQuickItem *item = createIconItem(); diff --git a/autotests/iconitemtest.h b/autotests/iconitemtest.h index 842682932..ef1ee3ede 100644 --- a/autotests/iconitemtest.h +++ b/autotests/iconitemtest.h @@ -56,6 +56,7 @@ private Q_SLOTS: void windowChanged(); void paintedSize(); void implicitSize(); + void nonSquareImplicitSize(); void roundToIconSize(); private: diff --git a/src/declarativeimports/core/iconitem.cpp b/src/declarativeimports/core/iconitem.cpp index 1327153fa..5e62172cd 100644 --- a/src/declarativeimports/core/iconitem.cpp +++ b/src/declarativeimports/core/iconitem.cpp @@ -150,11 +150,17 @@ void IconItem::setSource(const QVariant &source) } if (!sourceString.isEmpty()) { - //If a url in the form file:// is passed, take the image pointed by that from disk + // If a file:// URL or a absolute path is passed, take the image pointed by that from disk + QString localFile; if (sourceString.startsWith(QLatin1String("file:"))) { - const QUrl url(sourceString); + localFile = QUrl(sourceString).toLocalFile(); + } else if (sourceString.startsWith(QLatin1Char('/'))) { + localFile = sourceString; + } + + if (!localFile.isEmpty()) { m_icon = QIcon(); - m_imageIcon = QImage(url.toLocalFile()); + m_imageIcon = QImage(localFile); m_svgIconName.clear(); delete m_svgIcon; m_svgIcon = 0;