aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-04-25 17:05:57 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-04-26 07:34:19 +0000
commit86f546dc658106eab9ef489b5473a5407ff8c3c0 (patch)
treeed473cb9f016d9716b3bc38a93d30787d33d3351
parent8b9f4364ba05c51ba4a0d8edcd53ea411824a590 (diff)
QQuickIconImage: fix file selectors for named theme icons
QQuickIconImage needs to be associated with a QML context to be able to call QQmlContext::resolvedUrl(), which in turn passes it to the URL interceptor aka. QQmlFileSelector. Change-Id: Iff34fb8316c765ac0ff04d5d7a6ab23002b31385 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quickcontrols2/qquickiconimage.cpp12
-rw-r--r--src/quickcontrols2/qquickiconlabel.cpp1
-rw-r--r--tests/auto/qquickiconimage/data/fileSelectors.qml16
-rw-r--r--tests/auto/qquickiconimage/icons/testtheme/22x22/actions/+testselector/appointment-new.pngbin0 -> 1146 bytes
-rw-r--r--tests/auto/qquickiconimage/icons/testtheme/22x22/actions/+testselector/appointment-new@2x.pngbin0 -> 256 bytes
-rw-r--r--tests/auto/qquickiconimage/icons/testtheme/22x22@2/actions/+testselector/appointment-new.pngbin0 -> 256 bytes
-rw-r--r--tests/auto/qquickiconimage/resources.qrc3
-rw-r--r--tests/auto/qquickiconimage/tst_qquickiconimage.cpp28
8 files changed, 58 insertions, 2 deletions
diff --git a/src/quickcontrols2/qquickiconimage.cpp b/src/quickcontrols2/qquickiconimage.cpp
index d392b72a..629fc0cb 100644
--- a/src/quickcontrols2/qquickiconimage.cpp
+++ b/src/quickcontrols2/qquickiconimage.cpp
@@ -80,8 +80,16 @@ void QQuickIconImagePrivate::updateIcon()
const qreal dpr = calculateDevicePixelRatio();
const QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(icon, size * dpr, qCeil(dpr));
- url = entry ? QUrl::fromLocalFile(entry->filename) : source;
- isThemeIcon = entry != nullptr;
+
+ if (entry) {
+ QQmlContext *context = qmlContext(q);
+ const QUrl entryUrl = QUrl::fromLocalFile(entry->filename);
+ url = context ? context->resolvedUrl(entryUrl) : entryUrl;
+ isThemeIcon = true;
+ } else {
+ url = source;
+ isThemeIcon = false;
+ }
q->load();
updatingIcon = false;
diff --git a/src/quickcontrols2/qquickiconlabel.cpp b/src/quickcontrols2/qquickiconlabel.cpp
index d1ac8349..61151f28 100644
--- a/src/quickcontrols2/qquickiconlabel.cpp
+++ b/src/quickcontrols2/qquickiconlabel.cpp
@@ -96,6 +96,7 @@ bool QQuickIconLabelPrivate::createImage()
image->setSource(icon->source());
image->setSourceSize(QSize(icon->width(), icon->height()));
image->setColor(icon->color());
+ QQmlEngine::setContextForObject(image, qmlContext(q));
if (componentComplete)
completeComponent(image);
return true;
diff --git a/tests/auto/qquickiconimage/data/fileSelectors.qml b/tests/auto/qquickiconimage/data/fileSelectors.qml
new file mode 100644
index 00000000..e3ed3857
--- /dev/null
+++ b/tests/auto/qquickiconimage/data/fileSelectors.qml
@@ -0,0 +1,16 @@
+import QtQuick 2.9
+import QtQuick.Controls 2.3
+import QtQuick.Controls.impl 2.3
+
+Row {
+ width: 200
+ height: 200
+
+ IconImage {
+ name: "appointment-new"
+ sourceSize: Qt.size(22, 22)
+ }
+ Image {
+ source: "qrc:/icons/testtheme/22x22/actions/appointment-new.png"
+ }
+}
diff --git a/tests/auto/qquickiconimage/icons/testtheme/22x22/actions/+testselector/appointment-new.png b/tests/auto/qquickiconimage/icons/testtheme/22x22/actions/+testselector/appointment-new.png
new file mode 100644
index 00000000..c6ceca43
--- /dev/null
+++ b/tests/auto/qquickiconimage/icons/testtheme/22x22/actions/+testselector/appointment-new.png
Binary files differ
diff --git a/tests/auto/qquickiconimage/icons/testtheme/22x22/actions/+testselector/appointment-new@2x.png b/tests/auto/qquickiconimage/icons/testtheme/22x22/actions/+testselector/appointment-new@2x.png
new file mode 100644
index 00000000..f380ebb6
--- /dev/null
+++ b/tests/auto/qquickiconimage/icons/testtheme/22x22/actions/+testselector/appointment-new@2x.png
Binary files differ
diff --git a/tests/auto/qquickiconimage/icons/testtheme/22x22@2/actions/+testselector/appointment-new.png b/tests/auto/qquickiconimage/icons/testtheme/22x22@2/actions/+testselector/appointment-new.png
new file mode 100644
index 00000000..f380ebb6
--- /dev/null
+++ b/tests/auto/qquickiconimage/icons/testtheme/22x22@2/actions/+testselector/appointment-new.png
Binary files differ
diff --git a/tests/auto/qquickiconimage/resources.qrc b/tests/auto/qquickiconimage/resources.qrc
index 76757d4e..6558b039 100644
--- a/tests/auto/qquickiconimage/resources.qrc
+++ b/tests/auto/qquickiconimage/resources.qrc
@@ -4,6 +4,9 @@
<file>icons/testtheme/22x22/actions/appointment-new.png</file>
<file>icons/testtheme/22x22/actions/appointment-new@2x.png</file>
<file>icons/testtheme/22x22@2/actions/appointment-new.png</file>
+ <file>icons/testtheme/22x22/actions/+testselector/appointment-new.png</file>
+ <file>icons/testtheme/22x22/actions/+testselector/appointment-new@2x.png</file>
+ <file>icons/testtheme/22x22@2/actions/+testselector/appointment-new.png</file>
<file>icons/testtheme/index.theme</file>
<file>icons/testtheme/appointment-new.svg</file>
<file>icons/testtheme/22x22/actions/color-test-original.png</file>
diff --git a/tests/auto/qquickiconimage/tst_qquickiconimage.cpp b/tests/auto/qquickiconimage/tst_qquickiconimage.cpp
index 86bd2f2c..4e4afb13 100644
--- a/tests/auto/qquickiconimage/tst_qquickiconimage.cpp
+++ b/tests/auto/qquickiconimage/tst_qquickiconimage.cpp
@@ -32,6 +32,7 @@
#include <QtCore/qmath.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlfileselector.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
#include <QtQuick/qquickitemgrabresult.h>
@@ -65,6 +66,7 @@ private slots:
void svgNoSizes();
void svgSourceBindingSourceSize();
void color();
+ void fileSelectors();
private:
void setTheme();
@@ -452,6 +454,32 @@ void tst_qquickiconimage::changeSourceSize()
iconImage->setSourceSize(sourceSize);
}
+
+void tst_qquickiconimage::fileSelectors()
+{
+ SKIP_IF_DPR_TOO_HIGH();
+
+ QQuickView view;
+ QQmlFileSelector* fileSelector = new QQmlFileSelector(view.engine());
+ fileSelector->setExtraSelectors(QStringList() << "testselector");
+ view.setSource(testFileUrl("fileSelectors.qml"));
+ QCOMPARE(view.status(), QQuickView::Ready);
+ view.show();
+ view.requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(&view));
+
+ QQuickIconImage *iconImage = qobject_cast<QQuickIconImage*>(view.rootObject()->childItems().at(0));
+ QVERIFY(iconImage);
+
+ QQuickItem *image = view.rootObject()->childItems().at(1);
+ QVERIFY(image);
+
+ QImage iconImageWindowGrab = grabItemToImage(iconImage);
+ QCOMPARE(iconImageWindowGrab, grabItemToImage(image));
+
+ QCOMPARE(iconImageWindowGrab.pixelColor(iconImageWindowGrab.width() / 2, iconImageWindowGrab.height() / 2), QColor(Qt::blue));
+}
+
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);