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 | |
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')
-rw-r--r-- | tests/auto/quick/qquickimage/data/heart-highdpi@2x.png | bin | 0 -> 12577 bytes | |||
-rw-r--r-- | tests/auto/quick/qquickimage/tst_qquickimage.cpp | 44 | ||||
-rw-r--r-- | tests/manual/highdpi/fillmodes.qml | 72 | ||||
-rw-r--r-- | tests/manual/highdpi/heart-highdpi@2x.png | bin | 0 -> 20654 bytes | |||
-rw-r--r-- | tests/manual/highdpi/heart-lowdpi.png | bin | 0 -> 15194 bytes | |||
-rw-r--r-- | tests/manual/highdpi/heart.png | bin | 0 -> 15194 bytes | |||
-rw-r--r-- | tests/manual/highdpi/heart@2x.png | bin | 0 -> 20654 bytes | |||
-rw-r--r-- | tests/manual/highdpi/image.qml | 52 | ||||
-rw-r--r-- | tests/manual/highdpi/image2.qml | 64 | ||||
-rw-r--r-- | tests/manual/highdpi/imagesize.qml | 76 | ||||
-rw-r--r-- | tests/manual/highdpi/mirror.qml | 57 | ||||
-rw-r--r-- | tests/manual/highdpi/sourcesize.qml | 76 |
12 files changed, 441 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickimage/data/heart-highdpi@2x.png b/tests/auto/quick/qquickimage/data/heart-highdpi@2x.png Binary files differnew file mode 100644 index 0000000000..abe97fee4b --- /dev/null +++ b/tests/auto/quick/qquickimage/data/heart-highdpi@2x.png 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" diff --git a/tests/manual/highdpi/fillmodes.qml b/tests/manual/highdpi/fillmodes.qml new file mode 100644 index 0000000000..cff2bcc34c --- /dev/null +++ b/tests/manual/highdpi/fillmodes.qml @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 700 + + // the images should have the same display size and appearance on each row. + Column { + anchors.centerIn: parent.Center + Row { + Image { width: 130; height: 70; fillMode: Image.Stretch; source : "heart-lowdpi.png" } + Image { width: 130; height: 70; fillMode: Image.Stretch; source : "heart.png" } + Image { width: 130; height: 70; fillMode: Image.Stretch; source : "heart-highdpi@2x.png" } + } + Row { + Image { width: 130; height: 100; fillMode: Image.PreserveAspectFit; source : "heart-lowdpi.png" } + Image { width: 130; height: 100; fillMode: Image.PreserveAspectFit; source : "heart.png" } + Image { width: 130; height: 100; fillMode: Image.PreserveAspectFit; source : "heart-highdpi@2x.png" } + } + Row { + Image { width: 130; height: 100; fillMode: Image.PreserveAspectCrop; source : "heart-lowdpi.png" } + Image { width: 130; height: 100; fillMode: Image.PreserveAspectCrop; source : "heart.png" } + Image { width: 130; height: 100; fillMode: Image.PreserveAspectCrop; source : "heart-highdpi@2x.png" } + } + Row { + Image { width: 230; height: 200; fillMode: Image.Tile; source : "heart-lowdpi.png" } + Image { width: 230; height: 200; fillMode: Image.Tile; source : "heart.png" } + Image { width: 230; height: 200; fillMode: Image.Tile; source : "heart-highdpi@2x.png" } + } + } +} diff --git a/tests/manual/highdpi/heart-highdpi@2x.png b/tests/manual/highdpi/heart-highdpi@2x.png Binary files differnew file mode 100644 index 0000000000..a7a1ca89a4 --- /dev/null +++ b/tests/manual/highdpi/heart-highdpi@2x.png diff --git a/tests/manual/highdpi/heart-lowdpi.png b/tests/manual/highdpi/heart-lowdpi.png Binary files differnew file mode 100644 index 0000000000..deaec18274 --- /dev/null +++ b/tests/manual/highdpi/heart-lowdpi.png diff --git a/tests/manual/highdpi/heart.png b/tests/manual/highdpi/heart.png Binary files differnew file mode 100644 index 0000000000..deaec18274 --- /dev/null +++ b/tests/manual/highdpi/heart.png diff --git a/tests/manual/highdpi/heart@2x.png b/tests/manual/highdpi/heart@2x.png Binary files differnew file mode 100644 index 0000000000..a7a1ca89a4 --- /dev/null +++ b/tests/manual/highdpi/heart@2x.png diff --git a/tests/manual/highdpi/image.qml b/tests/manual/highdpi/image.qml new file mode 100644 index 0000000000..8deab5c734 --- /dev/null +++ b/tests/manual/highdpi/image.qml @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 400 + + Image { + source : "heart.png" + anchors.centerIn: parent + } +} diff --git a/tests/manual/highdpi/image2.qml b/tests/manual/highdpi/image2.qml new file mode 100644 index 0000000000..b83c8006d8 --- /dev/null +++ b/tests/manual/highdpi/image2.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 400 + + // These images should all have the same visual size: + Row { + anchors.centerIn: parent + // 1X only + Image { + source : "heart-lowdpi.png" + } + // 1X and 2x, switches on screen change. + Image { + source : "heart.png" + } + // 2x only + Image { + source : "heart-highdpi@2x.png" + } + } +} diff --git a/tests/manual/highdpi/imagesize.qml b/tests/manual/highdpi/imagesize.qml new file mode 100644 index 0000000000..ee6719a6ee --- /dev/null +++ b/tests/manual/highdpi/imagesize.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 400 + + Column { + anchors.centerIn: parent.Center + Row { + Image { width: 50; height: 50; fillMode: Image.Stretch; source : "heart-lowdpi.png" } + Image { width: 50; height: 50; fillMode: Image.Stretch; source : "heart.png" } + Image { width: 50; height: 50; fillMode: Image.Stretch; source : "heart-highdpi@2x.png" } + } + Row { + Image { width: 100; height: 100; fillMode: Image.Stretch; source : "heart-lowdpi.png" } + Image { width: 100; height: 100; fillMode: Image.Stretch; source : "heart.png" } + Image { width: 100; height: 100; fillMode: Image.Stretch; source : "heart-highdpi@2x.png" } + } + Row { + Image { width: 150; height: 150; fillMode: Image.Stretch; source : "heart-lowdpi.png" } + Image { width: 150; height: 150; fillMode: Image.Stretch; source : "heart.png" } + Image { width: 150; height: 150; fillMode: Image.Stretch; source : "heart-highdpi@2x.png" } + } + Row { + Image { width: 200; height: 200; fillMode: Image.Stretch; source : "heart-lowdpi.png" } + Image { width: 200; height: 200; fillMode: Image.Stretch; source : "heart.png" } + Image { width: 200; height: 200; fillMode: Image.Stretch; source : "heart-highdpi@2x.png" } + } + Row { + Image { width: 300; height: 300; fillMode: Image.Stretch; source : "heart-lowdpi.png" } + Image { width: 300; height: 300; fillMode: Image.Stretch; source : "heart.png" } + Image { width: 300; height: 300; fillMode: Image.Stretch; source : "heart-highdpi@2x.png" } + } + } +} diff --git a/tests/manual/highdpi/mirror.qml b/tests/manual/highdpi/mirror.qml new file mode 100644 index 0000000000..3a92a9abd4 --- /dev/null +++ b/tests/manual/highdpi/mirror.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 700 + + // the images should have the same display size and appearance on each row. + Column { + anchors.centerIn: parent.Center + Row { + Image { mirror: true; source : "heart-lowdpi.png" } + Image { mirror: true; source : "heart.png" } + Image { mirror: true; source : "heart-highdpi@2x.png" } + } + } +} diff --git a/tests/manual/highdpi/sourcesize.qml b/tests/manual/highdpi/sourcesize.qml new file mode 100644 index 0000000000..64bf8ad86b --- /dev/null +++ b/tests/manual/highdpi/sourcesize.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 400 + + // SourceSize is in device-independent pixels. These images + // should display at the same visual size. + Column { + anchors.centerIn: parent.Center + Row { + + // standard image with no @2x version + Image { + sourceSize.width: 75 + sourceSize.height: 75 + source : "heart-lowdpi.png" + } + + // image with "@2x" version on disk + Image { + sourceSize.width: 75 + sourceSize.height: 75 + source : "heart.png" + } + + // direct use of "@2x" image + Image { + sourceSize.width: 75 + sourceSize.height: 75 + source : "heart-highdpi@2x.png" + } + } + } +} |