summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-02-14 11:57:25 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-14 08:50:57 +0100
commitd95178153a0f15991b2e6e91216dbcf5c0be2af3 (patch)
tree26f50195f44f8a5f3ac2757f157e6bfafb6286b6 /tests
parent58d85747964473a71ca5339d296d6870f0871b0c (diff)
Preserve aspect ratio when setting Image.sourceSize
Setting both sourceSize.width and sourceSize.height results in changing the image aspect ratio. This is never what you'd want. Fit the image to the provided sourceSize, maintaining the aspect ratio. Task-number: QTBUG-21161 Change-Id: I77e9aacb8d31475d5df0aef1de52c0edbd1e2fc9 Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtquick2/qquickimage/data/sourceSize.qml7
-rw-r--r--tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp46
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquickimage/data/sourceSize.qml b/tests/auto/qtquick2/qquickimage/data/sourceSize.qml
new file mode 100644
index 0000000000..8e25c254d3
--- /dev/null
+++ b/tests/auto/qtquick2/qquickimage/data/sourceSize.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0
+
+Image {
+ source: "heart.png"
+ sourceSize.width: srcWidth
+ sourceSize.height: srcHeight
+}
diff --git a/tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp b/tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp
index b33caa78c4..7602f1b1d5 100644
--- a/tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp
+++ b/tests/auto/qtquick2/qquickimage/tst_qquickimage.cpp
@@ -95,6 +95,8 @@ private slots:
void sourceSize_QTBUG_16389();
void nullPixmapPaint();
void imageCrash_QTBUG_22125();
+ void sourceSize_data();
+ void sourceSize();
private:
QDeclarativeEngine engine;
@@ -498,6 +500,8 @@ void tst_qquickimage::tiling_QTBUG_6716()
QVERIFY(img.pixel(x, y) == qRgb(0, 255, 0));
}
}
+
+ delete canvas;
}
void tst_qquickimage::tiling_QTBUG_6716_data()
@@ -674,6 +678,8 @@ void tst_qquickimage::nullPixmapPaint()
qInstallMsgHandler(previousMsgHandler);
QVERIFY(numberOfWarnings == 0);
delete image;
+
+ delete canvas;
}
void tst_qquickimage::imageCrash_QTBUG_22125()
@@ -698,6 +704,46 @@ void tst_qquickimage::imageCrash_QTBUG_22125()
QCoreApplication::processEvents();
}
+void tst_qquickimage::sourceSize_data()
+{
+ QTest::addColumn<int>("sourceWidth");
+ QTest::addColumn<int>("sourceHeight");
+ QTest::addColumn<qreal>("implicitWidth");
+ QTest::addColumn<qreal>("implicitHeight");
+
+ QTest::newRow("unscaled") << 0 << 0 << 300.0 << 300.0;
+ QTest::newRow("scale width") << 100 << 0 << 100.0 << 100.0;
+ QTest::newRow("scale height") << 0 << 150 << 150.0 << 150.0;
+ QTest::newRow("larger sourceSize") << 400 << 400 << 300.0 << 300.0;
+}
+
+void tst_qquickimage::sourceSize()
+{
+ QFETCH(int, sourceWidth);
+ QFETCH(int, sourceHeight);
+ QFETCH(qreal, implicitWidth);
+ QFETCH(qreal, implicitHeight);
+
+ QQuickView *canvas = new QQuickView(0);
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("srcWidth", sourceWidth);
+ ctxt->setContextProperty("srcHeight", sourceHeight);
+
+ canvas->setSource(testFileUrl("sourceSize.qml"));
+ canvas->show();
+ qApp->processEvents();
+
+ QQuickImage *image = qobject_cast<QQuickImage*>(canvas->rootObject());
+ QVERIFY(image);
+
+ QCOMPARE(image->sourceSize().width(), sourceWidth);
+ QCOMPARE(image->sourceSize().height(), sourceHeight);
+ QCOMPARE(image->implicitWidth(), implicitWidth);
+ QCOMPARE(image->implicitHeight(), implicitHeight);
+
+ delete canvas;
+}
+
QTEST_MAIN(tst_qquickimage)
#include "tst_qquickimage.moc"