diff options
author | Shawn Rutledge <[email protected]> | 2015-12-03 17:48:38 +0100 |
---|---|---|
committer | Shawn Rutledge <[email protected]> | 2019-08-24 12:26:20 +0200 |
commit | 5d995ae122aa07486ead849560b74d2b62b883bb (patch) | |
tree | fba57d7eac473f9a41923bfc7719a5a87a281f79 /tests/auto/quick/qquickborderimage | |
parent | 506b4093b47f8ecf29c2e1e83e73e47e9ac767ad (diff) |
Move currentFrame and frameCount properties up to QQuickImageBase
AnimatedImage already had these properties, but some typically non-animated
image formats such as PDF, TIFF and ICO can also support multiple pages.
In either case, the currentFrame property can be used to select a specific
frame or page. However an AnimatedImage uses a QMovie to do that, whereas
a plain Image uses QQuickPixmap. So the accessors need to be virtual in
order to have these different implementations.
[ChangeLog][QtQuick][Image] Image and BorderImage now have currentFrame
and frameCount properties which can be used to step through the frames of
multi-page image formats such as TIFF, WEBP and ICO.
Task-number: QTBUG-77506
Change-Id: Id4d95a99a26a862957e44b1bd8ffe06d7eababef
Reviewed-by: Eirik Aavitsland <[email protected]>
Diffstat (limited to 'tests/auto/quick/qquickborderimage')
-rw-r--r-- | tests/auto/quick/qquickborderimage/data/multi.ico | bin | 0 -> 27110 bytes | |||
-rw-r--r-- | tests/auto/quick/qquickborderimage/data/multiframe.qml | 8 | ||||
-rw-r--r-- | tests/auto/quick/qquickborderimage/data/multiframeAsync.qml | 9 | ||||
-rw-r--r-- | tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp | 53 |
4 files changed, 70 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickborderimage/data/multi.ico b/tests/auto/quick/qquickborderimage/data/multi.ico Binary files differnew file mode 100644 index 0000000000..b748ceaa29 --- /dev/null +++ b/tests/auto/quick/qquickborderimage/data/multi.ico diff --git a/tests/auto/quick/qquickborderimage/data/multiframe.qml b/tests/auto/quick/qquickborderimage/data/multiframe.qml new file mode 100644 index 0000000000..8bd32da5a6 --- /dev/null +++ b/tests/auto/quick/qquickborderimage/data/multiframe.qml @@ -0,0 +1,8 @@ +import QtQuick 2.14 + +BorderImage { + source: "multi.ico" + border { left: 19; top: 19; right: 19; bottom: 19 } + width: 160; height: 160 + horizontalTileMode: BorderImage.Stretch +} diff --git a/tests/auto/quick/qquickborderimage/data/multiframeAsync.qml b/tests/auto/quick/qquickborderimage/data/multiframeAsync.qml new file mode 100644 index 0000000000..059e4becf3 --- /dev/null +++ b/tests/auto/quick/qquickborderimage/data/multiframeAsync.qml @@ -0,0 +1,9 @@ +import QtQuick 2.14 + +BorderImage { + source: "multi.ico" + asynchronous: true + border { left: 19; top: 19; right: 19; bottom: 19 } + width: 160; height: 160 + horizontalTileMode: BorderImage.Stretch +} diff --git a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp index 9292e1886a..4181f46551 100644 --- a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp +++ b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp @@ -79,6 +79,8 @@ private slots: #if QT_CONFIG(opengl) void borderImageMesh(); #endif + void multiFrame_data(); + void multiFrame(); private: QQmlEngine engine; @@ -601,6 +603,57 @@ void tst_qquickborderimage::borderImageMesh() qPrintable(errorMessage)); } #endif + +void tst_qquickborderimage::multiFrame_data() +{ + QTest::addColumn<QString>("qmlfile"); + QTest::addColumn<bool>("asynchronous"); + + QTest::addRow("default") << "multiframe.qml" << false; + QTest::addRow("async") << "multiframeAsync.qml" << true; +} + +void tst_qquickborderimage::multiFrame() +{ + QFETCH(QString, qmlfile); + QFETCH(bool, asynchronous); + Q_UNUSED(asynchronous) + + QQuickView view(testFileUrl(qmlfile)); + QQuickBorderImage *image = qobject_cast<QQuickBorderImage*>(view.rootObject()); + QVERIFY(image); + QSignalSpy countSpy(image, SIGNAL(frameCountChanged())); + QSignalSpy currentSpy(image, SIGNAL(currentFrameChanged())); + if (asynchronous) { + QCOMPARE(image->frameCount(), 0); + QTRY_COMPARE(image->frameCount(), 4); + QCOMPARE(countSpy.count(), 1); + } else { + QCOMPARE(image->frameCount(), 4); + } + QCOMPARE(image->currentFrame(), 0); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QImage contents = view.grabWindow(); + // The first frame looks blue, approximately qRgba(0x43, 0x7e, 0xd6, 0xff) + QRgb color = contents.pixel(60, 60); + QVERIFY(qRed(color) < 0xc0); + QVERIFY(qGreen(color) < 0xc0); + QVERIFY(qBlue(color) > 0xc0); + + image->setCurrentFrame(1); + QTRY_COMPARE(image->status(), QQuickImageBase::Ready); + QCOMPARE(currentSpy.count(), 1); + QCOMPARE(image->currentFrame(), 1); + contents = view.grabWindow(); + // The second frame looks green, approximately qRgba(0x3a, 0xd2, 0x31, 0xff) + color = contents.pixel(60, 60); + QVERIFY(qRed(color) < 0xc0); + QVERIFY(qGreen(color) > 0xc0); + QVERIFY(qBlue(color) < 0xc0); +} + QTEST_MAIN(tst_qquickborderimage) #include "tst_qquickborderimage.moc" |