diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2013-08-19 13:29:43 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-20 22:12:24 +0100 |
commit | 63fb30eb29c26cd7ba0d9133610acb85cad83775 (patch) | |
tree | fb0d4870c3f2c22d14a90ad26956b8b6f45d3886 /tests/auto/quick/qquickimage/tst_qquickimage.cpp | |
parent | 5277a60f56c83376c1f2e9d9d502f1793d8c4857 (diff) |
Implement high-dpi "@2x" image handling.
Make QQuickBaseImage::load() load "@2x" image files
on high-dpi displays. Reload images on screen change
in order to load the correct version depending on
screen dpi. Modify QQuickImageBase::updatePaintNode()
to work with @2x images.
QQuickBaseImage::load() now looks at the target
window's devicePixelRatio and checks for the presence
of a "@2x" file on disk. If found the @2x version
will be used.
Unlike QPixmap, QQuickPixmap has no special knowledge
of "@2x" files. They pixmap system will be asked to
load "@2x" files and will cache them and report the
(device) pixel size, like any other pixmap.
Add auto-test and manual test.
Task-number: QTBUG-32862, QTBUG-33069
Change-Id: I1f57a10075e499f6eee61df5421e1986521c6ab0
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickimage/tst_qquickimage.cpp')
-rw-r--r-- | tests/auto/quick/qquickimage/tst_qquickimage.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index b23591b593..0855403d5a 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -105,6 +105,7 @@ private slots: void progressAndStatusChanges(); void sourceSizeChanges(); void correctStatus(); + void highdpi(); private: QQmlEngine engine; @@ -928,6 +929,49 @@ void tst_qquickimage::correctStatus() delete obj; } +void tst_qquickimage::highdpi() +{ + TestHTTPServer server(14449); + QVERIFY(server.isValid()); + server.serveDirectory(dataDirectory()); + + QString componentStr = "import QtQuick 2.0\nImage { source: srcImage ; }"; + QQmlComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QQmlContext *ctxt = engine.rootContext(); + + // Testing "@2x" high-dpi image loading: + // The basic case is as follows. Suppose you have foo.png, + // which is a 64x64 png that fits in a QML layout. Now, + // on a high-dpi system that pixmap would not provide + // enough pixels. To fix this the app developer provides + // a 128x128 foo@2x.png, which Qt automatically loads. + // The image continues to be referred to as "foo.png" in + // the QML sources, and reports a size of 64x64. + // + + // Load "heart-highdpi@2x.png", which is a 300x300 png. As a 2x scale image it + // should render and report a geometry of 150x150. + ctxt->setContextProperty("srcImage", testFileUrl("heart-highdpi@2x.png")); + + QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); + QVERIFY(obj != 0); + + QCOMPARE(obj->width(), 150.0); + QCOMPARE(obj->height(), 150.0); + QCOMPARE(obj->paintedWidth(), 150.0); + QCOMPARE(obj->paintedHeight(), 150.0); + + // Load a normal 1x image. + ctxt->setContextProperty("srcImage", testFileUrl("heart.png")); + QCOMPARE(obj->width(), 300.0); + QCOMPARE(obj->height(), 300.0); + QCOMPARE(obj->paintedWidth(), 300.0); + QCOMPARE(obj->paintedHeight(), 300.0); + + delete obj; +} + QTEST_MAIN(tst_qquickimage) #include "tst_qquickimage.moc" |