[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
This commit is contained in:
parent
547dade2f8
commit
639e8684e3
BIN
autotests/data/test_nonsquare.png
Normal file
BIN
autotests/data/test_nonsquare.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
@ -514,6 +514,24 @@ void IconItemTest::implicitSize()
|
|||||||
QCOMPARE(item->implicitHeight(), qreal(64));
|
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()
|
void IconItemTest::roundToIconSize()
|
||||||
{
|
{
|
||||||
QQuickItem *item = createIconItem();
|
QQuickItem *item = createIconItem();
|
||||||
|
@ -56,6 +56,7 @@ private Q_SLOTS:
|
|||||||
void windowChanged();
|
void windowChanged();
|
||||||
void paintedSize();
|
void paintedSize();
|
||||||
void implicitSize();
|
void implicitSize();
|
||||||
|
void nonSquareImplicitSize();
|
||||||
void roundToIconSize();
|
void roundToIconSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -150,11 +150,17 @@ void IconItem::setSource(const QVariant &source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sourceString.isEmpty()) {
|
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:"))) {
|
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_icon = QIcon();
|
||||||
m_imageIcon = QImage(url.toLocalFile());
|
m_imageIcon = QImage(localFile);
|
||||||
m_svgIconName.clear();
|
m_svgIconName.clear();
|
||||||
delete m_svgIcon;
|
delete m_svgIcon;
|
||||||
m_svgIcon = 0;
|
m_svgIcon = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user