summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorJoona Petrell <joona.t.petrell@nokia.com>2010-04-14 07:15:22 (GMT)
committerJoona Petrell <joona.t.petrell@nokia.com>2010-04-14 07:16:44 (GMT)
commit6ae0b924102384d088c9a7f9b43170cf0d2668bd (patch)
treeb7815430e94da7fc21924e3be548b1c221068983 /tests/auto
parent4492df7ff293a5d76b5021bc60e3ba7d5041c303 (diff)
downloadQt-6ae0b924102384d088c9a7f9b43170cf0d2668bd.zip
Qt-6ae0b924102384d088c9a7f9b43170cf0d2668bd.tar.gz
Qt-6ae0b924102384d088c9a7f9b43170cf0d2668bd.tar.bz2
Image with PreserveAspect enabled with either width or height defined should implicitly update the undefined axis to follow the aspect ratio
Task-number: Reviewed-by: Martin Jones
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativeimage/data/aspectratio.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp25
2 files changed, 30 insertions, 1 deletions
diff --git a/tests/auto/declarative/qdeclarativeimage/data/aspectratio.qml b/tests/auto/declarative/qdeclarativeimage/data/aspectratio.qml
new file mode 100644
index 0000000..402d33e
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeimage/data/aspectratio.qml
@@ -0,0 +1,6 @@
+import Qt 4.7
+
+Image {
+ source: "heart.png"
+ fillMode: Image.PreserveAspectFit;
+}
diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
index 52d7c16..53c208e 100644
--- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
+++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
@@ -46,6 +46,7 @@
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
+#include <QtDeclarative/qdeclarativeview.h>
#include <private/qdeclarativeimage_p.h>
#include <private/qdeclarativeimagebase_p.h>
#include <private/qdeclarativeloader_p.h>
@@ -80,6 +81,7 @@ private slots:
void imageSource_data();
void clearSource();
void resized();
+ void preserveAspectRatio();
void smooth();
void pixmap();
void svg();
@@ -209,10 +211,31 @@ void tst_qdeclarativeimage::resized()
QCOMPARE(obj->width(), 300.);
QCOMPARE(obj->height(), 300.);
QCOMPARE(obj->fillMode(), QDeclarativeImage::Stretch);
-
delete obj;
}
+
+void tst_qdeclarativeimage::preserveAspectRatio()
+{
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+ canvas->show();
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/aspectratio.qml"));
+ QDeclarativeImage *image = qobject_cast<QDeclarativeImage*>(canvas->rootObject());
+ QVERIFY(image != 0);
+ image->setWidth(80.0);
+ QCOMPARE(image->width(), 80.);
+ QCOMPARE(image->height(), 80.);
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/aspectratio.qml"));
+ image = qobject_cast<QDeclarativeImage*>(canvas->rootObject());
+ image->setHeight(60.0);
+ QVERIFY(image != 0);
+ QCOMPARE(image->height(), 60.);
+ QCOMPARE(image->width(), 60.);
+ delete canvas;
+}
+
void tst_qdeclarativeimage::smooth()
{
QString componentStr = "import Qt 4.7\nImage { source: \"" SRCDIR "/data/colors.png\"; smooth: true; width: 300; height: 300 }";