diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-02-12 00:27:18 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2010-02-12 00:53:22 (GMT) |
commit | 3aa16c105b7f9e55e804ee6bbb738dd267e484f2 (patch) | |
tree | 9be7555cf3ae8aef55155064ca027e64a6ce640d /tests/auto/declarative | |
parent | ba1fdd6e275ab6d22efe6329325b7cd6aa40a56e (diff) | |
download | Qt-3aa16c105b7f9e55e804ee6bbb738dd267e484f2.zip Qt-3aa16c105b7f9e55e804ee6bbb738dd267e484f2.tar.gz Qt-3aa16c105b7f9e55e804ee6bbb738dd267e484f2.tar.bz2 |
Decouple Loader from QmlGraphicsItem
Task-number: QT-2823
Reviewed-by: Aaron Kennedy
Diffstat (limited to 'tests/auto/declarative')
5 files changed, 112 insertions, 5 deletions
diff --git a/tests/auto/declarative/qmlgraphicsloader/data/GraphicsWidget250x250.qml b/tests/auto/declarative/qmlgraphicsloader/data/GraphicsWidget250x250.qml new file mode 100644 index 0000000..627c7df --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsloader/data/GraphicsWidget250x250.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +QGraphicsWidget { + size: "250x250" +} diff --git a/tests/auto/declarative/qmlgraphicsloader/data/NoResizeGraphicsWidget.qml b/tests/auto/declarative/qmlgraphicsloader/data/NoResizeGraphicsWidget.qml new file mode 100644 index 0000000..0704e18 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsloader/data/NoResizeGraphicsWidget.qml @@ -0,0 +1,8 @@ +import Qt 4.6
+
+Loader {
+ resizeMode: Loader.NoResize
+ source: "GraphicsWidget250x250.qml"
+ width: 200
+ height: 80
+}
diff --git a/tests/auto/declarative/qmlgraphicsloader/data/SizeGraphicsWidgetToLoader.qml b/tests/auto/declarative/qmlgraphicsloader/data/SizeGraphicsWidgetToLoader.qml new file mode 100644 index 0000000..97c72f4 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsloader/data/SizeGraphicsWidgetToLoader.qml @@ -0,0 +1,8 @@ +import Qt 4.6
+
+Loader {
+ resizeMode: Loader.SizeItemToLoader
+ width: 200
+ height: 80
+ source: "GraphicsWidget250x250.qml"
+}
diff --git a/tests/auto/declarative/qmlgraphicsloader/data/SizeLoaderToGraphicsWidget.qml b/tests/auto/declarative/qmlgraphicsloader/data/SizeLoaderToGraphicsWidget.qml new file mode 100644 index 0000000..cb72f05 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsloader/data/SizeLoaderToGraphicsWidget.qml @@ -0,0 +1,6 @@ +import Qt 4.6
+
+Loader {
+ resizeMode: Loader.SizeLoaderToItem
+ source: "GraphicsWidget250x250.qml"
+}
diff --git a/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp b/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp index 25543a9..43f58c1 100644 --- a/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp +++ b/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp @@ -39,6 +39,9 @@ ** ****************************************************************************/ #include <qtest.h> +#include <QtGui/QGraphicsWidget> +#include <QtGui/QGraphicsScene> + #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcomponent.h> #include <private/qmlgraphicsloader_p.h> @@ -77,6 +80,9 @@ private slots: void sizeLoaderToItem(); void sizeItemToLoader(); void noResize(); + void sizeLoaderToGraphicsWidget(); + void sizeGraphicsWidgetToLoader(); + void noResizeGraphicsWidget(); void networkRequestUrl(); void failNetworkRequest(); // void networkComponent(); @@ -240,7 +246,7 @@ void tst_QmlGraphicsLoader::sizeLoaderToItem() QCOMPARE(loader->height(), 60.0); // Check resize - QmlGraphicsItem *rect = loader->item(); + QmlGraphicsItem *rect = qobject_cast<QmlGraphicsItem*>(loader->item()); QVERIFY(rect); rect->setWidth(150); rect->setHeight(45); @@ -264,7 +270,7 @@ void tst_QmlGraphicsLoader::sizeItemToLoader() QCOMPARE(loader->width(), 200.0); QCOMPARE(loader->height(), 80.0); - QmlGraphicsItem *rect = loader->item(); + QmlGraphicsItem *rect = qobject_cast<QmlGraphicsItem*>(loader->item()); QVERIFY(rect); QCOMPARE(rect->width(), 200.0); QCOMPARE(rect->height(), 80.0); @@ -279,8 +285,8 @@ void tst_QmlGraphicsLoader::sizeItemToLoader() loader->setResizeMode(QmlGraphicsLoader::SizeLoaderToItem); rect->setWidth(160); rect->setHeight(45); - QCOMPARE(rect->width(), 160.0); - QCOMPARE(rect->height(), 45.0); + QCOMPARE(loader->width(), 160.0); + QCOMPARE(loader->height(), 45.0); } void tst_QmlGraphicsLoader::noResize() @@ -291,12 +297,86 @@ void tst_QmlGraphicsLoader::noResize() QCOMPARE(loader->width(), 200.0); QCOMPARE(loader->height(), 80.0); - QmlGraphicsItem *rect = loader->item(); + QmlGraphicsItem *rect = qobject_cast<QmlGraphicsItem*>(loader->item()); QVERIFY(rect); QCOMPARE(rect->width(), 120.0); QCOMPARE(rect->height(), 60.0); } +void tst_QmlGraphicsLoader::sizeLoaderToGraphicsWidget() +{ + QmlComponent component(&engine, TEST_FILE("/SizeLoaderToGraphicsWidget.qml")); + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); + QGraphicsScene scene; + scene.addItem(loader); + + QVERIFY(loader != 0); + QVERIFY(loader->resizeMode() == QmlGraphicsLoader::SizeLoaderToItem); + QCOMPARE(loader->width(), 250.0); + QCOMPARE(loader->height(), 250.0); + + // Check resize + QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(loader->item()); + QVERIFY(widget); + widget->resize(QSizeF(150,45)); + QCOMPARE(loader->width(), 150.0); + QCOMPARE(loader->height(), 45.0); + + // Switch mode + loader->setResizeMode(QmlGraphicsLoader::SizeItemToLoader); + loader->setWidth(180); + loader->setHeight(30); + QCOMPARE(widget->size().width(), 180.0); + QCOMPARE(widget->size().height(), 30.0); +} + +void tst_QmlGraphicsLoader::sizeGraphicsWidgetToLoader() +{ + QmlComponent component(&engine, TEST_FILE("/SizeGraphicsWidgetToLoader.qml")); + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); + QGraphicsScene scene; + scene.addItem(loader); + + QVERIFY(loader != 0); + QVERIFY(loader->resizeMode() == QmlGraphicsLoader::SizeItemToLoader); + QCOMPARE(loader->width(), 200.0); + QCOMPARE(loader->height(), 80.0); + + QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(loader->item()); + QVERIFY(widget); + QCOMPARE(widget->size().width(), 200.0); + QCOMPARE(widget->size().height(), 80.0); + + // Check resize + loader->setWidth(180); + loader->setHeight(30); + QCOMPARE(widget->size().width(), 180.0); + QCOMPARE(widget->size().height(), 30.0); + + // Switch mode + loader->setResizeMode(QmlGraphicsLoader::SizeLoaderToItem); + widget->resize(QSizeF(160,45)); + QCOMPARE(loader->width(), 160.0); + QCOMPARE(loader->height(), 45.0); +} + +void tst_QmlGraphicsLoader::noResizeGraphicsWidget() +{ + QmlComponent component(&engine, TEST_FILE("/NoResizeGraphicsWidget.qml")); + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); + QGraphicsScene scene; + scene.addItem(loader); + + QVERIFY(loader != 0); + QCOMPARE(loader->width(), 200.0); + QCOMPARE(loader->height(), 80.0); + + QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(loader->item()); + QVERIFY(widget); + QCOMPARE(widget->size().width(), 250.0); + QCOMPARE(widget->size().height(), 250.0); +} + void tst_QmlGraphicsLoader::networkRequestUrl() { TestHTTPServer server(SERVER_PORT); |