diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2017-02-16 13:32:01 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2017-02-24 10:40:12 +0000 |
commit | bb1acc24587ebdecc4051ef4b573ef32cfb8a8c5 (patch) | |
tree | 0665a2676223f8c662e73d770f5ebe6da8b15209 /tests/auto/quick/qquickimage | |
parent | dca1f953264a373cbbe42adccb93fea84b96af51 (diff) |
QQuickImage: take DPI into account for implicit and painted sizes
As an example, an @2x image will report an implicit size that is twice
as large as it should be when its fillMode is set to PreserveAspectFit.
This commit adds code that was likely missed in 63fb30eb.
Change-Id: I38cfdf3a429726639209c88dfb38eebb0b9ff162
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickimage')
-rw-r--r-- | tests/auto/quick/qquickimage/tst_qquickimage.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index 4699f947a1..2681f1a966 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -91,6 +91,8 @@ private slots: void sourceSizeChanges(); void correctStatus(); void highdpi(); + void highDpiFillModesAndSizes_data(); + void highDpiFillModesAndSizes(); void hugeImages(); private: @@ -971,6 +973,65 @@ void tst_qquickimage::highdpi() delete obj; } +void tst_qquickimage::highDpiFillModesAndSizes_data() +{ + QTest::addColumn<QQuickImage::FillMode>("fillMode"); + QTest::addColumn<qreal>("expectedHeightAfterSettingWidthTo100"); + QTest::addColumn<qreal>("expectedImplicitHeightAfterSettingWidthTo100"); + QTest::addColumn<qreal>("expectedPaintedWidthAfterSettingWidthTo100"); + QTest::addColumn<qreal>("expectedPaintedHeightAfterSettingWidthTo100"); + + QTest::addRow("Stretch") << QQuickImage::Stretch << 150.0 << 150.0 << 100.0 << 150.0; + QTest::addRow("PreserveAspectFit") << QQuickImage::PreserveAspectFit << 100.0 << 100.0 << 100.0 << 100.0; + QTest::addRow("PreserveAspectCrop") << QQuickImage::PreserveAspectCrop << 150.0 << 150.0 << 150.0 << 150.0; + QTest::addRow("Tile") << QQuickImage::Tile << 150.0 << 150.0 << 100.0 << 150.0; + QTest::addRow("TileVertically") << QQuickImage::TileVertically << 150.0 << 150.0 << 100.0 << 150.0; + QTest::addRow("TileHorizontally") << QQuickImage::TileHorizontally << 150.0 << 150.0 << 100.0 << 150.0; + QTest::addRow("Pad") << QQuickImage::Pad << 150.0 << 150.0 << 150.0 << 150.0; +} + +void tst_qquickimage::highDpiFillModesAndSizes() +{ + QFETCH(QQuickImage::FillMode, fillMode); + QFETCH(qreal, expectedHeightAfterSettingWidthTo100); + QFETCH(qreal, expectedImplicitHeightAfterSettingWidthTo100); + QFETCH(qreal, expectedPaintedWidthAfterSettingWidthTo100); + QFETCH(qreal, expectedPaintedHeightAfterSettingWidthTo100); + + QString componentStr = "import QtQuick 2.0\nImage { source: srcImage; }"; + QQmlComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + + engine.rootContext()->setContextProperty("srcImage", testFileUrl("heart-highdpi@2x.png")); + + QScopedPointer<QQuickImage> image(qobject_cast<QQuickImage*>(component.create())); + QVERIFY(image); + QCOMPARE(image->width(), 150.0); + QCOMPARE(image->height(), 150.0); + QCOMPARE(image->paintedWidth(), 150.0); + QCOMPARE(image->paintedHeight(), 150.0); + QCOMPARE(image->implicitWidth(), 150.0); + QCOMPARE(image->implicitHeight(), 150.0); + QCOMPARE(image->paintedWidth(), 150.0); + QCOMPARE(image->paintedHeight(), 150.0); + + // The implicit size should not change when setting any fillMode here. + image->setFillMode(fillMode); + QCOMPARE(image->fillMode(), fillMode); + QCOMPARE(image->implicitWidth(), 150.0); + QCOMPARE(image->implicitHeight(), 150.0); + QCOMPARE(image->paintedWidth(), 150.0); + QCOMPARE(image->paintedHeight(), 150.0); + + image->setWidth(100.0); + QCOMPARE(image->width(), 100.0); + QCOMPARE(image->height(), expectedHeightAfterSettingWidthTo100); + QCOMPARE(image->implicitWidth(), 150.0); + QCOMPARE(image->implicitHeight(), expectedImplicitHeightAfterSettingWidthTo100); + QCOMPARE(image->paintedWidth(), expectedPaintedWidthAfterSettingWidthTo100); + QCOMPARE(image->paintedHeight(), expectedPaintedHeightAfterSettingWidthTo100); +} + void tst_qquickimage::hugeImages() { QQuickView view; |