From afcbf6a97744a7b113dc5ce542618a5543aead91 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 3 Nov 2009 14:17:31 +1000 Subject: Avoid crashing on faulty call to createQmlObject --- src/declarative/qml/qmlengine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index c562e02..29d91bc 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -625,6 +625,11 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi url = QUrl(ctxt->argument(2).toString()); QObject *parentArg = activeEnginePriv->objectClass->toQObject(ctxt->argument(1)); QmlContext *qmlCtxt = qmlContext(parentArg); + if(!parentArg || !qmlCtxt){ + //TODO: Could use a qmlInfo() like function for script functions + qWarning() << "createQmlObject called with invalid parent object"; + return engine->nullValue(); + } if (url.isEmpty()) { url = qmlCtxt->resolvedUrl(QUrl(QLatin1String(""))); } else { -- cgit v0.12 From 4e8df537210736d8a723a409e5e01046efa44a39 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 4 Nov 2009 08:53:12 +1000 Subject: Position items in the correct order Nearly fixes QT-2241, but still waiting for a signal to appear in QGraphicsItem which allows up to reposition items after a change. --- .../graphicsitems/qmlgraphicspositioners.cpp | 21 +++++++++++------- .../graphicsitems/qmlgraphicspositioners_p.h | 1 + tests/auto/declarative/layouts/tst_layouts.cpp | 25 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index f599025..b4544c5 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -209,7 +209,12 @@ void QmlGraphicsBasePositioner::prePositioning() QCoreApplication::postEvent(this, new QEvent(QEvent::User)); } QSet allItems; + //Need to order children by creation order modified by stacking order + //###can we avoid using the QGraphicsItemPrivate? QList children = childItems(); + qSort(children.begin(), children.end(), d->insertionOrder); + positionedItems = QList(); + for (int ii = 0; ii < children.count(); ++ii) { QmlGraphicsItem *child = qobject_cast(children.at(ii)); if (!child) @@ -234,6 +239,7 @@ void QmlGraphicsBasePositioner::prePositioning() d->_newItems+=child; } allItems += child; + positionedItems << child; } QSet deletedItems = d->_items - allItems; foreach(QmlGraphicsItem *child, d->_items){ @@ -497,9 +503,9 @@ void QmlGraphicsColumn::doPositioning() } } - QList children = childItems(); + QList children = positionedItems; for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = qobject_cast(children.at(ii)); + QmlGraphicsItem *child = children.at(ii); if (!child || isInvisible(child)) continue; @@ -653,9 +659,9 @@ void QmlGraphicsRow::doPositioning() applyRemove(changes, item); } } - QList children = childItems(); + QList children = positionedItems; for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = qobject_cast(children.at(ii)); + QmlGraphicsItem *child = children.at(ii); if (!child || isInvisible(child)) continue; @@ -859,7 +865,7 @@ void QmlGraphicsGrid::doPositioning() QList maxColWidth; QList maxRowHeight; int childIndex =0; - QList children = childItems(); + QList children = positionedItems; for (int i=0; i(children.at(childIndex++)); + QmlGraphicsItem *child = children.at(childIndex++); if (!child || isInvisible(child)) continue; if (child->width() > maxColWidth[j]) @@ -889,8 +895,7 @@ void QmlGraphicsGrid::doPositioning() applyRemove(changes, item); } } - foreach(QGraphicsItem* schild, children){ - QmlGraphicsItem *child = qobject_cast(schild); + foreach(QmlGraphicsItem* child, children){ if (!child || isInvisible(child)) continue; bool needMove = (child->x()!=xoffset)||(child->y()!=yoffset); diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h index 0011ec5..56adc8b 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h @@ -104,6 +104,7 @@ private Q_SLOTS: protected: QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent); void setMovingItem(QmlGraphicsItem *); + QList positionedItems; private: void applyTransition(const QList >& changes, QmlGraphicsItem* target, diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index b0df57ea..96729a3 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -58,6 +58,7 @@ private slots: void test_grid(); void test_grid_spacing(); + void test_repeater(); private: QmlView *createView(const QString &filename); }; @@ -222,6 +223,30 @@ void tst_QmlGraphicsLayouts::test_grid_spacing() QCOMPARE(five->y(), 54.0); } +void tst_QmlGraphicsLayouts::test_repeater() +{ + QmlView *canvas = createView("data/repeater.qml"); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QVERIFY(one != 0); + + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QVERIFY(two != 0); + + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 100.0); + QCOMPARE(three->y(), 0.0); +} + QmlView *tst_QmlGraphicsLayouts::createView(const QString &filename) { QmlView *canvas = new QmlView(0); -- cgit v0.12 From f3cce7a770f25c42d5c85b012df338fc712f5b2e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 4 Nov 2009 11:57:42 +1000 Subject: Add tests for the the positioner transitions. --- .../declarative/layouts/data/grid-animated.qml | 55 ++++++ .../layouts/data/horizontal-animated.qml | 42 +++++ tests/auto/declarative/layouts/data/repeater.qml | 20 ++ .../declarative/layouts/data/vertical-animated.qml | 42 +++++ tests/auto/declarative/layouts/tst_layouts.cpp | 204 +++++++++++++++++++++ 5 files changed, 363 insertions(+) create mode 100644 tests/auto/declarative/layouts/data/grid-animated.qml create mode 100644 tests/auto/declarative/layouts/data/horizontal-animated.qml create mode 100644 tests/auto/declarative/layouts/data/repeater.qml create mode 100644 tests/auto/declarative/layouts/data/vertical-animated.qml diff --git a/tests/auto/declarative/layouts/data/grid-animated.qml b/tests/auto/declarative/layouts/data/grid-animated.qml new file mode 100644 index 0000000..9edccaf --- /dev/null +++ b/tests/auto/declarative/layouts/data/grid-animated.qml @@ -0,0 +1,55 @@ +import Qt 4.6 + +Item { + width: 640 + height: 480 + Grid { + columns: 3 + add: Transition { + NumberAnimation { + properties: "x,y"; from: -100 + } + } + remove: Transition { + NumberAnimation { + properties: "x,y"; to: -100 + } + } + move: Transition { + NumberAnimation { + properties: "x,y"; + } + } + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + opacity: 0 + color: "green" + width: 50 + height: 50 + } + Rectangle { + objectName: "three" + color: "blue" + width: 50 + height: 50 + } + Rectangle { + objectName: "four" + color: "cyan" + width: 50 + height: 50 + } + Rectangle { + objectName: "five" + color: "magenta" + width: 50 + height: 50 + } + } +} diff --git a/tests/auto/declarative/layouts/data/horizontal-animated.qml b/tests/auto/declarative/layouts/data/horizontal-animated.qml new file mode 100644 index 0000000..f757d18 --- /dev/null +++ b/tests/auto/declarative/layouts/data/horizontal-animated.qml @@ -0,0 +1,42 @@ +import Qt 4.6 + +Item { + width: 640 + height: 480 + Row { + add: Transition { + NumberAnimation { + properties: "x"; from: -100 + } + } + remove: Transition { + NumberAnimation { + properties: "x"; to: -100 + } + } + move: Transition { + NumberAnimation { + properties: "x"; + } + } + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "blue" + opacity: 0 + width: 50 + height: 50 + } + Rectangle { + objectName: "three" + color: "red" + width: 50 + height: 50 + } + } +} diff --git a/tests/auto/declarative/layouts/data/repeater.qml b/tests/auto/declarative/layouts/data/repeater.qml new file mode 100644 index 0000000..2bc5e94 --- /dev/null +++ b/tests/auto/declarative/layouts/data/repeater.qml @@ -0,0 +1,20 @@ +import Qt 4.6 + +Item { + width: 640 + height: 480 + Row { + Repeater{ model: 3; + delegate: Component { + Rectangle { + color: "red" + width: 50 + height: 50 + z: {if(index == 0){2;}else if(index == 1){1;} else{3;}} + objectName: {if(index == 0){"one";}else if(index == 1){"two";} else{"three";}} + + } + } + } + } +} diff --git a/tests/auto/declarative/layouts/data/vertical-animated.qml b/tests/auto/declarative/layouts/data/vertical-animated.qml new file mode 100644 index 0000000..f52a78a --- /dev/null +++ b/tests/auto/declarative/layouts/data/vertical-animated.qml @@ -0,0 +1,42 @@ +import Qt 4.6 + +Item { + width: 640 + height: 480 + Column { + add: Transition { + NumberAnimation { + properties: "y"; from: -100 + } + } + remove: Transition { + NumberAnimation { + properties: "y"; to: -100 + } + } + move: Transition { + NumberAnimation { + properties: "y"; + } + } + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "blue" + opacity: 0 + width: 50 + height: 50 + } + Rectangle { + objectName: "three" + color: "red" + width: 50 + height: 50 + } + } +} diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index 96729a3..c0c067a 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -53,10 +53,13 @@ public: private slots: void test_horizontal(); void test_horizontal_spacing(); + void test_horizontal_animated(); void test_vertical(); void test_vertical_spacing(); + void test_vertical_animated(); void test_grid(); void test_grid_spacing(); + void test_grid_animated(); void test_repeater(); private: @@ -115,6 +118,57 @@ void tst_QmlGraphicsLayouts::test_horizontal_spacing() QCOMPARE(three->y(), 0.0); } +void tst_QmlGraphicsLayouts::test_horizontal_animated() +{ + QmlView *canvas = createView(SRCDIR "/data/horizontal-animated.qml"); + + canvas->execute(); + qApp->processEvents(); + + QTest::qWait(0);//Let the animation start + //Note that one and three animate in + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QVERIFY(one != 0); + QCOMPARE(one->x(), -100.0); + + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QVERIFY(two != 0); + QCOMPARE(two->x(), 0.0); + + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QVERIFY(three != 0); + QCOMPARE(three->x(), -100.0); + + QTest::qWait(300);//Let the animation complete + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(three->y(), 0.0); + + //Add 'two' + two->setOpacity(1.0); + QCOMPARE(two->opacity(), 1.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->x(), -100.0); + QCOMPARE(three->x(), 50.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->x(), 50.0); + QCOMPARE(three->x(), 100.0); + + //Remove 'two' + two->setOpacity(0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(three->x(), 100.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->x(), 50.0); + QCOMPARE(three->x(), 50.0); +} + void tst_QmlGraphicsLayouts::test_vertical() { QmlView *canvas = createView(SRCDIR "/data/vertical.qml"); @@ -163,6 +217,57 @@ void tst_QmlGraphicsLayouts::test_vertical_spacing() QCOMPARE(three->y(), 80.0); } +void tst_QmlGraphicsLayouts::test_vertical_animated() +{ + QmlView *canvas = createView(SRCDIR "/data/vertical-animated.qml"); + + canvas->execute(); + qApp->processEvents(); + + QTest::qWait(0);//Let the animation start + //Note that one and three animate in + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QVERIFY(one != 0); + QCOMPARE(one->y(), -100.0); + + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QVERIFY(two != 0); + QCOMPARE(two->y(), 0.0); + + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QVERIFY(three != 0); + QCOMPARE(three->y(), -100.0); + + QTest::qWait(300);//Let the animation complete + + QCOMPARE(one->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(three->y(), 50.0); + QCOMPARE(three->x(), 0.0); + + //Add 'two' + two->setOpacity(1.0); + QCOMPARE(two->opacity(), 1.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->y(), -100.0); + QCOMPARE(three->y(), 50.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->y(), 100.0); + + //Remove 'two' + two->setOpacity(0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->y(), 100.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->y(), 50.0); +} + void tst_QmlGraphicsLayouts::test_grid() { QmlView *canvas = createView("data/grid.qml"); @@ -223,6 +328,105 @@ void tst_QmlGraphicsLayouts::test_grid_spacing() QCOMPARE(five->y(), 54.0); } +void tst_QmlGraphicsLayouts::test_grid_animated() +{ + QmlView *canvas = createView(SRCDIR "/data/grid-animated.qml"); + canvas->execute(); + qApp->processEvents(); + + QTest::qWait(0);//Let the animation start + //Note that all but two animate in + QmlGraphicsRectangle *one = canvas->root()->findChild("one"); + QVERIFY(one != 0); + QCOMPARE(one->x(), -100.0); + QCOMPARE(one->y(), -100.0); + + QmlGraphicsRectangle *two = canvas->root()->findChild("two"); + QVERIFY(two != 0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 0.0); + + QmlGraphicsRectangle *three = canvas->root()->findChild("three"); + QVERIFY(three != 0); + QCOMPARE(three->x(), -100.0); + QCOMPARE(three->y(), -100.0); + + QmlGraphicsRectangle *four = canvas->root()->findChild("four"); + QVERIFY(four != 0); + QCOMPARE(four->x(), -100.0); + QCOMPARE(four->y(), -100.0); + + QmlGraphicsRectangle *five = canvas->root()->findChild("five"); + QVERIFY(five != 0); + QCOMPARE(five->x(), -100.0); + QCOMPARE(five->y(), -100.0); + + QTest::qWait(300);//Let the animation complete + + QCOMPARE(one->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(four->y(), 0.0); + QCOMPARE(four->x(), 100.0); + QCOMPARE(five->y(), 50.0); + QCOMPARE(five->x(), 0.0); + + //Add 'two' + two->setOpacity(1.0); + QCOMPARE(two->opacity(), 1.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 100.0); + QCOMPARE(four->y(), 0.0); + QCOMPARE(five->x(), 0.0); + QCOMPARE(five->y(), 50.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 100.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); + + //Remove 'two' + two->setOpacity(0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 100.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 100.0); + QCOMPARE(four->y(), 0.0); + QCOMPARE(five->x(), 0.0); + QCOMPARE(five->y(), 50.0); +} + void tst_QmlGraphicsLayouts::test_repeater() { QmlView *canvas = createView("data/repeater.qml"); -- cgit v0.12 From 8fbff4dffd53546e4c3acecd0a9700a7ad970c83 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 5 Nov 2009 13:48:33 +1000 Subject: Test more ListView. --- tests/auto/declarative/listview/tst_listview.cpp | 94 ++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 6bf1080..b8f87b7 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -70,6 +70,8 @@ private slots: void qAbstractItemModel_moved(); void enforceRange(); + void spacing(); + void sections(); private: template void items(); @@ -264,6 +266,13 @@ void tst_QmlGraphicsListView::items() listview->decrementCurrentIndex(); QCOMPARE(listview->currentIndex(), 0); + // set an empty model and confirm that items are destroyed + T model2; + ctxt->setContextProperty("testModel", &model2); + + int itemCount = findItems(viewport, "wrapper").count(); + QVERIFY(itemCount == 0); + delete canvas; } @@ -632,6 +641,91 @@ void tst_QmlGraphicsListView::enforceRange() delete canvas; } +void tst_QmlGraphicsListView::spacing() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + listview->setSpacing(10); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*30); + } + + listview->setSpacing(0); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + delete canvas; +} + +void tst_QmlGraphicsListView::sections() +{ + QmlView *canvas = createView(SRCDIR "/data/listview-sections.qml"); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + QVERIFY(item); + QCOMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); + } + + delete canvas; +} + void tst_QmlGraphicsListView::qListModelInterface_items() { items(); -- cgit v0.12 From 0ef5d89b540be963d1a8131f6625f990a4fe66e8 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 5 Nov 2009 14:03:47 +1000 Subject: Particles cleaned up and placed in in qmlgraphics/ API changes: Removed bool streamIn Added int emissionRate Added int emissionVariance Added void burst(count, emissionRate=-1) While rewriting the internals to accomodate this, all other outstanding particles bugs were believed fixed. Task-number: QT-2392 QT-2391 QT-2390 QT-2406 --- demos/declarative/minehunt/Explosion.qml | 7 +- demos/declarative/samegame/content/BoomBlock.qml | 12 +- doc/src/declarative/advtutorial4.qdoc | 6 +- .../samegame/samegame4/content/BoomBlock.qml | 13 +- src/declarative/QmlChanges.txt | 2 + src/declarative/extra/extra.pri | 2 - src/declarative/extra/qmlgraphicsparticles.cpp | 1134 ----------------- src/declarative/extra/qmlgraphicsparticles_p.h | 230 ---- src/declarative/graphicsitems/graphicsitems.pri | 2 + .../graphicsitems/qmlgraphicsparticles.cpp | 1278 ++++++++++++++++++++ .../graphicsitems/qmlgraphicsparticles_p.h | 252 ++++ .../qmlgraphicsparticles/data/particles.qml | 2 +- .../tst_qmlgraphicsparticles.cpp | 7 +- 13 files changed, 1558 insertions(+), 1389 deletions(-) delete mode 100644 src/declarative/extra/qmlgraphicsparticles.cpp delete mode 100644 src/declarative/extra/qmlgraphicsparticles_p.h create mode 100644 src/declarative/graphicsitems/qmlgraphicsparticles.cpp create mode 100644 src/declarative/graphicsitems/qmlgraphicsparticles_p.h diff --git a/demos/declarative/minehunt/Explosion.qml b/demos/declarative/minehunt/Explosion.qml index a997048..e337c46 100644 --- a/demos/declarative/minehunt/Explosion.qml +++ b/demos/declarative/minehunt/Explosion.qml @@ -16,13 +16,10 @@ Item { velocity: 100 velocityDeviation: 20 z: 100 - opacity: 0 - streamIn: false + opacity: 1 } states: [ State { name: "exploding"; when: explode == true - PropertyChanges { target: particles; count: 200 } - PropertyChanges { target: particles; opacity: 1 } - PropertyChanges { target: particles; emitting: false } // i.e. emit only once + StateChangeScript {script: particles.burst(200); } } ] diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index b0c297b..723e62a 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -26,9 +26,11 @@ Item { id:block } Particles { id: particles - width:1; height:1; anchors.centerIn: parent; opacity: 0 - lifeSpan: 700; lifeSpanDeviation: 600; count:0; streamIn: false - angle: 0; angleDeviation: 360; velocity: 100; velocityDeviation:30 + width:1; height:1; anchors.centerIn: parent; + emissionRate: 0; + lifeSpan: 700; lifeSpanDeviation: 600; + angle: 0; angleDeviation: 360; + velocity: 100; velocityDeviation:30; source: { if(type == 0){ "pics/redStar.png"; @@ -45,9 +47,7 @@ Item { id:block PropertyChanges { target: img; opacity: 1 } }, State{ name: "DeathState"; when: dying == true - PropertyChanges { target: particles; count: 50 } - PropertyChanges { target: particles; opacity: 1 } - PropertyChanges { target: particles; emitting: false } // i.e. emit only once + StateChangeScript { script: particles.burst(50); } PropertyChanges { target: img; opacity: 0 } StateChangeScript { script: block.destroy(1000); } } diff --git a/doc/src/declarative/advtutorial4.qdoc b/doc/src/declarative/advtutorial4.qdoc index e30fe84..5f8c0e9 100644 --- a/doc/src/declarative/advtutorial4.qdoc +++ b/doc/src/declarative/advtutorial4.qdoc @@ -106,9 +106,9 @@ the block, like so: \snippet declarative/tutorials/samegame/samegame4/content/BoomBlock.qml 3 -To fully understand this you'll want to look at the Particles element documentation, but it's important to note that count is set -to zero. -We next extend the 'dying' state, which triggers the particles by setting the count to non-zero. The code for the states now look +To fully understand this you'll want to look at the Particles element documentation, but it's important to note that emissionRate is set +to zero, so that no particles are emitted normally. +We next extend the 'dying' state, which creates a burst of particles by calling the burst method on the particles element. The code for the states now look like this: \snippet declarative/tutorials/samegame/samegame4/content/BoomBlock.qml 4 diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml index 7ad8b07..4c2ba43 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml @@ -31,9 +31,11 @@ Item { id:block //![3] Particles { id: particles - width:1; height:1; anchors.centerIn: parent; opacity: 0 - lifeSpan: 700; lifeSpanDeviation: 600; count:0; streamIn: false - angle: 0; angleDeviation: 360; velocity: 100; velocityDeviation:30 + width:1; height:1; anchors.centerIn: parent; + emissionRate: 0; + lifeSpan: 700; lifeSpanDeviation: 600; + angle: 0; angleDeviation: 360; + velocity: 100; velocityDeviation:30; source: { if(type == 0){ "pics/redStar.png"; @@ -52,10 +54,9 @@ Item { id:block PropertyChanges { target: img; opacity: 1 } }, State{ name: "DeathState"; when: dying == true - PropertyChanges { target: particles; count: 50 } - PropertyChanges { target: particles; opacity: 1 } - PropertyChanges { target: particles; emitting: false } // i.e. emit only once + StateChangeScript { script: particles.burst(50); } PropertyChanges { target: img; opacity: 0 } + StateChangeScript { script: block.destroy(1000); } } ] //![4] diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 465ee9e..c85ef77 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -82,6 +82,7 @@ Loader: add sourceComponent property Loader: add resizeMode property ListView: preferredHighlightBegin, preferredHighlightEnd ListView: strictlyEnforceHighlightRange +Particles: Added emissionRate, emissionVariance and burst() Deletions: Column/VerticalPositioner: lost "margins" property @@ -92,6 +93,7 @@ Flickable: removed "dragMode" property ComponentInstance: removed. Replaced by Loader.sourceComponent ListView: removed currentItemMode. Replaced by highligh range. ListView: removed snapPos. +Particles: removed streamIn. Replaced by emissionRate Other Changes: ids must be lowercase: Text { id: foo }, not Text { id: Foo } diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri index 9d0e760..a81416d 100644 --- a/src/declarative/extra/extra.pri +++ b/src/declarative/extra/extra.pri @@ -4,7 +4,6 @@ SOURCES += \ extra/qmldatetimeformatter.cpp \ extra/qmlgraphicsintegermodel.cpp \ extra/qmlgraphicsanimatedimageitem.cpp \ - extra/qmlgraphicsparticles.cpp \ extra/qmlbehavior.cpp \ extra/qmlfontloader.cpp @@ -15,7 +14,6 @@ HEADERS += \ extra/qmlgraphicsintegermodel_p.h \ extra/qmlgraphicsanimatedimageitem_p.h \ extra/qmlgraphicsanimatedimageitem_p_p.h \ - extra/qmlgraphicsparticles_p.h \ extra/qmlbehavior_p.h \ extra/qmlfontloader_p.h diff --git a/src/declarative/extra/qmlgraphicsparticles.cpp b/src/declarative/extra/qmlgraphicsparticles.cpp deleted file mode 100644 index 0349a4e..0000000 --- a/src/declarative/extra/qmlgraphicsparticles.cpp +++ /dev/null @@ -1,1134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "private/qmlgraphicsitem_p.h" - -#include -#include -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#define M_PI_2 (M_PI / 2.) -#endif -#ifndef INT_MAX -#define INT_MAX 2147483647 -#endif -#include -#include -#include -#include - -#include "qmlgraphicsparticles_p.h" -#include -#include -#include - -QT_BEGIN_NAMESPACE -#define PI_SQR 9.8696044 -// parabolic approximation -inline qreal fastSin(qreal theta) -{ - const qreal b = 4 / M_PI; - const qreal c = -4 / PI_SQR; - - qreal y = b * theta + c * theta * qAbs(theta); - return y; -} - -inline qreal fastCos(qreal theta) -{ - theta += M_PI_2; - if (theta > M_PI) - theta -= 2 * M_PI; - - return fastSin(theta); -} - -class QmlGraphicsParticle -{ -public: - QmlGraphicsParticle(int time) : lifeSpan(1000), fadeOutAge(800) - , opacity(0), birthTime(time), x_velocity(0), y_velocity(0) - , state(FadeIn), data(0) - { - } - - int lifeSpan; - int fadeOutAge; - qreal x; - qreal y; - qreal opacity; - int birthTime; - qreal x_velocity; - qreal y_velocity; - enum State { FadeIn, Solid, FadeOut }; - State state; - void *data; -}; - -//--------------------------------------------------------------------------- - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotion,QmlGraphicsParticleMotion) - -/*! - \class QmlGraphicsParticleMotion - \ingroup group_effects - \brief The QmlGraphicsParticleMotion class is the base class for particle motion. - \internal - - This class causes the particles to remain static. -*/ - -/*! - Constructs a QmlGraphicsParticleMotion with parent object \a parent. -*/ -QmlGraphicsParticleMotion::QmlGraphicsParticleMotion(QObject *parent) : - QObject(parent) -{ -} - -/*! - Move the \a particle to its new position. \a interval is the number of - milliseconds elapsed since it was last moved. -*/ -void QmlGraphicsParticleMotion::advance(QmlGraphicsParticle &particle, int interval) -{ - Q_UNUSED(particle); - Q_UNUSED(interval); -} - -/*! - The \a particle has just been created. Some motion strategies require - additional state information. This can be allocated by this function. -*/ -void QmlGraphicsParticleMotion::created(QmlGraphicsParticle &particle) -{ - Q_UNUSED(particle); -} - -/*! - The \a particle is about to be destroyed. Any additional memory - that has been allocated for the particle should be freed. -*/ -void QmlGraphicsParticleMotion::destroy(QmlGraphicsParticle &particle) -{ - Q_UNUSED(particle); -} - -/*! - \qmlclass ParticleMotionLinear - \brief The ParticleMotionLinear object moves particles linearly. - - \sa Particles -*/ - -/*! - \internal - \class QmlGraphicsParticleMotionLinear - \ingroup group_effects - \brief The QmlGraphicsParticleMotionLinear class moves the particles linearly. -*/ - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionLinear,QmlGraphicsParticleMotionLinear) - -void QmlGraphicsParticleMotionLinear::advance(QmlGraphicsParticle &p, int interval) -{ - p.x += interval * p.x_velocity; - p.y += interval * p.y_velocity; -} - -/*! - \qmlclass ParticleMotionGravity - \brief The ParticleMotionGravity object moves particles towards a point. - - \sa Particles -*/ - -/*! - \internal - \class QmlGraphicsParticleMotionGravity - \ingroup group_effects - \brief The QmlGraphicsParticleMotionGravity class moves the particles towards a point. -*/ - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionGravity,QmlGraphicsParticleMotionGravity) - -/*! - \qmlproperty int ParticleMotionGravity::xattractor - \qmlproperty int ParticleMotionGravity::yattractor - These properties hold the x and y coordinates of the point attracting the particles. -*/ - -/*! - \qmlproperty int ParticleMotionGravity::acceleration - This property holds the acceleration to apply to the particles. -*/ - -/*! - \property QmlGraphicsParticleMotionGravity::xattractor - \brief the x coordinate of the point attracting the particles. -*/ - -/*! - \property QmlGraphicsParticleMotionGravity::yattractor - \brief the y coordinate of the point attracting the particles. -*/ - -/*! - \property QmlGraphicsParticleMotionGravity::acceleration - \brief the acceleration to apply to the particles. -*/ - -void QmlGraphicsParticleMotionGravity::advance(QmlGraphicsParticle &p, int interval) -{ - qreal xdiff = p.x - _xAttr; - qreal ydiff = p.y - _yAttr; - - qreal xcomp = xdiff / (xdiff + ydiff); - qreal ycomp = ydiff / (xdiff + ydiff); - - p.x_velocity += xcomp * _accel * interval; - p.y_velocity += ycomp * _accel * interval; - - p.x += interval * p.x_velocity; - p.y += interval * p.y_velocity; -} - -/*! - \qmlclass ParticleMotionWander - \brief The ParticleMotionWander object moves particles in a somewhat random fashion. - - The particles will continue roughly in the original direction, however will randomly - drift to each side. - - The code below produces an effect similar to falling snow. - - \qml -Rectangle { - width: 240 - height: 320 - color: "black" - - Particles { - y: 0 - width: parent.width - height: 30 - source: "star.png" - lifeSpan: 5000 - count: 50 - angle: 70 - angleDeviation: 36 - velocity: 30 - velocityDeviation: 10 - ParticleMotionWander { - xvariance: 30 - pace: 100 - } - } -} - \endqml - - \sa Particles -*/ - -/*! - \internal - \class QmlGraphicsParticleMotionWander - \ingroup group_effects - \brief The QmlGraphicsParticleMotionWander class moves particles in a somewhat random fashion. - - The particles will continue roughly in the original direction, however will randomly - drift to each side. -*/ - -/*! - \qmlproperty int QmlGraphicsParticleMotionWander::xvariance - \qmlproperty int QmlGraphicsParticleMotionWander::yvariance - - These properties set the amount to wander in the x and y directions. -*/ - -/*! - \qmlproperty int QmlGraphicsParticleMotionWander::pace - This property holds how quickly the paricles will move from side to side. -*/ - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionWander,QmlGraphicsParticleMotionWander) - -void QmlGraphicsParticleMotionWander::advance(QmlGraphicsParticle &p, int interval) -{ - if (!particles) - particles = qobject_cast(parent()); - if (particles) { - Data *d = (Data*)p.data; - if (_xvariance != 0.) { - qreal xdiff = p.x_velocity - d->x_targetV; - if ((xdiff > d->x_peak && d->x_var > 0.0) || (xdiff < -d->x_peak && d->x_var < 0.0)) { - d->x_var = -d->x_var; - d->x_peak = _xvariance + _xvariance * qreal(rand()) / RAND_MAX; - } - p.x_velocity += d->x_var * interval; - } - p.x += interval * p.x_velocity; - - if (_yvariance != 0.) { - qreal ydiff = p.y_velocity - d->y_targetV; - if ((ydiff > d->y_peak && d->y_var > 0.0) || (ydiff < -d->y_peak && d->y_var < 0.0)) { - d->y_var = -d->y_var; - d->y_peak = _yvariance + _yvariance * qreal(rand()) / RAND_MAX; - } - p.y_velocity += d->y_var * interval; - } - p.y += interval * p.y_velocity; - } -} - -void QmlGraphicsParticleMotionWander::created(QmlGraphicsParticle &p) -{ - if (!p.data) { - Data *d = new Data; - p.data = (void*)d; - d->x_targetV = p.x_velocity; - d->y_targetV = p.y_velocity; - d->x_peak = _xvariance; - d->y_peak = _yvariance; - d->x_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; - d->y_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; - } -} - -void QmlGraphicsParticleMotionWander::destroy(QmlGraphicsParticle &p) -{ - if (p.data) - delete (Data*)p.data; -} - -//--------------------------------------------------------------------------- -class QmlGraphicsParticlesPainter : public QmlGraphicsItem -{ -public: - QmlGraphicsParticlesPainter(QmlGraphicsParticlesPrivate *p, QmlGraphicsItem* parent) - : QmlGraphicsItem(parent), d(p) - { - setFlag(QGraphicsItem::ItemHasNoContents, false); - maxX = minX = maxY = minY = 0; - } - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - - void updateSize(); - - qreal maxX; - qreal minX; - qreal maxY; - qreal minY; - QmlGraphicsParticlesPrivate* d; -}; - -//--------------------------------------------------------------------------- -class QmlGraphicsParticlesPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsParticles) -public: - QmlGraphicsParticlesPrivate() - : count(1), lifeSpan(1000), lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300) - , angle(0), angleDev(0), velocity(0), velocityDev(0) - , addParticleTime(0), addParticleCount(0), lastAdvTime(0), stream(false), streamDelay(0) - , emitting(true), motion(0), pendingPixmapCache(false), clock(this) - { - } - - ~QmlGraphicsParticlesPrivate() - { - } - - void init() - { - Q_Q(QmlGraphicsParticles); - paintItem = new QmlGraphicsParticlesPainter(this, q); - } - - void tick(int time); - void createParticle(int time); - void updateOpacity(QmlGraphicsParticle &p, int age); - - QUrl url; - QPixmap image; - int count; - int lifeSpan; - int lifeSpanDev; - int fadeInDur; - int fadeOutDur; - qreal angle; - qreal angleDev; - qreal velocity; - qreal velocityDev; - int addParticleTime; - int addParticleCount; - int lastAdvTime; - bool stream; - int streamDelay; - bool emitting; - QmlGraphicsParticleMotion *motion; - QmlGraphicsParticlesPainter *paintItem; - - bool pendingPixmapCache; - - QList particles; - QTickAnimationProxy clock; - -}; - -void QmlGraphicsParticlesPrivate::tick(int time) -{ - Q_Q(QmlGraphicsParticles); - if (!motion) - motion = new QmlGraphicsParticleMotionLinear(q); - - int oldCount = particles.count(); - int removed = 0; - int interval = time - lastAdvTime; - for (int i = 0; i < particles.count(); ) { - QmlGraphicsParticle &particle = particles[i]; - int age = time - particle.birthTime; - if (age >= particle.lifeSpan) { - QmlGraphicsParticle part = particles.takeAt(i); - motion->destroy(part); - ++removed; - } else { - updateOpacity(particle, age); - motion->advance(particle, interval); - ++i; - } - } - - while(removed-- && particles.count() < count && emitting) - createParticle(time); - - if (!addParticleTime) - addParticleTime = time; - - if (particles.count() < count && emitting) { - qreal perc = (lifeSpanDev <= 0)?(1.):(qreal(time - addParticleTime) / qreal(lifeSpanDev)); - int percCount = addParticleCount + (int)perc * (count - addParticleCount); - int streamWidth = -1; - if (stream){ - if (streamDelay > time){ - streamWidth = 0; - }else{ - int missed = time - streamDelay; - qreal streamWidthReal = qreal(count)/qreal(lifeSpan); - if (streamWidthReal < 1){ - streamDelay = time + (int)(1.0/streamWidthReal); - streamWidth = 1; - streamWidth += missed/streamDelay; - }else{ - streamWidth = qRound(streamWidthReal * (time-lastAdvTime)); - } - } - } - while(particles.count() < count && - (!stream || (particles.count() < percCount && streamWidth--))) - createParticle(time); - } - - lastAdvTime = time; - paintItem->updateSize(); - paintItem->update(); - if (!(oldCount || particles.count()) && (!count || !emitting)) { - lastAdvTime = 0; - clock.stop(); - } -} - -void QmlGraphicsParticlesPrivate::createParticle(int time) -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer x; -#endif - Q_Q(QmlGraphicsParticles); - QmlGraphicsParticle p(time); - p.x = q->x() + q->width() * qreal(rand()) / RAND_MAX - image.width()/2.0; - p.y = q->y() + q->height() * qreal(rand()) / RAND_MAX - image.height()/2.0; - p.lifeSpan = lifeSpan; - if (lifeSpanDev) - p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(rand()) / RAND_MAX); - p.fadeOutAge = p.lifeSpan - fadeOutDur; - if (fadeInDur == 0.) { - p.state= QmlGraphicsParticle::Solid; - p.opacity = 1.0; - } - qreal a = angle; - if (angleDev) - a += angleDev/2 - angleDev * qreal(rand()) / RAND_MAX; - if (a > M_PI) - a = a - 2 * M_PI; - qreal v = velocity; - if (velocityDev) - v += velocityDev/2 - velocityDev * qreal(rand()) / RAND_MAX; - p.x_velocity = v * fastCos(a); - p.y_velocity = v * fastSin(a); - particles.append(p); - motion->created(particles.last()); -} - -void QmlGraphicsParticlesPrivate::updateOpacity(QmlGraphicsParticle &p, int age) -{ - switch (p.state) { - case QmlGraphicsParticle::FadeIn: - if (age <= fadeInDur) { - p.opacity = qreal(age) / fadeInDur; - break; - } else { - p.opacity = 1.0; - p.state = QmlGraphicsParticle::Solid; - // Fall through - } - case QmlGraphicsParticle::Solid: - if (age <= p.fadeOutAge) { - break; - } else { - p.state = QmlGraphicsParticle::FadeOut; - // Fall through - } - case QmlGraphicsParticle::FadeOut: - p.opacity = qreal(p.lifeSpan - age) / fadeOutDur; - break; - } -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Particles,QmlGraphicsParticles) - -/*! - \qmlclass Particles - \brief The Particles object generates and moves particles. - \inherits Item - - The particles created by this object cannot be dealt with directly, they can only be controlled through the parameters of the Particles object. The particles are all the same pixmap, specified by the user. - - The particles are painted relative to the parent of the Particles object. Moving the - Particles object will not move the particles already emitted. - - The below example creates two differently behaving particle sources. - The top one has particles falling from the top like snow, - the lower one has particles expelled up like a fountain. - - \qml -Rectangle { - width: 240 - height: 320 - color: "black" - Particles { - y: 0 - width: parent.width - height: 30 - source: "star.png" - lifeSpan: 5000 - count: 50 - angle: 70 - angleDeviation: 36 - velocity: 30 - velocityDeviation: 10 - ParticleMotionWander { - xvariance: 30 - pace: 100 - } - } - Particles { - y: 300 - x: 120 - width: 1 - height: 1 - source: "star.png" - lifeSpan: 5000 - count: 200 - angle: 270 - angleDeviation: 45 - velocity: 50 - velocityDeviation: 30 - ParticleMotionGravity { - yattractor: 1000 - xattractor: 0 - acceleration: 25 - } - } -} - \endqml - \image particles.gif -*/ - -/*! - \internal - \class QmlGraphicsParticles - \ingroup group_effects - \brief The QmlGraphicsParticles class generates and moves particles. -*/ - -QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsParticlesPrivate), parent) -{ - Q_D(QmlGraphicsParticles); - d->init(); -} - -QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - Q_D(QmlGraphicsParticles); - d->init(); -} - -QmlGraphicsParticles::~QmlGraphicsParticles() -{ - Q_D(QmlGraphicsParticles); - if (d->pendingPixmapCache) - QmlPixmapCache::cancelGet(d->url, this); -} - -/*! - \qmlproperty string Particles::src - This property holds the URL of the particle image. -*/ - -/*! - \property QmlGraphicsParticles::source - \brief the URL of the particle image. -*/ -QUrl QmlGraphicsParticles::source() const -{ - Q_D(const QmlGraphicsParticles); - return d->url; -} - -void QmlGraphicsParticles::imageLoaded() -{ - Q_D(QmlGraphicsParticles); - d->pendingPixmapCache = false; - QmlPixmapCache::find(d->url, &d->image); - d->paintItem->updateSize(); - d->paintItem->update(); -} - -void QmlGraphicsParticles::setSource(const QUrl &name) -{ - Q_D(QmlGraphicsParticles); - - if ((d->url.isEmpty() == name.isEmpty()) && name == d->url) - return; - - if (d->pendingPixmapCache) { - QmlPixmapCache::cancelGet(d->url, this); - d->pendingPixmapCache = false; - } - if (name.isEmpty()) { - d->url = name; - d->image = QPixmap(); - d->paintItem->updateSize(); - d->paintItem->update(); - } else { - d->url = name; - Q_ASSERT(!name.isRelative()); - QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->url, &d->image); - if (reply) { - connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded())); - d->pendingPixmapCache = true; - } else { - //### unify with imageLoaded - d->paintItem->updateSize(); - d->paintItem->update(); - } - } -} - -/*! - \qmlproperty int Particles::count - This property holds the target number of particles -*/ - -/*! - \property QmlGraphicsParticles::count - \brief the target number of particles -*/ -int QmlGraphicsParticles::count() const -{ - Q_D(const QmlGraphicsParticles); - return d->count; -} - -void QmlGraphicsParticles::setCount(int cnt) -{ - Q_D(QmlGraphicsParticles); - if (cnt == d->count) - return; - - int oldCount = d->count; - d->count = cnt; - d->addParticleTime = 0; - d->addParticleCount = d->particles.count(); - if (!oldCount && d->clock.state() != QAbstractAnimation::Running && d->count) { - d->clock.start(); - } - d->paintItem->updateSize(); - d->paintItem->update(); -} - -/*! - \qmlproperty int Particles::lifeSpan - \qmlproperty int Particles::lifeSpanDeviation - - These properties describe the life span of each particle. - - The default lifespan for a particle is 1000ms. - - lifeSpanDeviation randomly varies the lifeSpan up to the specified variation. For - example, the following creates particles whose lifeSpan will vary - from 150ms to 250ms: - - \qml -Particles { - source: "star.png" - lifeSpan: 200 - lifeSpanDeviation: 100 -} - \endqml -*/ - -/*! - \property QmlGraphicsParticles::lifeSpan - \brief the life span of each particle. - - Default value is 1000ms. - - \sa QmlGraphicsParticles::lifeSpanDeviation -*/ -int QmlGraphicsParticles::lifeSpan() const -{ - Q_D(const QmlGraphicsParticles); - return d->lifeSpan; -} - -void QmlGraphicsParticles::setLifeSpan(int ls) -{ - Q_D(QmlGraphicsParticles); - d->lifeSpan = ls; -} - -/*! - \property QmlGraphicsParticles::lifeSpanDeviation - \brief the maximum possible deviation from the set lifeSpan. - - Randomly varies the lifeSpan up to the specified variation. For - example, the following creates particles whose lifeSpan will vary - from 150ms to 250ms: - -\qml -Particles { - source: "star.png" - lifeSpan: 200 - lifeSpanDeviation: 100 -} -\endqml - - \sa QmlGraphicsParticles::lifeSpan -*/ -int QmlGraphicsParticles::lifeSpanDeviation() const -{ - Q_D(const QmlGraphicsParticles); - return d->lifeSpanDev; -} - -void QmlGraphicsParticles::setLifeSpanDeviation(int dev) -{ - Q_D(QmlGraphicsParticles); - d->lifeSpanDev = dev; -} - -/*! - \qmlproperty int Particles::fadeInDuration - \qmlproperty int Particles::fadeOutDuration - These properties hold the time taken to fade the particles in and out. - - By default fade in is 200ms and fade out is 300ms. -*/ - -/*! - \property QmlGraphicsParticles::fadeInDuration - \brief the time taken to fade in the particles. - - Default value is 200ms. -*/ -int QmlGraphicsParticles::fadeInDuration() const -{ - Q_D(const QmlGraphicsParticles); - return d->fadeInDur; -} - -void QmlGraphicsParticles::setFadeInDuration(int dur) -{ - Q_D(QmlGraphicsParticles); - if (dur >= 0.0) - d->fadeInDur = dur; -} - -/*! - \property QmlGraphicsParticles::fadeOutDuration - \brief the time taken to fade out the particles. - - Default value is 300ms. -*/ -int QmlGraphicsParticles::fadeOutDuration() const -{ - Q_D(const QmlGraphicsParticles); - return d->fadeOutDur; -} - -void QmlGraphicsParticles::setFadeOutDuration(int dur) -{ - Q_D(QmlGraphicsParticles); - if (dur >= 0.0) - d->fadeOutDur = dur; -} - -/*! - \qmlproperty real Particles::angle - \qmlproperty real Particles::angleDeviation - - These properties control particle direction. - - angleDeviation randomly varies the direction up to the specified variation. For - example, the following creates particles whose initial direction will - vary from 15 degrees to 105 degrees: - - \qml -Particles { - source: "star.png" - angle: 60 - angleDeviation: 90 -} - \endqml -*/ - -/*! - \property QmlGraphicsParticles::angle - \brief the initial angle of direction. - - \sa QmlGraphicsParticles::angleDeviation -*/ -qreal QmlGraphicsParticles::angle() const -{ - Q_D(const QmlGraphicsParticles); - return d->angle * 180.0 / M_PI; -} - -void QmlGraphicsParticles::setAngle(qreal angle) -{ - Q_D(QmlGraphicsParticles); - d->angle = angle * M_PI / 180.0; -} - -/*! - \property QmlGraphicsParticles::angleDeviation - \brief the maximum possible deviation from the set angle. - - Randomly varies the direction up to the specified variation. For - example, the following creates particles whose initial direction will - vary from 15 degrees to 105 degrees: - -\qml -Particles { - source: "star.png" - angle: 60 - angleDeviation: 90 -} -\endqml - - \sa QmlGraphicsParticles::angle -*/ -qreal QmlGraphicsParticles::angleDeviation() const -{ - Q_D(const QmlGraphicsParticles); - return d->angleDev * 180.0 / M_PI; -} - -void QmlGraphicsParticles::setAngleDeviation(qreal dev) -{ - Q_D(QmlGraphicsParticles); - d->angleDev = dev * M_PI / 180.0;; -} - -/*! - \qmlproperty real Particles::velocity - \qmlproperty real Particles::velocityDeviation - - These properties control the velocity of the particles. - - velocityDeviation randomly varies the velocity up to the specified variation. For - example, the following creates particles whose initial velocity will - vary from 40 to 60. - - \qml -Particles { - source: "star.png" - velocity: 50 - velocityDeviation: 20 -} - \endqml -*/ - -/*! - \property QmlGraphicsParticles::velocity - \brief the initial velocity of the particles. - - \sa QmlGraphicsParticles::velocityDeviation -*/ -qreal QmlGraphicsParticles::velocity() const -{ - Q_D(const QmlGraphicsParticles); - return d->velocity * 1000.0; -} - -void QmlGraphicsParticles::setVelocity(qreal velocity) -{ - Q_D(QmlGraphicsParticles); - d->velocity = velocity / 1000.0; -} - -/*! - \property QmlGraphicsParticles::velocityDeviation - \brief the maximum possible deviation from the set velocity. - - Randomly varies the velocity up to the specified variation. For - example, the following creates particles whose initial velocity will - vary from 40 to 60. - -\qml -Particles { - source: "star.png" - velocity: 50 - velocityDeviation: 20 -} -\endqml - - \sa QmlGraphicsParticles::velocity -*/ -qreal QmlGraphicsParticles::velocityDeviation() const -{ - Q_D(const QmlGraphicsParticles); - return d->velocityDev * 1000.0; -} - -void QmlGraphicsParticles::setVelocityDeviation(qreal velocity) -{ - Q_D(QmlGraphicsParticles); - d->velocityDev = velocity / 1000.0; -} - -/*! - \qmlproperty bool Particles::streamIn - This property determines whether the particles stream in at a constant rate - - When stream is set to true the particles will stream in at a constant rate. - Otherwise the particles will appear as a clump. Note that this only affects the - start of the particle effect, variables such as lifespan deviation can cause the - particles to unclump over time. -*/ -/*! - \property QmlGraphicsParticles::streamIn - \brief determines whether the particles stream in at a constant rate - - When stream is set to true the particles will stream in at a constant rate. - Otherwise the particles will appear as a clump. Note that this only affects the - start of the particle effect, variables such as lifespan deviation can cause the - -*/ -//The name may need a rethink -bool QmlGraphicsParticles::streamIn() const -{ - Q_D(const QmlGraphicsParticles); - return d->stream; -} - -void QmlGraphicsParticles::setStreamIn(bool b) -{ - Q_D(QmlGraphicsParticles); - d->stream = b; -} - -/*! - \qmlproperty bool Particles::emitting - This property determines whether new particles are created - - If emitting is set to false no new particles will be created. This means that - when a particle reaches the end of its lifespan it is not replaced. This - property can be used to turn particles on and off with a more natural look. - - The default setting is true. Note that if it initialized to false no particles - will be produced until it is set to true. -*/ -/*! - \property QmlGraphicsParticles::emitting - If emitting is set to false no new particles will be created. This means that - when a particle reaches the end of its lifespan it is not replaced. This - property can be used to turn particles on and off with a more natural look. - - The default setting is true. Note that if it initialized to false no particles - will be produced until it is set to true. -*/ -bool QmlGraphicsParticles::emitting() const -{ - Q_D(const QmlGraphicsParticles); - return d->emitting; -} - -void QmlGraphicsParticles::setEmitting(bool r) -{ - Q_D(QmlGraphicsParticles); - d->emitting = r; - if (d->count && r) - d->clock.start(); -} -/*! - \qmlproperty ParticleMotion Particles::motion - This property sets the type of motion to apply to the particles. - - When a particle is created it will have an initial direction and velocity. - The motion of the particle during its lifeSpan is then influenced by the - motion property. - - Default motion is ParticleMotionLinear. -*/ - -/*! - \property QmlGraphicsParticles::motion - \brief sets the type of motion to apply to the particles. - - When a particle is created it will have an initial direction and velocity. - The motion of the particle during its lifeSpan is then influenced by the - motion property. - - Default motion is QmlGraphicsParticleMotionLinear. -*/ -QmlGraphicsParticleMotion *QmlGraphicsParticles::motion() const -{ - Q_D(const QmlGraphicsParticles); - return d->motion; -} - -void QmlGraphicsParticles::setMotion(QmlGraphicsParticleMotion *motion) -{ - Q_D(QmlGraphicsParticles); - d->motion = motion; -} - -void QmlGraphicsParticlesPainter::updateSize() -{ - if (!isComponentComplete()) - return; - - const int parentX = parentItem()->x(); - const int parentY = parentItem()->y(); - for (int i = 0; i < d->particles.count(); ++i) { - const QmlGraphicsParticle &particle = d->particles.at(i); - if(particle.x > maxX) - maxX = particle.x; - if(particle.x < minX) - minX = particle.x; - if(particle.y > maxY) - maxY = particle.y; - if(particle.y < minY) - minY = particle.y; - } - - int myWidth = (int)(maxX-minX+0.5)+d->image.width(); - int myX = (int)(minX - parentX); - int myHeight = (int)(maxY-minY+0.5)+d->image.height(); - int myY = (int)(minY - parentY); - setWidth(myWidth); - setHeight(myHeight); - setX(myX); - setY(myY); -} - -void QmlGraphicsParticles::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_UNUSED(p); - //painting is done by the ParticlesPainter, so it can have the right size -} - -void QmlGraphicsParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - if (d->image.isNull() || d->particles.isEmpty()) - return; - - const int myX = x() + parentItem()->x(); - const int myY = y() + parentItem()->y(); - - static QVarLengthArray pixmapData; - if (pixmapData.count() < d->particles.count()) - pixmapData.resize(d->particles.count()); - - const QRectF sourceRect = d->image.rect(); - for (int i = 0; i < d->particles.count(); ++i) { - const QmlGraphicsParticle &particle = d->particles.at(i); - pixmapData[i].point = QPointF(particle.x - myX, particle.y - myY); - pixmapData[i].opacity = particle.opacity; - - //these never change - pixmapData[i].rotation = 0; - pixmapData[i].scaleX = 1; - pixmapData[i].scaleY = 1; - pixmapData[i].source = sourceRect; - } - qDrawPixmaps(p, pixmapData.data(), d->particles.count(), d->image); -} - -void QmlGraphicsParticles::componentComplete() -{ - Q_D(QmlGraphicsParticles); - QmlGraphicsItem::componentComplete(); - if (d->count) { - d->paintItem->updateSize(); - d->clock.start(); - } - if (d->lifeSpanDev > d->lifeSpan) - d->lifeSpanDev = d->lifeSpan; -} - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlgraphicsparticles_p.h b/src/declarative/extra/qmlgraphicsparticles_p.h deleted file mode 100644 index 9eca762..0000000 --- a/src/declarative/extra/qmlgraphicsparticles_p.h +++ /dev/null @@ -1,230 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLGRAPHICSPARTICLES_H -#define QMLGRAPHICSPARTICLES_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsParticle; -class QmlGraphicsParticles; -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotion : public QObject -{ - Q_OBJECT -public: - QmlGraphicsParticleMotion(QObject *parent=0); - - virtual void advance(QmlGraphicsParticle &, int interval); - virtual void created(QmlGraphicsParticle &); - virtual void destroy(QmlGraphicsParticle &); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionLinear : public QmlGraphicsParticleMotion -{ - Q_OBJECT -public: - QmlGraphicsParticleMotionLinear(QObject *parent=0) - : QmlGraphicsParticleMotion(parent) {} - - virtual void advance(QmlGraphicsParticle &, int interval); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionGravity : public QmlGraphicsParticleMotion -{ - Q_OBJECT - - Q_PROPERTY(int xattractor READ xAttractor WRITE setXAttractor) - Q_PROPERTY(int yattractor READ yAttractor WRITE setYAttractor) - Q_PROPERTY(int acceleration READ acceleration WRITE setAcceleration) -public: - QmlGraphicsParticleMotionGravity(QObject *parent=0) - : QmlGraphicsParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} - - int xAttractor() const { return _xAttr; } - void setXAttractor(int x) { _xAttr = x; } - - int yAttractor() const { return _yAttr; } - void setYAttractor(int y) { _yAttr = y; } - - int acceleration() const { return int(_accel * 1000000); } - void setAcceleration(int accel) { _accel = qreal(accel)/1000000.0; } - - virtual void advance(QmlGraphicsParticle &, int interval); - -private: - int _xAttr; - int _yAttr; - qreal _accel; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionWander : public QmlGraphicsParticleMotion -{ - Q_OBJECT -public: - QmlGraphicsParticleMotionWander() - : QmlGraphicsParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {} - - virtual void advance(QmlGraphicsParticle &, int interval); - virtual void created(QmlGraphicsParticle &); - virtual void destroy(QmlGraphicsParticle &); - - struct Data { - qreal x_targetV; - qreal y_targetV; - qreal x_peak; - qreal y_peak; - qreal x_var; - qreal y_var; - }; - - Q_PROPERTY(int xvariance READ xVariance WRITE setXVariance) - int xVariance() const { return int(_xvariance * 1000); } - void setXVariance(int var) { _xvariance = var / 1000.0; } - - Q_PROPERTY(int yvariance READ yVariance WRITE setYVariance) - int yVariance() const { return int(_yvariance * 1000); } - void setYVariance(int var) { _yvariance = var / 1000.0; } - - Q_PROPERTY(int pace READ pace WRITE setPace) - int pace() const { return int(_pace * 1000); } - void setPace(int pace) { _pace = pace / 1000.0; } - -private: - QmlGraphicsParticles *particles; - qreal _xvariance; - qreal _yvariance; - qreal _pace; -}; - -class QmlGraphicsParticlesPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsParticles : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(int count READ count WRITE setCount) - Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan) - Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation) - Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration) - Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration) - Q_PROPERTY(qreal angle READ angle WRITE setAngle) - Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation) - Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) - Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation) - Q_PROPERTY(bool streamIn READ streamIn WRITE setStreamIn) - Q_PROPERTY(bool emitting READ emitting WRITE setEmitting) - Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion) - Q_CLASSINFO("DefaultProperty", "motion") - -public: - QmlGraphicsParticles(QmlGraphicsItem *parent=0); - ~QmlGraphicsParticles(); - - QUrl source() const; - void setSource(const QUrl &); - - int count() const; - void setCount(int cnt); - - int lifeSpan() const; - void setLifeSpan(int); - - int lifeSpanDeviation() const; - void setLifeSpanDeviation(int); - - int fadeInDuration() const; - void setFadeInDuration(int); - - int fadeOutDuration() const; - void setFadeOutDuration(int); - - qreal angle() const; - void setAngle(qreal); - - qreal angleDeviation() const; - void setAngleDeviation(qreal); - - qreal velocity() const; - void setVelocity(qreal); - - qreal velocityDeviation() const; - void setVelocityDeviation(qreal); - - bool streamIn() const; - void setStreamIn(bool); - - bool emitting() const; - void setEmitting(bool); - - QmlGraphicsParticleMotion *motion() const; - void setMotion(QmlGraphicsParticleMotion *); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -protected: - virtual void componentComplete(); - QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent); - -private Q_SLOTS: - void imageLoaded(); - -private: - Q_DISABLE_COPY(QmlGraphicsParticles) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsParticles) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsParticleMotion) -QML_DECLARE_TYPE(QmlGraphicsParticleMotionLinear) -QML_DECLARE_TYPE(QmlGraphicsParticleMotionGravity) -QML_DECLARE_TYPE(QmlGraphicsParticleMotionWander) -QML_DECLARE_TYPE(QmlGraphicsParticles) - -QT_END_HEADER - -#endif diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index cf71451..3c4e39a 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -42,6 +42,7 @@ HEADERS += \ graphicsitems/qmlgraphicsvisualitemmodel_p.h \ graphicsitems/qmlgraphicslistview_p.h \ graphicsitems/qmlgraphicsgraphicsobjectcontainer_p.h \ + graphicsitems/qmlgraphicsparticles_p.h \ graphicsitems/qmlgraphicslayoutitem_p.h \ graphicsitems/qmlgraphicseffects.cpp @@ -72,6 +73,7 @@ SOURCES += \ graphicsitems/qmlgraphicsvisualitemmodel.cpp \ graphicsitems/qmlgraphicslistview.cpp \ graphicsitems/qmlgraphicsgraphicsobjectcontainer.cpp \ + graphicsitems/qmlgraphicsparticles.cpp \ graphicsitems/qmlgraphicslayoutitem.cpp \ contains(QT_CONFIG, webkit) { diff --git a/src/declarative/graphicsitems/qmlgraphicsparticles.cpp b/src/declarative/graphicsitems/qmlgraphicsparticles.cpp new file mode 100644 index 0000000..d906fd3 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsparticles.cpp @@ -0,0 +1,1278 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qmlgraphicsitem_p.h" + +#include +#include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#define M_PI_2 (M_PI / 2.) +#endif +#ifndef INT_MAX +#define INT_MAX 2147483647 +#endif +#include +#include +#include +#include + +#include "qmlgraphicsparticles_p.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE +#define PI_SQR 9.8696044 +// parabolic approximation +inline qreal fastSin(qreal theta) +{ + const qreal b = 4 / M_PI; + const qreal c = -4 / PI_SQR; + + qreal y = b * theta + c * theta * qAbs(theta); + return y; +} + +inline qreal fastCos(qreal theta) +{ + theta += M_PI_2; + if (theta > M_PI) + theta -= 2 * M_PI; + + return fastSin(theta); +} + +class QmlGraphicsParticle +{ +public: + QmlGraphicsParticle(int time) : lifeSpan(1000), fadeOutAge(800) + , opacity(0), birthTime(time), x_velocity(0), y_velocity(0) + , state(FadeIn), data(0) + { + } + + int lifeSpan; + int fadeOutAge; + qreal x; + qreal y; + qreal opacity; + int birthTime; + qreal x_velocity; + qreal y_velocity; + enum State { FadeIn, Solid, FadeOut }; + State state; + void *data; +}; + +//--------------------------------------------------------------------------- + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotion,QmlGraphicsParticleMotion) + +/*! + \class QmlGraphicsParticleMotion + \ingroup group_effects + \brief The QmlGraphicsParticleMotion class is the base class for particle motion. + \internal + + This class causes the particles to remain static. +*/ + +/*! + Constructs a QmlGraphicsParticleMotion with parent object \a parent. +*/ +QmlGraphicsParticleMotion::QmlGraphicsParticleMotion(QObject *parent) : + QObject(parent) +{ +} + +/*! + Move the \a particle to its new position. \a interval is the number of + milliseconds elapsed since it was last moved. +*/ +void QmlGraphicsParticleMotion::advance(QmlGraphicsParticle &particle, int interval) +{ + Q_UNUSED(particle); + Q_UNUSED(interval); +} + +/*! + The \a particle has just been created. Some motion strategies require + additional state information. This can be allocated by this function. +*/ +void QmlGraphicsParticleMotion::created(QmlGraphicsParticle &particle) +{ + Q_UNUSED(particle); +} + +/*! + The \a particle is about to be destroyed. Any additional memory + that has been allocated for the particle should be freed. +*/ +void QmlGraphicsParticleMotion::destroy(QmlGraphicsParticle &particle) +{ + Q_UNUSED(particle); +} + +/*! + \qmlclass ParticleMotionLinear + \brief The ParticleMotionLinear object moves particles linearly. + + \sa Particles +*/ + +/*! + \internal + \class QmlGraphicsParticleMotionLinear + \ingroup group_effects + \brief The QmlGraphicsParticleMotionLinear class moves the particles linearly. +*/ + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionLinear,QmlGraphicsParticleMotionLinear) + +void QmlGraphicsParticleMotionLinear::advance(QmlGraphicsParticle &p, int interval) +{ + p.x += interval * p.x_velocity; + p.y += interval * p.y_velocity; +} + +/*! + \qmlclass ParticleMotionGravity + \brief The ParticleMotionGravity object moves particles towards a point. + + \sa Particles +*/ + +/*! + \internal + \class QmlGraphicsParticleMotionGravity + \ingroup group_effects + \brief The QmlGraphicsParticleMotionGravity class moves the particles towards a point. +*/ + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionGravity,QmlGraphicsParticleMotionGravity) + +/*! + \qmlproperty int ParticleMotionGravity::xattractor + \qmlproperty int ParticleMotionGravity::yattractor + These properties hold the x and y coordinates of the point attracting the particles. +*/ + +/*! + \qmlproperty int ParticleMotionGravity::acceleration + This property holds the acceleration to apply to the particles. +*/ + +/*! + \property QmlGraphicsParticleMotionGravity::xattractor + \brief the x coordinate of the point attracting the particles. +*/ + +/*! + \property QmlGraphicsParticleMotionGravity::yattractor + \brief the y coordinate of the point attracting the particles. +*/ + +/*! + \property QmlGraphicsParticleMotionGravity::acceleration + \brief the acceleration to apply to the particles. +*/ + +void QmlGraphicsParticleMotionGravity::advance(QmlGraphicsParticle &p, int interval) +{ + qreal xdiff = p.x - _xAttr; + qreal ydiff = p.y - _yAttr; + + qreal xcomp = xdiff / (xdiff + ydiff); + qreal ycomp = ydiff / (xdiff + ydiff); + + p.x_velocity += xcomp * _accel * interval; + p.y_velocity += ycomp * _accel * interval; + + p.x += interval * p.x_velocity; + p.y += interval * p.y_velocity; +} + +/*! + \qmlclass ParticleMotionWander + \brief The ParticleMotionWander object moves particles in a somewhat random fashion. + + The particles will continue roughly in the original direction, however will randomly + drift to each side. + + The code below produces an effect similar to falling snow. + + \qml +Rectangle { + width: 240 + height: 320 + color: "black" + + Particles { + y: 0 + width: parent.width + height: 30 + source: "star.png" + lifeSpan: 5000 + count: 50 + angle: 70 + angleDeviation: 36 + velocity: 30 + velocityDeviation: 10 + ParticleMotionWander { + xvariance: 30 + pace: 100 + } + } +} + \endqml + + \sa Particles +*/ + +/*! + \internal + \class QmlGraphicsParticleMotionWander + \ingroup group_effects + \brief The QmlGraphicsParticleMotionWander class moves particles in a somewhat random fashion. + + The particles will continue roughly in the original direction, however will randomly + drift to each side. +*/ + +/*! + \qmlproperty int QmlGraphicsParticleMotionWander::xvariance + \qmlproperty int QmlGraphicsParticleMotionWander::yvariance + + These properties set the amount to wander in the x and y directions. +*/ + +/*! + \qmlproperty int QmlGraphicsParticleMotionWander::pace + This property holds how quickly the paricles will move from side to side. +*/ + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionWander,QmlGraphicsParticleMotionWander) + +void QmlGraphicsParticleMotionWander::advance(QmlGraphicsParticle &p, int interval) +{ + if (!particles) + particles = qobject_cast(parent()); + if (particles) { + Data *d = (Data*)p.data; + if (_xvariance != 0.) { + qreal xdiff = p.x_velocity - d->x_targetV; + if ((xdiff > d->x_peak && d->x_var > 0.0) || (xdiff < -d->x_peak && d->x_var < 0.0)) { + d->x_var = -d->x_var; + d->x_peak = _xvariance + _xvariance * qreal(rand()) / RAND_MAX; + } + p.x_velocity += d->x_var * interval; + } + p.x += interval * p.x_velocity; + + if (_yvariance != 0.) { + qreal ydiff = p.y_velocity - d->y_targetV; + if ((ydiff > d->y_peak && d->y_var > 0.0) || (ydiff < -d->y_peak && d->y_var < 0.0)) { + d->y_var = -d->y_var; + d->y_peak = _yvariance + _yvariance * qreal(rand()) / RAND_MAX; + } + p.y_velocity += d->y_var * interval; + } + p.y += interval * p.y_velocity; + } +} + +void QmlGraphicsParticleMotionWander::created(QmlGraphicsParticle &p) +{ + if (!p.data) { + Data *d = new Data; + p.data = (void*)d; + d->x_targetV = p.x_velocity; + d->y_targetV = p.y_velocity; + d->x_peak = _xvariance; + d->y_peak = _yvariance; + d->x_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; + d->y_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; + } +} + +void QmlGraphicsParticleMotionWander::destroy(QmlGraphicsParticle &p) +{ + if (p.data) + delete (Data*)p.data; +} + +//--------------------------------------------------------------------------- +class QmlGraphicsParticlesPainter : public QmlGraphicsItem +{ +public: + QmlGraphicsParticlesPainter(QmlGraphicsParticlesPrivate *p, QmlGraphicsItem* parent) + : QmlGraphicsItem(parent), d(p) + { + setFlag(QGraphicsItem::ItemHasNoContents, false); + maxX = minX = maxY = minY = 0; + } + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + + void updateSize(); + + qreal maxX; + qreal minX; + qreal maxY; + qreal minY; + QmlGraphicsParticlesPrivate* d; +}; + +//--------------------------------------------------------------------------- +class QmlGraphicsParticlesPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsParticles) +public: + QmlGraphicsParticlesPrivate() + : count(1), emissionRate(-1), emissionVariance(0.5), lifeSpan(1000) + , lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300) + , angle(0), angleDev(0), velocity(0), velocityDev(0), emissionCarry(0.) + , addParticleTime(0), addParticleCount(0), lastAdvTime(0) + , emitting(true), motion(0), pendingPixmapCache(false), clock(this) + { + } + + ~QmlGraphicsParticlesPrivate() + { + } + + void init() + { + Q_Q(QmlGraphicsParticles); + paintItem = new QmlGraphicsParticlesPainter(this, q); + } + + void tick(int time); + void createParticle(int time); + void updateOpacity(QmlGraphicsParticle &p, int age); + + QUrl url; + QPixmap image; + int count; + int emissionRate; + qreal emissionVariance; + int lifeSpan; + int lifeSpanDev; + int fadeInDur; + int fadeOutDur; + qreal angle; + qreal angleDev; + qreal velocity; + qreal velocityDev; + qreal emissionCarry; + int addParticleTime; + int addParticleCount; + int lastAdvTime; + bool emitting; + QmlGraphicsParticleMotion *motion; + QmlGraphicsParticlesPainter *paintItem; + + bool pendingPixmapCache; + + QList > bursts;//countLeft, emissionRate pairs + QList particles; + QTickAnimationProxy clock; + +}; + +void QmlGraphicsParticlesPrivate::tick(int time) +{ + Q_Q(QmlGraphicsParticles); + if (!motion) + motion = new QmlGraphicsParticleMotionLinear(q); + + int oldCount = particles.count(); + int removed = 0; + int interval = time - lastAdvTime; + for (int i = 0; i < particles.count(); ) { + QmlGraphicsParticle &particle = particles[i]; + int age = time - particle.birthTime; + if (age >= particle.lifeSpan) { + QmlGraphicsParticle part = particles.takeAt(i); + motion->destroy(part); + ++removed; + } else { + updateOpacity(particle, age); + motion->advance(particle, interval); + ++i; + } + } + + if(emissionRate == -1)//Otherwise leave emission to the emission rate + while(removed-- && ((count == -1) || particles.count() < count) && emitting) + createParticle(time); + + if (!addParticleTime) + addParticleTime = time; + + //Possibly emit new particles + if (((count == -1) || particles.count() < count) && emitting + && !(count==-1 && emissionRate==-1)) { + int emissionCount = -1; + if (emissionRate != -1){ + qreal variance = 1.; + if (emissionVariance > 0.){ + variance += (qreal(rand())/RAND_MAX) * emissionVariance * (rand()%2?-1.:1.); + } + qreal emission = emissionRate * (qreal(interval)/1000.); + emission = emission * variance + emissionCarry; + double tmpDbl; + emissionCarry = modf(emission, &tmpDbl); + emissionCount = (int)tmpDbl; + emissionCount = qMax(0,emissionCount); + } + while(((count == -1) || particles.count() < count) && + (emissionRate==-1 || emissionCount--)) + createParticle(time); + } + + //Deal with emissions from requested bursts + for(int i=0; i 0.){ + variance += (qreal(rand())/RAND_MAX) * emissionVariance * (rand()%2?-1.:1.); + } + qreal workingEmission = bursts[i].second * (qreal(interval)/1000.); + workingEmission *= variance; + emission = (int)workingEmission; + emission = qMax(emission, 0); + } + emission = qMin(emission, bursts[i].first); + bursts[i].first -= emission; + while(emission--) + createParticle(time); + } + for(int i=bursts.size()-1; i>=0; i--) + if(bursts[i].first <= 0) + bursts.removeAt(i); + + lastAdvTime = time; + paintItem->updateSize(); + paintItem->update(); + if (!(oldCount || particles.count()) && (!count || !emitting) && bursts.isEmpty()) { + lastAdvTime = 0; + clock.stop(); + } +} + +void QmlGraphicsParticlesPrivate::createParticle(int time) +{ +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer x; +#endif + Q_Q(QmlGraphicsParticles); + QmlGraphicsParticle p(time); + p.x = q->x() + q->width() * qreal(rand()) / RAND_MAX - image.width()/2.0; + p.y = q->y() + q->height() * qreal(rand()) / RAND_MAX - image.height()/2.0; + p.lifeSpan = lifeSpan; + if (lifeSpanDev) + p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(rand()) / RAND_MAX); + p.fadeOutAge = p.lifeSpan - fadeOutDur; + if (fadeInDur == 0.) { + p.state= QmlGraphicsParticle::Solid; + p.opacity = 1.0; + } + qreal a = angle; + if (angleDev) + a += angleDev/2 - angleDev * qreal(rand()) / RAND_MAX; + if (a > M_PI) + a = a - 2 * M_PI; + qreal v = velocity; + if (velocityDev) + v += velocityDev/2 - velocityDev * qreal(rand()) / RAND_MAX; + p.x_velocity = v * fastCos(a); + p.y_velocity = v * fastSin(a); + particles.append(p); + motion->created(particles.last()); +} + +void QmlGraphicsParticlesPrivate::updateOpacity(QmlGraphicsParticle &p, int age) +{ + switch (p.state) { + case QmlGraphicsParticle::FadeIn: + if (age <= fadeInDur) { + p.opacity = qreal(age) / fadeInDur; + break; + } else { + p.opacity = 1.0; + p.state = QmlGraphicsParticle::Solid; + // Fall through + } + case QmlGraphicsParticle::Solid: + if (age <= p.fadeOutAge) { + break; + } else { + p.state = QmlGraphicsParticle::FadeOut; + // Fall through + } + case QmlGraphicsParticle::FadeOut: + p.opacity = qreal(p.lifeSpan - age) / fadeOutDur; + break; + } +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Particles,QmlGraphicsParticles) + +/*! + \qmlclass Particles + \brief The Particles object generates and moves particles. + \inherits Item + + This element provides preliminary support for particles in QML, and may be heavily changed or removed in later versions. + + The particles created by this object cannot be dealt with directly, they can only be controlled through the parameters of the Particles object. The particles are all the same pixmap, specified by the user. + + The particles are painted relative to the parent of the Particles object. Moving the + Particles object will not move the particles already emitted. + + The below example creates two differently behaving particle sources. + The top one has particles falling from the top like snow, + the lower one has particles expelled up like a fountain. + + \qml +Rectangle { + width: 240 + height: 320 + color: "black" + Particles { + y: 0 + width: parent.width + height: 30 + source: "star.png" + lifeSpan: 5000 + count: 50 + angle: 70 + angleDeviation: 36 + velocity: 30 + velocityDeviation: 10 + ParticleMotionWander { + xvariance: 30 + pace: 100 + } + } + Particles { + y: 300 + x: 120 + width: 1 + height: 1 + source: "star.png" + lifeSpan: 5000 + count: 200 + angle: 270 + angleDeviation: 45 + velocity: 50 + velocityDeviation: 30 + ParticleMotionGravity { + yattractor: 1000 + xattractor: 0 + acceleration: 25 + } + } +} + \endqml + \image particles.gif +*/ + +/*! + \internal + \class QmlGraphicsParticles + \ingroup group_effects + \brief The QmlGraphicsParticles class generates and moves particles. +*/ + +QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsParticlesPrivate), parent) +{ + Q_D(QmlGraphicsParticles); + d->init(); +} + +QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + Q_D(QmlGraphicsParticles); + d->init(); +} + +QmlGraphicsParticles::~QmlGraphicsParticles() +{ + Q_D(QmlGraphicsParticles); + if (d->pendingPixmapCache) + QmlPixmapCache::cancelGet(d->url, this); +} + +/*! + \qmlproperty string Particles::src + This property holds the URL of the particle image. +*/ + +/*! + \property QmlGraphicsParticles::source + \brief the URL of the particle image. +*/ +QUrl QmlGraphicsParticles::source() const +{ + Q_D(const QmlGraphicsParticles); + return d->url; +} + +void QmlGraphicsParticles::imageLoaded() +{ + Q_D(QmlGraphicsParticles); + d->pendingPixmapCache = false; + QmlPixmapCache::find(d->url, &d->image); + d->paintItem->updateSize(); + d->paintItem->update(); +} + +void QmlGraphicsParticles::setSource(const QUrl &name) +{ + Q_D(QmlGraphicsParticles); + + if ((d->url.isEmpty() == name.isEmpty()) && name == d->url) + return; + + if (d->pendingPixmapCache) { + QmlPixmapCache::cancelGet(d->url, this); + d->pendingPixmapCache = false; + } + if (name.isEmpty()) { + d->url = name; + d->image = QPixmap(); + d->paintItem->updateSize(); + d->paintItem->update(); + } else { + d->url = name; + Q_ASSERT(!name.isRelative()); + QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->url, &d->image); + if (reply) { + connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded())); + d->pendingPixmapCache = true; + } else { + //### unify with imageLoaded + d->paintItem->updateSize(); + d->paintItem->update(); + } + } + emit sourceChanged(); +} + +/*! + \qmlproperty int Particles::count + This property holds the maximum number of particles + + The particles element emits particles until it has count active + particles. When this number is reached, new particles are not emitted until + some of the current particles reach theend of their lifespan. + + If count is -1 then there is no maximum number of active particles, and + particles will be constantly emitted at the rate specified by emissionRate. + + If both count and emissionRate are set to -1, nothing will be emitted. + +*/ + +/*! + \property QmlGraphicsParticles::count + \brief the maximum number of particles +*/ +int QmlGraphicsParticles::count() const +{ + Q_D(const QmlGraphicsParticles); + return d->count; +} + +void QmlGraphicsParticles::setCount(int cnt) +{ + Q_D(QmlGraphicsParticles); + if (cnt == d->count) + return; + + int oldCount = d->count; + d->count = cnt; + d->addParticleTime = 0; + d->addParticleCount = d->particles.count(); + if (!oldCount && d->clock.state() != QAbstractAnimation::Running && d->count && d->emitting) { + d->clock.start(); + } + d->paintItem->updateSize(); + d->paintItem->update(); + emit countChanged(); +} + + +/*! + \qmlproperty int Particles::emissionRate + This property holds the target number of particles to emit every second. + + The particles element will emit up to emissionRate particles every + second. Fewer particles may be emitted per second if the maximum number of + particles has been reached. + + If emissionRate is set to -1 there is no limit to the number of + particles emitted per second, and particles will be instantly emitted to + reach the maximum number of particles specified by count. + + The default value for emissionRate is -1. + + If both count and emissionRate are set to -1, nothing will be emitted. +*/ + +/*! + \property QmlGraphicsParticles::emissionRate + \brief the emission rate of particles +*/ +int QmlGraphicsParticles::emissionRate() const +{ + Q_D(const QmlGraphicsParticles); + return d->emissionRate; +} +void QmlGraphicsParticles::setEmissionRate(int er) +{ + Q_D(QmlGraphicsParticles); + if(er == d->emissionRate) + return; + d->emissionRate = er; + emit emissionRateChanged(); +} + +/*! + \qmlproperty qreal Particles::emissionVariance + This property holds how inconsistent the rate of particle emissions are. + It is a number between 0 (no variance) and 1 (some variance). + + The expected number of particles emitted per second is emissionRate. If + emissionVariance is 0 then particles will be emitted consistently throughout + each second to reach that number. If emissionVariance is greater than 0 the + rate of particle emission will vary randomly throughout the second, with the + consequence that the actual number of particles emitted in one second will + vary randomly as well. + + emissionVariance is the maximum deviation from emitting + emissionRate particles per second. An emissionVariance of 0 means you should + get exactly emissionRate particles emitted per second, + and an emissionVariance of 1 means you will get between zero and two times + emissionRate particles per second, but you should get emissionRate particles + per second on average. + + Note that even with an emissionVariance of 0 there may be some variance due + to performance and hardware constraints. + + The default value of emissionVariance is 0.5 +*/ + +/*! + \property QmlGraphicsParticles::emissionVariance + \brief how much the particle emission amounts vary per tick +*/ + +qreal QmlGraphicsParticles::emissionVariance() const +{ + Q_D(const QmlGraphicsParticles); + return d->emissionVariance; +} + +void QmlGraphicsParticles::setEmissionVariance(qreal ev) +{ + Q_D(QmlGraphicsParticles); + if(d->emissionVariance == ev) + return; + d->emissionVariance = ev; + emit emissionVarianceChanged(); +} + +/*! + \qmlproperty int Particles::lifeSpan + \qmlproperty int Particles::lifeSpanDeviation + + These properties describe the life span of each particle. + + The default lifespan for a particle is 1000ms. + + lifeSpanDeviation randomly varies the lifeSpan up to the specified variation. For + example, the following creates particles whose lifeSpan will vary + from 150ms to 250ms: + + \qml +Particles { + source: "star.png" + lifeSpan: 200 + lifeSpanDeviation: 100 +} + \endqml +*/ + +/*! + \property QmlGraphicsParticles::lifeSpan + \brief the life span of each particle. + + Default value is 1000ms. + + \sa QmlGraphicsParticles::lifeSpanDeviation +*/ +int QmlGraphicsParticles::lifeSpan() const +{ + Q_D(const QmlGraphicsParticles); + return d->lifeSpan; +} + +void QmlGraphicsParticles::setLifeSpan(int ls) +{ + Q_D(QmlGraphicsParticles); + if(d->lifeSpan == ls) + return; + d->lifeSpan = ls; + emit lifeSpanChanged(); +} + +/*! + \property QmlGraphicsParticles::lifeSpanDeviation + \brief the maximum possible deviation from the set lifeSpan. + + Randomly varies the lifeSpan up to the specified variation. For + example, the following creates particles whose lifeSpan will vary + from 150ms to 250ms: + +\qml +Particles { + source: "star.png" + lifeSpan: 200 + lifeSpanDeviation: 100 +} +\endqml + + \sa QmlGraphicsParticles::lifeSpan +*/ +int QmlGraphicsParticles::lifeSpanDeviation() const +{ + Q_D(const QmlGraphicsParticles); + return d->lifeSpanDev; +} + +void QmlGraphicsParticles::setLifeSpanDeviation(int dev) +{ + Q_D(QmlGraphicsParticles); + if(d->lifeSpanDev == dev) + return; + d->lifeSpanDev = dev; + emit lifeSpanDeviationChanged(); +} + +/*! + \qmlproperty int Particles::fadeInDuration + \qmlproperty int Particles::fadeOutDuration + These properties hold the time taken to fade the particles in and out. + + By default fade in is 200ms and fade out is 300ms. +*/ + +/*! + \property QmlGraphicsParticles::fadeInDuration + \brief the time taken to fade in the particles. + + Default value is 200ms. +*/ +int QmlGraphicsParticles::fadeInDuration() const +{ + Q_D(const QmlGraphicsParticles); + return d->fadeInDur; +} + +void QmlGraphicsParticles::setFadeInDuration(int dur) +{ + Q_D(QmlGraphicsParticles); + if (dur < 0.0 || dur == d->fadeInDur) + return; + d->fadeInDur = dur; + emit fadeInDurationChanged(); +} + +/*! + \property QmlGraphicsParticles::fadeOutDuration + \brief the time taken to fade out the particles. + + Default value is 300ms. +*/ +int QmlGraphicsParticles::fadeOutDuration() const +{ + Q_D(const QmlGraphicsParticles); + return d->fadeOutDur; +} + +void QmlGraphicsParticles::setFadeOutDuration(int dur) +{ + Q_D(QmlGraphicsParticles); + if (dur < 0.0 || d->fadeOutDur == dur) + return; + d->fadeOutDur = dur; + emit fadeOutDurationChanged(); +} + +/*! + \qmlproperty real Particles::angle + \qmlproperty real Particles::angleDeviation + + These properties control particle direction. + + angleDeviation randomly varies the direction up to the specified variation. For + example, the following creates particles whose initial direction will + vary from 15 degrees to 105 degrees: + + \qml +Particles { + source: "star.png" + angle: 60 + angleDeviation: 90 +} + \endqml +*/ + +/*! + \property QmlGraphicsParticles::angle + \brief the initial angle of direction. + + \sa QmlGraphicsParticles::angleDeviation +*/ +qreal QmlGraphicsParticles::angle() const +{ + Q_D(const QmlGraphicsParticles); + return d->angle * 180.0 / M_PI; +} + +void QmlGraphicsParticles::setAngle(qreal angle) +{ + Q_D(QmlGraphicsParticles); + qreal radAngle = angle * M_PI / 180.0; + if(radAngle == d->angle) + return; + d->angle = radAngle; + emit angleChanged(); +} + +/*! + \property QmlGraphicsParticles::angleDeviation + \brief the maximum possible deviation from the set angle. + + Randomly varies the direction up to the specified variation. For + example, the following creates particles whose initial direction will + vary from 15 degrees to 105 degrees: + +\qml +Particles { + source: "star.png" + angle: 60 + angleDeviation: 90 +} +\endqml + + \sa QmlGraphicsParticles::angle +*/ +qreal QmlGraphicsParticles::angleDeviation() const +{ + Q_D(const QmlGraphicsParticles); + return d->angleDev * 180.0 / M_PI; +} + +void QmlGraphicsParticles::setAngleDeviation(qreal dev) +{ + Q_D(QmlGraphicsParticles); + qreal radDev = dev * M_PI / 180.0; + if(radDev == d->angleDev) + return; + d->angleDev = radDev; + emit angleDeviationChanged(); +} + +/*! + \qmlproperty real Particles::velocity + \qmlproperty real Particles::velocityDeviation + + These properties control the velocity of the particles. + + velocityDeviation randomly varies the velocity up to the specified variation. For + example, the following creates particles whose initial velocity will + vary from 40 to 60. + + \qml +Particles { + source: "star.png" + velocity: 50 + velocityDeviation: 20 +} + \endqml +*/ + +/*! + \property QmlGraphicsParticles::velocity + \brief the initial velocity of the particles. + + \sa QmlGraphicsParticles::velocityDeviation +*/ +qreal QmlGraphicsParticles::velocity() const +{ + Q_D(const QmlGraphicsParticles); + return d->velocity * 1000.0; +} + +void QmlGraphicsParticles::setVelocity(qreal velocity) +{ + Q_D(QmlGraphicsParticles); + qreal realVel = velocity / 1000.0; + if(realVel == d->velocity) + return; + d->velocity = realVel; + emit velocityChanged(); +} + +/*! + \property QmlGraphicsParticles::velocityDeviation + \brief the maximum possible deviation from the set velocity. + + Randomly varies the velocity up to the specified variation. For + example, the following creates particles whose initial velocity will + vary from 40 to 60. + +\qml +Particles { + source: "star.png" + velocity: 50 + velocityDeviation: 20 +} +\endqml + + \sa QmlGraphicsParticles::velocity +*/ +qreal QmlGraphicsParticles::velocityDeviation() const +{ + Q_D(const QmlGraphicsParticles); + return d->velocityDev * 1000.0; +} + +void QmlGraphicsParticles::setVelocityDeviation(qreal velocity) +{ + Q_D(QmlGraphicsParticles); + qreal realDev = velocity / 1000.0; + if(realDev == d->velocityDev) + return; + d->velocityDev = realDev; + emit velocityDeviationChanged(); +} + +/*! + \qmlproperty bool Particles::emitting + This property determines whether new particles are created + + If emitting is set to false no new particles will be created. This means that + when a particle reaches the end of its lifespan it is not replaced. This + property can be used to turn particles on and off with a more natural look. + + The default setting is true. Note that if it initialized to false no particles + will be produced until it is set to true. +*/ +/*! + \property QmlGraphicsParticles::emitting + If emitting is set to false no new particles will be created. This means that + when a particle reaches the end of its lifespan it is not replaced. This + property can be used to turn particles on and off with a more natural look. + + The default setting is true. Note that if it initialized to false no particles + will be produced until it is set to true. +*/ +bool QmlGraphicsParticles::emitting() const +{ + Q_D(const QmlGraphicsParticles); + return d->emitting; +} + +void QmlGraphicsParticles::setEmitting(bool r) +{ + Q_D(QmlGraphicsParticles); + if(d->emitting == r) + return; + d->emitting = r; + if (d->count && r) + d->clock.start(); + emit emittingChanged(); +} +/*! + \qmlproperty ParticleMotion Particles::motion + This property sets the type of motion to apply to the particles. + + When a particle is created it will have an initial direction and velocity. + The motion of the particle during its lifeSpan is then influenced by the + motion property. + + Default motion is ParticleMotionLinear. +*/ + +/*! + \property QmlGraphicsParticles::motion + \brief sets the type of motion to apply to the particles. + + When a particle is created it will have an initial direction and velocity. + The motion of the particle during its lifeSpan is then influenced by the + motion property. + + Default motion is QmlGraphicsParticleMotionLinear. +*/ +QmlGraphicsParticleMotion *QmlGraphicsParticles::motion() const +{ + Q_D(const QmlGraphicsParticles); + return d->motion; +} + +void QmlGraphicsParticles::setMotion(QmlGraphicsParticleMotion *motion) +{ + Q_D(QmlGraphicsParticles); + d->motion = motion; +} + +/*! + \qmlmethod Particles::burst + + Initiates a burst of particles. + + This method takes two arguments. The first argument is the number + of particles to emit and the second argument is the emissionRate for the + burst. If the second argument is omitted, it is treated as -1. The burst + of particles has a separate emissionRate and count to the normal emission of + particles. The burst uses the same values as normal emission for all other + properties, including emissionVariance and emitting. + + The normal emission of particles will continue during the burst, however + the particles created by the burst count towards the maximum number used by + normal emission. To avoid this behavior, use two Particles elements. + +*/ +void QmlGraphicsParticles::burst(int count, int emissionRate) +{ + Q_D(QmlGraphicsParticles); + d->bursts << qMakePair(count, emissionRate); + if (d->clock.state() != QAbstractAnimation::Running && d->emitting) + d->clock.start(); +} + +void QmlGraphicsParticlesPainter::updateSize() +{ + if (!isComponentComplete()) + return; + + const int parentX = parentItem()->x(); + const int parentY = parentItem()->y(); + for (int i = 0; i < d->particles.count(); ++i) { + const QmlGraphicsParticle &particle = d->particles.at(i); + if(particle.x > maxX) + maxX = particle.x; + if(particle.x < minX) + minX = particle.x; + if(particle.y > maxY) + maxY = particle.y; + if(particle.y < minY) + minY = particle.y; + } + + int myWidth = (int)(maxX-minX+0.5)+d->image.width(); + int myX = (int)(minX - parentX); + int myHeight = (int)(maxY-minY+0.5)+d->image.height(); + int myY = (int)(minY - parentY); + setWidth(myWidth); + setHeight(myHeight); + setX(myX); + setY(myY); +} + +void QmlGraphicsParticles::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + Q_UNUSED(p); + //painting is done by the ParticlesPainter, so it can have the right size +} + +void QmlGraphicsParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + if (d->image.isNull() || d->particles.isEmpty()) + return; + + const int myX = x() + parentItem()->x(); + const int myY = y() + parentItem()->y(); + + QVarLengthArray pixmapData; + pixmapData.resize(d->particles.count()); + + const QRectF sourceRect = d->image.rect(); + qreal halfPWidth = sourceRect.width()/2.; + qreal halfPHeight = sourceRect.height()/2.; + for (int i = 0; i < d->particles.count(); ++i) { + const QmlGraphicsParticle &particle = d->particles.at(i); + pixmapData[i].point = QPointF(particle.x - myX + halfPWidth, particle.y - myY + halfPHeight); + pixmapData[i].opacity = particle.opacity; + + //these never change + pixmapData[i].rotation = 0; + pixmapData[i].scaleX = 1; + pixmapData[i].scaleY = 1; + pixmapData[i].source = sourceRect; + } + qDrawPixmaps(p, pixmapData.data(), d->particles.count(), d->image); +} + +void QmlGraphicsParticles::componentComplete() +{ + Q_D(QmlGraphicsParticles); + QmlGraphicsItem::componentComplete(); + if (d->count) { + d->paintItem->updateSize(); + d->clock.start(); + } + if (d->lifeSpanDev > d->lifeSpan) + d->lifeSpanDev = d->lifeSpan; +} + +QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicsparticles_p.h b/src/declarative/graphicsitems/qmlgraphicsparticles_p.h new file mode 100644 index 0000000..851edd7 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsparticles_p.h @@ -0,0 +1,252 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLGRAPHICSPARTICLES_H +#define QMLGRAPHICSPARTICLES_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsParticle; +class QmlGraphicsParticles; +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotion : public QObject +{ + Q_OBJECT +public: + QmlGraphicsParticleMotion(QObject *parent=0); + + virtual void advance(QmlGraphicsParticle &, int interval); + virtual void created(QmlGraphicsParticle &); + virtual void destroy(QmlGraphicsParticle &); +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionLinear : public QmlGraphicsParticleMotion +{ + Q_OBJECT +public: + QmlGraphicsParticleMotionLinear(QObject *parent=0) + : QmlGraphicsParticleMotion(parent) {} + + virtual void advance(QmlGraphicsParticle &, int interval); +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionGravity : public QmlGraphicsParticleMotion +{ + Q_OBJECT + + Q_PROPERTY(int xattractor READ xAttractor WRITE setXAttractor) + Q_PROPERTY(int yattractor READ yAttractor WRITE setYAttractor) + Q_PROPERTY(int acceleration READ acceleration WRITE setAcceleration) +public: + QmlGraphicsParticleMotionGravity(QObject *parent=0) + : QmlGraphicsParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} + + int xAttractor() const { return _xAttr; } + void setXAttractor(int x) { _xAttr = x; } + + int yAttractor() const { return _yAttr; } + void setYAttractor(int y) { _yAttr = y; } + + int acceleration() const { return int(_accel * 1000000); } + void setAcceleration(int accel) { _accel = qreal(accel)/1000000.0; } + + virtual void advance(QmlGraphicsParticle &, int interval); + +private: + int _xAttr; + int _yAttr; + qreal _accel; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionWander : public QmlGraphicsParticleMotion +{ + Q_OBJECT +public: + QmlGraphicsParticleMotionWander() + : QmlGraphicsParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {} + + virtual void advance(QmlGraphicsParticle &, int interval); + virtual void created(QmlGraphicsParticle &); + virtual void destroy(QmlGraphicsParticle &); + + struct Data { + qreal x_targetV; + qreal y_targetV; + qreal x_peak; + qreal y_peak; + qreal x_var; + qreal y_var; + }; + + Q_PROPERTY(int xvariance READ xVariance WRITE setXVariance) + int xVariance() const { return int(_xvariance * 1000); } + void setXVariance(int var) { _xvariance = var / 1000.0; } + + Q_PROPERTY(int yvariance READ yVariance WRITE setYVariance) + int yVariance() const { return int(_yvariance * 1000); } + void setYVariance(int var) { _yvariance = var / 1000.0; } + + Q_PROPERTY(int pace READ pace WRITE setPace) + int pace() const { return int(_pace * 1000); } + void setPace(int pace) { _pace = pace / 1000.0; } + +private: + QmlGraphicsParticles *particles; + qreal _xvariance; + qreal _yvariance; + qreal _pace; +}; + +class QmlGraphicsParticlesPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsParticles : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged) + Q_PROPERTY(int emissionRate READ emissionRate WRITE setEmissionRate NOTIFY emissionRateChanged) + Q_PROPERTY(qreal emissionVariance READ emissionVariance WRITE setEmissionVariance NOTIFY emissionVarianceChanged) + Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan NOTIFY lifeSpanChanged) + Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation NOTIFY lifeSpanDeviationChanged) + Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration NOTIFY fadeInDurationChanged) + Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration NOTIFY fadeOutDurationChanged) + Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged) + Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation NOTIFY angleDeviationChanged) + Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged) + Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation NOTIFY velocityDeviationChanged) + Q_PROPERTY(bool emitting READ emitting WRITE setEmitting NOTIFY emittingChanged) + Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion) + Q_CLASSINFO("DefaultProperty", "motion") + +public: + QmlGraphicsParticles(QmlGraphicsItem *parent=0); + ~QmlGraphicsParticles(); + + QUrl source() const; + void setSource(const QUrl &); + + int count() const; + void setCount(int cnt); + + int emissionRate() const; + void setEmissionRate(int); + + qreal emissionVariance() const; + void setEmissionVariance(qreal); + + int lifeSpan() const; + void setLifeSpan(int); + + int lifeSpanDeviation() const; + void setLifeSpanDeviation(int); + + int fadeInDuration() const; + void setFadeInDuration(int); + + int fadeOutDuration() const; + void setFadeOutDuration(int); + + qreal angle() const; + void setAngle(qreal); + + qreal angleDeviation() const; + void setAngleDeviation(qreal); + + qreal velocity() const; + void setVelocity(qreal); + + qreal velocityDeviation() const; + void setVelocityDeviation(qreal); + + bool emitting() const; + void setEmitting(bool); + + QmlGraphicsParticleMotion *motion() const; + void setMotion(QmlGraphicsParticleMotion *); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +public Q_SLOTS: + void burst(int count, int emissionRate=-1); + +protected: + virtual void componentComplete(); + QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent); + +Q_SIGNALS: + void sourceChanged(); + void countChanged(); + void emissionRateChanged(); + void emissionVarianceChanged(); + void lifeSpanChanged(); + void lifeSpanDeviationChanged(); + void fadeInDurationChanged(); + void fadeOutDurationChanged(); + void angleChanged(); + void angleDeviationChanged(); + void velocityChanged(); + void velocityDeviationChanged(); + void emittingChanged(); + +private Q_SLOTS: + void imageLoaded(); + +private: + Q_DISABLE_COPY(QmlGraphicsParticles) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsParticles) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsParticleMotion) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionLinear) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionGravity) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionWander) +QML_DECLARE_TYPE(QmlGraphicsParticles) + +QT_END_HEADER + +#endif diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml b/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml index dccd2c7..c58927e 100644 --- a/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml +++ b/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml @@ -8,7 +8,7 @@ Rectangle{ objectName: "particles" width:1; height:1; anchors.centerIn: parent; opacity: 1 lifeSpan: 100; lifeSpanDeviation: 20; count:1000; - fadeInDuration: 20; fadeOutDuration: 20; + fadeInDuration: 20; fadeOutDuration: 20; count: -1; emissionRate: 1000 angle: 0; angleDeviation: 360; velocity: 500; velocityDeviation:30 source: "particle.png" } diff --git a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp index e50437a..ed68eaf 100644 --- a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp +++ b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp @@ -91,8 +91,11 @@ void tst_QmlGraphicsParticles::properties() particles->setVelocityDeviation(100.0); QCOMPARE(particles->velocityDeviation(), 100.0); - particles->setEmitting(false); - QCOMPARE(particles->emitting(), false); + particles->setEmissionVariance(0.5); + QCOMPARE(particles->emissionVariance(),0.5); + + particles->setEmissionRate(12); + QCOMPARE(particles->emissionRate(), 12); } void tst_QmlGraphicsParticles::runs() -- cgit v0.12 From 21ccecb582b251b9f7f3850b294868854ddac478 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 5 Nov 2009 14:49:30 +1000 Subject: qmlgraphicstext visual tests --- .../visual/qfxtext/font/data-MAC/plaintext.0.png | Bin 0 -> 94120 bytes .../visual/qfxtext/font/data-MAC/plaintext.qml | 351 ++++++++++++++++++++ .../visual/qfxtext/font/data-MAC/richtext.0.png | Bin 0 -> 121122 bytes .../visual/qfxtext/font/data-MAC/richtext.qml | 359 +++++++++++++++++++++ .../visual/qfxtext/font/data/plaintext.0.png | Bin 0 -> 94120 bytes .../visual/qfxtext/font/data/plaintext.qml | 351 ++++++++++++++++++++ .../visual/qfxtext/font/data/richtext.0.png | Bin 0 -> 121122 bytes .../visual/qfxtext/font/data/richtext.qml | 359 +++++++++++++++++++++ .../declarative/visual/qfxtext/font/plaintext.qml | 76 +++++ .../declarative/visual/qfxtext/font/richtext.qml | 76 +++++ 10 files changed, 1572 insertions(+) create mode 100644 tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.0.png create mode 100644 tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.qml create mode 100644 tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.0.png create mode 100644 tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.qml create mode 100644 tests/auto/declarative/visual/qfxtext/font/data/plaintext.0.png create mode 100644 tests/auto/declarative/visual/qfxtext/font/data/plaintext.qml create mode 100644 tests/auto/declarative/visual/qfxtext/font/data/richtext.0.png create mode 100644 tests/auto/declarative/visual/qfxtext/font/data/richtext.qml create mode 100644 tests/auto/declarative/visual/qfxtext/font/plaintext.qml create mode 100644 tests/auto/declarative/visual/qfxtext/font/richtext.qml diff --git a/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.0.png b/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.0.png new file mode 100644 index 0000000..50d56dc Binary files /dev/null and b/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.0.png differ diff --git a/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.qml b/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.qml new file mode 100644 index 0000000..63e20d4 --- /dev/null +++ b/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.qml @@ -0,0 +1,351 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 32 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 48 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 64 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 80 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 96 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 112 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 128 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 144 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 160 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 176 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 192 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 208 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 224 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 240 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 256 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 272 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 288 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 304 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 320 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 336 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 352 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 368 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 384 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 400 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 416 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 432 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 448 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 464 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 480 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 496 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 512 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 528 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 544 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 560 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 576 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 592 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 608 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 624 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 640 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 656 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 672 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 688 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 704 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 720 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 736 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 752 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 768 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 784 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 800 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 816 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 832 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 848 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 864 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 880 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 896 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 912 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 928 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 944 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 960 + image: "plaintext.0.png" + } + Frame { + msec: 976 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 992 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1008 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1024 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1040 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1056 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1072 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1088 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1104 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1120 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1136 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1152 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1168 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1184 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Key { + type: 6 + key: 16777249 + modifiers: 0 + text: "" + autorep: false + count: 1 + } + Frame { + msec: 1200 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1216 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1232 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1248 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1264 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1280 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1296 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1312 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1328 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1344 + hash: "d553014bc56a46787e30459b0f44f57a" + } +} diff --git a/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.0.png b/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.0.png new file mode 100644 index 0000000..2910670 Binary files /dev/null and b/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.0.png differ diff --git a/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.qml b/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.qml new file mode 100644 index 0000000..d55ad90 --- /dev/null +++ b/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.qml @@ -0,0 +1,359 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 32 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 48 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 64 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 80 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 96 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 112 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 128 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 144 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 160 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 176 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 192 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 208 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 224 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 240 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 256 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 272 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 288 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 304 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 320 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 336 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 352 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 368 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 384 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 400 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 416 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 432 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 448 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 464 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 480 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 496 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 512 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 528 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 544 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 560 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 576 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 592 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 608 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 624 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 640 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 656 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 672 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 688 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 704 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 720 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 736 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 752 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 768 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 784 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 800 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 816 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 832 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 848 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 864 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 880 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 896 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 912 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 928 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 944 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 960 + image: "richtext.0.png" + } + Frame { + msec: 976 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 992 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1008 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1024 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1040 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1056 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1072 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1088 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1104 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1120 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1136 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1152 + hash: "dfea78484b840b8cab690e277b960723" + } + Key { + type: 6 + key: 16777249 + modifiers: 0 + text: "" + autorep: false + count: 1 + } + Frame { + msec: 1168 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1184 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1200 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1216 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1232 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1248 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1264 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1280 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1296 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1312 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1328 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1344 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1360 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1376 + hash: "dfea78484b840b8cab690e277b960723" + } +} diff --git a/tests/auto/declarative/visual/qfxtext/font/data/plaintext.0.png b/tests/auto/declarative/visual/qfxtext/font/data/plaintext.0.png new file mode 100644 index 0000000..50d56dc Binary files /dev/null and b/tests/auto/declarative/visual/qfxtext/font/data/plaintext.0.png differ diff --git a/tests/auto/declarative/visual/qfxtext/font/data/plaintext.qml b/tests/auto/declarative/visual/qfxtext/font/data/plaintext.qml new file mode 100644 index 0000000..f4cbcbd --- /dev/null +++ b/tests/auto/declarative/visual/qfxtext/font/data/plaintext.qml @@ -0,0 +1,351 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 32 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 48 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 64 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 80 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 96 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 112 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 128 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 144 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 160 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 176 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 192 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 208 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 224 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 240 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 256 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 272 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 288 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 304 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 320 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 336 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 352 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 368 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 384 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 400 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 416 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 432 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 448 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 464 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 480 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 496 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 512 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 528 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 544 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 560 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 576 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 592 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 608 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 624 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 640 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 656 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 672 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 688 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 704 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 720 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 736 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 752 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 768 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 784 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 800 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 816 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 832 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 848 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 864 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 880 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 896 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 912 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 928 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 944 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 960 + image: "plaintext.0.png" + } + Frame { + msec: 976 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 992 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1008 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1024 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1040 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1056 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1072 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1088 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1104 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1120 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1136 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1152 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1168 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1184 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Key { + type: 6 + key: 16777249 + modifiers: 67108864 + text: "" + autorep: false + count: 1 + } + Frame { + msec: 1200 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1216 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1232 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1248 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1264 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1280 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1296 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1312 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1328 + hash: "d553014bc56a46787e30459b0f44f57a" + } + Frame { + msec: 1344 + hash: "d553014bc56a46787e30459b0f44f57a" + } +} diff --git a/tests/auto/declarative/visual/qfxtext/font/data/richtext.0.png b/tests/auto/declarative/visual/qfxtext/font/data/richtext.0.png new file mode 100644 index 0000000..2910670 Binary files /dev/null and b/tests/auto/declarative/visual/qfxtext/font/data/richtext.0.png differ diff --git a/tests/auto/declarative/visual/qfxtext/font/data/richtext.qml b/tests/auto/declarative/visual/qfxtext/font/data/richtext.qml new file mode 100644 index 0000000..9f396c2 --- /dev/null +++ b/tests/auto/declarative/visual/qfxtext/font/data/richtext.qml @@ -0,0 +1,359 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 32 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 48 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 64 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 80 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 96 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 112 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 128 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 144 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 160 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 176 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 192 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 208 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 224 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 240 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 256 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 272 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 288 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 304 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 320 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 336 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 352 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 368 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 384 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 400 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 416 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 432 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 448 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 464 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 480 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 496 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 512 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 528 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 544 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 560 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 576 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 592 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 608 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 624 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 640 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 656 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 672 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 688 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 704 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 720 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 736 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 752 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 768 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 784 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 800 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 816 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 832 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 848 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 864 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 880 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 896 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 912 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 928 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 944 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 960 + image: "richtext.0.png" + } + Frame { + msec: 976 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 992 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1008 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1024 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1040 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1056 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1072 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1088 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1104 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1120 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1136 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1152 + hash: "dfea78484b840b8cab690e277b960723" + } + Key { + type: 6 + key: 16777249 + modifiers: 67108864 + text: "" + autorep: false + count: 1 + } + Frame { + msec: 1168 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1184 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1200 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1216 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1232 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1248 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1264 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1280 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1296 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1312 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1328 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1344 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1360 + hash: "dfea78484b840b8cab690e277b960723" + } + Frame { + msec: 1376 + hash: "dfea78484b840b8cab690e277b960723" + } +} diff --git a/tests/auto/declarative/visual/qfxtext/font/plaintext.qml b/tests/auto/declarative/visual/qfxtext/font/plaintext.qml new file mode 100644 index 0000000..c58b95c --- /dev/null +++ b/tests/auto/declarative/visual/qfxtext/font/plaintext.qml @@ -0,0 +1,76 @@ +import Qt 4.6 + +Rectangle { + id: s; width: 800; height: 800; color: "lightsteelblue" + property string text: "The quick brown fox jumps over the lazy dog." + + Column { + spacing: 10 + Text { + text: s.text + } + Text { + text: s.text; font.pixelSize: 18 + } + Text { + text: s.text; font.pointSize: 25 + } + Text { + text: s.text; color: "red" + } + Text { + text: s.text; font.capitalization: "AllUppercase" + } + Text { + text: s.text; font.underline: true + } + Text { + text: s.text; font.overline: true + } + Text { + text: s.text; font.strikeout: true + } + Text { + text: s.text; font.underline: true; font.overline: true; font.strikeout: true + } + Text { + text: s.text; font.letterSpacing: 200 + } + Text { + text: s.text; font.underline: true; font.letterSpacing: 200; font.capitalization: "AllUppercase"; color: "blue" + } + Text { + text: s.text; font.overline: true; font.wordSpacing: 25; font.capitalization: "Capitalize"; color: "green" + } + Text { + text: s.text; font.pixelSize: 18; style: Text.Outline; styleColor: "white" + } + Text { + text: s.text; font.pixelSize: 18; style: Text.Sunken; styleColor: "gray" + } + Text { + text: s.text; font.pixelSize: 18; style: Text.Raised; styleColor: "yellow" + } + Text { + text: s.text; horizontalAlignment: Text.AlignLeft; width: 800 + } + Text { + text: s.text; horizontalAlignment: Text.AlignHCenter; width: 800 + } + Text { + text: s.text; horizontalAlignment: Text.AlignRight; width: 800 + } + Text { + text: s.text; font.pixelSize: 18; style: Text.Outline; styleColor: "white"; wrap: true; width: 200 + } + Text { + text: s.text; elide: Text.ElideLeft; width: 200 + } + Text { + text: s.text; elide: Text.ElideMiddle; width: 200 + } + Text { + text: s.text; elide: Text.ElideRight; width: 200 + } + } +} diff --git a/tests/auto/declarative/visual/qfxtext/font/richtext.qml b/tests/auto/declarative/visual/qfxtext/font/richtext.qml new file mode 100644 index 0000000..390527a --- /dev/null +++ b/tests/auto/declarative/visual/qfxtext/font/richtext.qml @@ -0,0 +1,76 @@ +import Qt 4.6 + +Rectangle { + id: s; width: 800; height: 800; color: "lightsteelblue" + property string text: "The quick brown fox jumps over the lazy dog." + + Column { + spacing: 10 + Text { + text: s.text + } + Text { + text: s.text; font.pixelSize: 18 + } + Text { + text: s.text; font.pointSize: 25 + } + Text { + text: s.text; color: "red" + } + Text { + text: s.text; font.capitalization: "AllUppercase" + } + Text { + text: s.text; font.underline: true + } + Text { + text: s.text; font.overline: true + } + Text { + text: s.text; font.strikeout: true + } + Text { + text: s.text; font.underline: true; font.overline: true; font.strikeout: true + } + Text { + text: s.text; font.letterSpacing: 200 + } + Text { + text: s.text; font.underline: true; font.letterSpacing: 200; font.capitalization: "AllUppercase"; color: "blue" + } + Text { + text: s.text; font.overline: true; font.wordSpacing: 25; font.capitalization: "Capitalize"; color: "green" + } + Text { + text: s.text; font.pixelSize: 18; style: Text.Outline; styleColor: "white" + } + Text { + text: s.text; font.pixelSize: 18; style: Text.Sunken; styleColor: "gray" + } + Text { + text: s.text; font.pixelSize: 18; style: Text.Raised; styleColor: "yellow" + } + Text { + text: s.text; horizontalAlignment: Text.AlignLeft; width: 800 + } + Text { + text: s.text; horizontalAlignment: Text.AlignHCenter; width: 800 + } + Text { + text: s.text; horizontalAlignment: Text.AlignRight; width: 800 + } + Text { + text: s.text; font.pixelSize: 18; style: Text.Outline; styleColor: "white"; wrap: true; width: 200 + } + Text { + text: s.text; elide: Text.ElideLeft; width: 200 + } + Text { + text: s.text; elide: Text.ElideMiddle; width: 200 + } + Text { + text: s.text; elide: Text.ElideRight; width: 200 + } + } +} -- cgit v0.12 From 7d290c0a38f325a3c024a38bcd5da94877d7fd64 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 5 Nov 2009 14:51:40 +1000 Subject: Loader cleanup and testing. --- .../graphicsitems/qmlgraphicsloader.cpp | 89 ++++++++++++---------- .../graphicsitems/qmlgraphicsloader_p.h | 1 - .../graphicsitems/qmlgraphicsloader_p_p.h | 5 +- tests/auto/declarative/qfxloader/tst_qfxloader.cpp | 13 +++- 4 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsloader.cpp b/src/declarative/graphicsitems/qmlgraphicsloader.cpp index 4d463ab..d42e559 100644 --- a/src/declarative/graphicsitems/qmlgraphicsloader.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsloader.cpp @@ -45,7 +45,8 @@ QT_BEGIN_NAMESPACE QmlGraphicsLoaderPrivate::QmlGraphicsLoaderPrivate() -: item(0), component(0), ownComponent(false), resizeMode(QmlGraphicsLoader::SizeLoaderToItem) + : item(0), component(0), ownComponent(false) + , resizeMode(QmlGraphicsLoader::SizeLoaderToItem) { } @@ -53,6 +54,36 @@ QmlGraphicsLoaderPrivate::~QmlGraphicsLoaderPrivate() { } +void QmlGraphicsLoaderPrivate::clear() +{ + if (ownComponent) { + delete component; + component = 0; + ownComponent = false; + } + source = QUrl(); + + delete item; + item = 0; +} + +void QmlGraphicsLoaderPrivate::initResize() +{ + Q_Q(QmlGraphicsLoader); + + QmlGraphicsItem *resizeItem = 0; + if (resizeMode == QmlGraphicsLoader::SizeLoaderToItem) + resizeItem = item; + else if (resizeMode == QmlGraphicsLoader::SizeItemToLoader) + resizeItem = q; + if (resizeItem) { + QObject::connect(resizeItem, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); + QObject::connect(resizeItem, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); + } + _q_updateSize(); +} + + QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QmlGraphicsLoader) /*! @@ -74,6 +105,17 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QmlGraphicsLoader) MouseRegion { anchors.fill: parent; onClicked: pageLoader.source = "Page1.qml" } } \endcode + + If the Loader source is changed, any previous items instantiated + will be destroyed. Setting \c source to an empty string + will destroy the currently instantiated items, freeing resources + and leaving the Loader empty. For example: + + \code + pageLoader.source = "" + \endcode + + unloads "Page1.qml" and frees resources consumed by it. */ /*! @@ -102,7 +144,7 @@ QmlGraphicsLoader::~QmlGraphicsLoader() This property holds the URL of the QML component to instantiate. - \sa status, progress + \sa sourceComponent, status, progress */ QUrl QmlGraphicsLoader::source() const { @@ -116,12 +158,7 @@ void QmlGraphicsLoader::setSource(const QUrl &url) if (d->source == url) return; - if (d->ownComponent) { - delete d->component; - d->component = 0; - } - delete d->item; - d->item = 0; + d->clear(); d->source = url; if (d->source.isEmpty()) { @@ -164,7 +201,7 @@ void QmlGraphicsLoader::setSource(const QUrl &url) } \endqml - \sa source + \sa source, progress */ QmlComponent *QmlGraphicsLoader::sourceComponent() const @@ -179,13 +216,7 @@ void QmlGraphicsLoader::setSourceComponent(QmlComponent *comp) if (comp == d->component) return; - d->source = QUrl(); - if (d->ownComponent) { - delete d->component; - d->component = 0; - } - delete d->item; - d->item = 0; + d->clear(); d->component = comp; d->ownComponent = false; @@ -233,16 +264,7 @@ void QmlGraphicsLoaderPrivate::_q_sourceLoaded() if (item) { item->setParentItem(q); // item->setFocus(true); - QmlGraphicsItem *resizeItem = 0; - if (resizeMode == QmlGraphicsLoader::SizeLoaderToItem) - resizeItem = item; - else if (resizeMode == QmlGraphicsLoader::SizeItemToLoader) - resizeItem = q; - if (resizeItem) { - QObject::connect(resizeItem, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); - QObject::connect(resizeItem, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); - } - _q_updateSize(); + initResize(); } } else { delete obj; @@ -340,20 +362,7 @@ void QmlGraphicsLoader::setResizeMode(ResizeMode mode) } d->resizeMode = mode; - - if (d->item) { - QmlGraphicsItem *resizeItem = 0; - if (d->resizeMode == SizeLoaderToItem) - resizeItem = d->item; - else if (d->resizeMode == SizeItemToLoader) - resizeItem = this; - if (resizeItem) { - connect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); - connect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); - } - - d->_q_updateSize(); - } + d->initResize(); } void QmlGraphicsLoaderPrivate::_q_updateSize() diff --git a/src/declarative/graphicsitems/qmlgraphicsloader_p.h b/src/declarative/graphicsitems/qmlgraphicsloader_p.h index 8cd1819..ad516b4 100644 --- a/src/declarative/graphicsitems/qmlgraphicsloader_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsloader_p.h @@ -63,7 +63,6 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsLoader : public QmlGraphicsItem Q_PROPERTY(QmlGraphicsItem *item READ item NOTIFY itemChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - //### sourceItem public: QmlGraphicsLoader(QmlGraphicsItem *parent=0); diff --git a/src/declarative/graphicsitems/qmlgraphicsloader_p_p.h b/src/declarative/graphicsitems/qmlgraphicsloader_p_p.h index 23fedb7..cd7316d 100644 --- a/src/declarative/graphicsitems/qmlgraphicsloader_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsloader_p_p.h @@ -67,10 +67,13 @@ public: QmlGraphicsLoaderPrivate(); ~QmlGraphicsLoaderPrivate(); + void clear(); + void initResize(); + QUrl source; QmlGraphicsItem *item; QmlComponent *component; - bool ownComponent; + bool ownComponent : 1; QmlGraphicsLoader::ResizeMode resizeMode; void _q_sourceLoaded(); diff --git a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp index 9a8f8f1..9a3da90 100644 --- a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp +++ b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp @@ -110,14 +110,21 @@ void tst_qfxloader::component() void tst_qfxloader::clear() { - QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"Rect120x60.qml\" }"), QUrl("file://" SRCDIR "/")); + QmlComponent component(&engine, QByteArray( + "import Qt 4.6\n" + " Loader { id: loader\n" + " source: 'Rect120x60.qml'\n" + " Timer { interval: 200; running: true; onTriggered: loader.source = '' }\n" + " }") + , QUrl("file://" SRCDIR "/")); QmlGraphicsLoader *loader = qobject_cast(component.create()); QVERIFY(loader != 0); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast(loader)->children().count(), 1); - loader->setSource(QUrl("")); + QTest::qWait(500); + QVERIFY(loader->item() == 0); QCOMPARE(loader->progress(), 0.0); QCOMPARE(static_cast(loader)->children().count(), 0); @@ -136,7 +143,7 @@ void tst_qfxloader::urlToComponent() "}" ) , QUrl("file://" SRCDIR "/")); QmlGraphicsLoader *loader = qobject_cast(component.create()); - QTest::qWait(1000); + QTest::qWait(500); QVERIFY(loader != 0); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); -- cgit v0.12 From 5343b49bbff4d813da1faf3fc4fc406441faccf0 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 5 Nov 2009 14:55:39 +1000 Subject: Fix flicking endpoint adjustment with variable height items. --- .../graphicsitems/qmlgraphicsflickable.cpp | 98 ++++++++++++---------- .../graphicsitems/qmlgraphicslistview.cpp | 6 +- 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp index 19c5abc..aa3de26 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp @@ -185,17 +185,17 @@ void QmlGraphicsFlickablePrivate::flickX(qreal velocity) { Q_Q(QmlGraphicsFlickable); qreal maxDistance = -1; - if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. - velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; // -ve velocity means list is moving up if (velocity > 0) { - if (_moveX.value() < q->minXExtent()) - maxDistance = qAbs(q->minXExtent() -_moveX.value() + (overShoot?30:0)); - flickTargetX = q->minXExtent(); + const qreal minX = q->minXExtent(); + if (_moveX.value() < minX) + maxDistance = qAbs(minX -_moveX.value() + (overShoot?30:0)); + flickTargetX = minX; } else { - if (_moveX.value() > q->maxXExtent()) - maxDistance = qAbs(q->maxXExtent() - _moveX.value()) + (overShoot?30:0); - flickTargetX = q->maxXExtent(); + const qreal maxX = q->maxXExtent(); + if (_moveX.value() > maxX) + maxDistance = qAbs(maxX - _moveX.value()) + (overShoot?30:0); + flickTargetX = maxX; } if (maxDistance > 0) { qreal v = velocity; @@ -225,13 +225,15 @@ void QmlGraphicsFlickablePrivate::flickY(qreal velocity) qreal maxDistance = -1; // -ve velocity means list is moving up if (velocity > 0) { - if (_moveY.value() < q->minYExtent()) - maxDistance = qAbs(q->minYExtent() -_moveY.value() + (overShoot?30:0)); - flickTargetY = q->minYExtent(); + const qreal minY = q->minYExtent(); + if (_moveY.value() < minY) + maxDistance = qAbs(minY -_moveY.value() + (overShoot?30:0)); + flickTargetY = minY; } else { - if (_moveY.value() > q->maxYExtent()) - maxDistance = qAbs(q->maxYExtent() - _moveY.value()) + (overShoot?30:0); - flickTargetY = q->maxYExtent(); + const qreal maxY = q->maxYExtent(); + if (_moveY.value() > maxY) + maxDistance = qAbs(maxY - _moveY.value()) + (overShoot?30:0); + flickTargetY = maxY; } if (maxDistance > 0) { qreal v = velocity; @@ -261,8 +263,6 @@ void QmlGraphicsFlickablePrivate::fixupX() if (!q->xflick() || _moveX.timeLine()) return; - vTime = timeline.time(); - if (_moveX.value() > q->minXExtent() || (q->maxXExtent() > q->minXExtent())) { timeline.reset(_moveX); if (_moveX.value() != q->minXExtent()) @@ -275,6 +275,8 @@ void QmlGraphicsFlickablePrivate::fixupX() } else { flicked = false; } + + vTime = timeline.time(); } void QmlGraphicsFlickablePrivate::fixupY() @@ -283,8 +285,6 @@ void QmlGraphicsFlickablePrivate::fixupY() if (!q->yflick() || _moveY.timeLine()) return; - vTime = timeline.time(); - if (_moveY.value() > q->minYExtent() || (q->maxYExtent() > q->minYExtent())) { timeline.reset(_moveY); if (_moveY.value() != q->minYExtent()) @@ -297,6 +297,8 @@ void QmlGraphicsFlickablePrivate::fixupY() } else { flicked = false; } + + vTime = timeline.time(); } void QmlGraphicsFlickablePrivate::updateBeginningEnd() @@ -447,6 +449,7 @@ void QmlGraphicsFlickable::setViewportX(qreal pos) Q_D(QmlGraphicsFlickable); pos = qRound(pos); d->timeline.reset(d->_moveX); + d->vTime = d->timeline.time(); if (-pos != d->_moveX.value()) { d->_moveX.setValue(-pos); viewportMoved(); @@ -464,6 +467,7 @@ void QmlGraphicsFlickable::setViewportY(qreal pos) Q_D(QmlGraphicsFlickable); pos = qRound(pos); d->timeline.reset(d->_moveY); + d->vTime = d->timeline.time(); if (-pos != d->_moveY.value()) { d->_moveY.setValue(-pos); viewportMoved(); @@ -491,6 +495,7 @@ void QmlGraphicsFlickable::setInteractive(bool interactive) d->interactive = interactive; if (!interactive && d->flicked) { d->timeline.clear(); + d->vTime = d->timeline.time(); d->flicked = false; emit flickingChanged(); emit flickEnded(); @@ -837,56 +842,57 @@ void QmlGraphicsFlickable::viewportMoved() Q_D(QmlGraphicsFlickable); int elapsed = QmlGraphicsItemPrivate::elapsed(d->velocityTime); + if (!elapsed) + return; - if (elapsed) { - qreal prevY = d->lastFlickablePosition.x(); - qreal prevX = d->lastFlickablePosition.y(); - d->velocityTimeline.clear(); - if (d->pressed) { - qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / elapsed; - qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / elapsed; - d->velocityTimeline.move(d->horizontalVelocity, horizontalVelocity, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->horizontalVelocity, 0, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->verticalVelocity, verticalVelocity, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->verticalVelocity, 0, d->reportedVelocitySmoothing); - } else { - if (d->timeline.time() != d->vTime) { - qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / (d->timeline.time() - d->vTime); - qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / (d->timeline.time() - d->vTime); - d->horizontalVelocity.setValue(horizontalVelocity); - d->verticalVelocity.setValue(verticalVelocity); - } - d->vTime = d->timeline.time(); + qreal prevY = d->lastFlickablePosition.x(); + qreal prevX = d->lastFlickablePosition.y(); + d->velocityTimeline.clear(); + if (d->pressed) { + qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / elapsed; + qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / elapsed; + d->velocityTimeline.move(d->horizontalVelocity, horizontalVelocity, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->horizontalVelocity, 0, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->verticalVelocity, verticalVelocity, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->verticalVelocity, 0, d->reportedVelocitySmoothing); + } else { + if (d->timeline.time() > d->vTime) { + qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / (d->timeline.time() - d->vTime); + qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / (d->timeline.time() - d->vTime); + d->horizontalVelocity.setValue(horizontalVelocity); + d->verticalVelocity.setValue(verticalVelocity); } } - d->lastFlickablePosition = QPointF(d->_moveY.value(), d->_moveX.value()); QmlGraphicsItemPrivate::restart(d->velocityTime); - d->updateBeginningEnd(); + d->lastFlickablePosition = QPointF(d->_moveY.value(), d->_moveX.value()); - if (d->flicked) { + if (d->flicked && d->timeline.time() > d->vTime) { // Near an end and it seems that the extent has changed? // Recalculate the flick so that we don't end up in an odd position. if (d->velocityY > 0) { const qreal minY = minYExtent(); - if (minY - d->_moveY.value() < height()/3 && minY != d->flickTargetY) + if (minY - d->_moveY.value() < height()/2 && minY != d->flickTargetY) d->flickY(-d->verticalVelocity.value()); - } else { + } else if (d->velocityY < 0) { const qreal maxY = maxYExtent(); - if (d->_moveY.value() - maxY < height()/3 && maxY != d->flickTargetY) + if (d->_moveY.value() - maxY < height()/2 && maxY != d->flickTargetY) d->flickY(-d->verticalVelocity.value()); } if (d->velocityX > 0) { const qreal minX = minXExtent(); - if (minX - d->_moveX.value() < height()/3 && minX != d->flickTargetX) + if (minX - d->_moveX.value() < height()/2 && minX != d->flickTargetX) d->flickX(-d->horizontalVelocity.value()); - } else { + } else if (d->velocityX < 0) { const qreal maxX = maxXExtent(); - if (d->_moveX.value() - maxX < height()/3 && maxX != d->flickTargetX) + if (d->_moveX.value() - maxX < height()/2 && maxX != d->flickTargetX) d->flickX(-d->horizontalVelocity.value()); } } + + d->vTime = d->timeline.time(); + d->updateBeginningEnd(); } void QmlGraphicsFlickable::cancelFlick() diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index efe047a..5adb9cf 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -815,8 +815,9 @@ void QmlGraphicsListViewPrivate::fixupY() if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) { if (currentItem && highlight && currentItem->position() != highlight->position()) { moveReason = Mouse; - timeline.clear(); + timeline.reset(_moveY); timeline.move(_moveY, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), 200); + vTime = timeline.time(); } } } @@ -830,8 +831,9 @@ void QmlGraphicsListViewPrivate::fixupX() if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) { if (currentItem && highlight && currentItem->position() != highlight->position()) { moveReason = Mouse; - timeline.clear(); + timeline.reset(_moveX); timeline.move(_moveX, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), 200); + vTime = timeline.time(); } } } -- cgit v0.12 From b8e788865cae90122e51ad1a2649d0891370fb3d Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 5 Nov 2009 15:05:03 +1000 Subject: use FreeMono.ttf --- examples/declarative/fonts/fonts.qml | 3 +-- examples/declarative/fonts/fonts/Fontin-Bold.ttf | Bin 30916 -> 0 bytes examples/declarative/fonts/fonts/FreeMono.ttf | Bin 0 -> 267400 bytes .../declarative/qmlfontloader/data/Fontin-Bold.ttf | Bin 30916 -> 0 bytes tests/auto/declarative/qmlfontloader/data/FreeMono.ttf | Bin 0 -> 267400 bytes .../declarative/qmlfontloader/tst_qmlfontloader.cpp | 4 ++-- 6 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 examples/declarative/fonts/fonts/Fontin-Bold.ttf create mode 100644 examples/declarative/fonts/fonts/FreeMono.ttf delete mode 100644 tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf create mode 100644 tests/auto/declarative/qmlfontloader/data/FreeMono.ttf diff --git a/examples/declarative/fonts/fonts.qml b/examples/declarative/fonts/fonts.qml index 80d82ad..c7af666 100644 --- a/examples/declarative/fonts/fonts.qml +++ b/examples/declarative/fonts/fonts.qml @@ -8,8 +8,7 @@ Rectangle { FontLoader { id: fixedFont; name: "Courier" } - FontLoader { id: localFont; source: "fonts/Fontin-Bold.ttf" } - /* A font by Jos Buivenga (exljbris) -> www.exljbris.nl */ + FontLoader { id: localFont; source: "fonts/FreeMono.ttf" } FontLoader { id: webFont; source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" } FontLoader { id: webFont2; source: "http://wrong.address.org" } diff --git a/examples/declarative/fonts/fonts/Fontin-Bold.ttf b/examples/declarative/fonts/fonts/Fontin-Bold.ttf deleted file mode 100644 index f6a33b0..0000000 Binary files a/examples/declarative/fonts/fonts/Fontin-Bold.ttf and /dev/null differ diff --git a/examples/declarative/fonts/fonts/FreeMono.ttf b/examples/declarative/fonts/fonts/FreeMono.ttf new file mode 100644 index 0000000..d7ce52d Binary files /dev/null and b/examples/declarative/fonts/fonts/FreeMono.ttf differ diff --git a/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf b/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf deleted file mode 100644 index f6a33b0..0000000 Binary files a/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf and /dev/null differ diff --git a/tests/auto/declarative/qmlfontloader/data/FreeMono.ttf b/tests/auto/declarative/qmlfontloader/data/FreeMono.ttf new file mode 100644 index 0000000..d7ce52d Binary files /dev/null and b/tests/auto/declarative/qmlfontloader/data/FreeMono.ttf differ diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp index 23f7025..a5ab13d 100644 --- a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -97,13 +97,13 @@ void tst_qmlfontloader::namedFont() void tst_qmlfontloader::localFont() { - QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/Fontin-Bold.ttf\" }"; + QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/FreeMono.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); QmlFontLoader *fontObject = qobject_cast(component.create()); QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); - QTRY_COMPARE(fontObject->name(), QString("Fontin")); + QTRY_COMPARE(fontObject->name(), QString("FreeMono")); QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } -- cgit v0.12 From 5c488b43a87cfdb146bcc5564faa229c979b8292 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 5 Nov 2009 15:15:18 +1000 Subject: update text visuals --- .../visual/qfxtext/font/data-MAC/plaintext.0.png | Bin 94120 -> 103016 bytes .../visual/qfxtext/font/data-MAC/plaintext.qml | 166 ++++++++++---------- .../visual/qfxtext/font/data-MAC/richtext.0.png | Bin 121122 -> 136499 bytes .../visual/qfxtext/font/data-MAC/richtext.qml | 170 ++++++++++----------- .../declarative/visual/qfxtext/font/plaintext.qml | 15 +- .../declarative/visual/qfxtext/font/richtext.qml | 15 +- 6 files changed, 192 insertions(+), 174 deletions(-) diff --git a/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.0.png b/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.0.png index 50d56dc..a54a327 100644 Binary files a/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.0.png and b/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.0.png differ diff --git a/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.qml b/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.qml index 63e20d4..266c9a3 100644 --- a/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.qml +++ b/tests/auto/declarative/visual/qfxtext/font/data-MAC/plaintext.qml @@ -6,239 +6,239 @@ VisualTest { } Frame { msec: 16 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 32 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 48 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 64 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 80 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 96 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 112 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 128 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 144 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 160 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 176 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 192 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 208 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 224 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 240 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 256 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 272 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 288 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 304 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 320 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 336 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 352 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 368 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 384 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 400 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 416 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 432 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 448 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 464 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 480 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 496 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 512 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 528 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 544 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 560 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 576 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 592 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 608 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 624 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 640 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 656 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 672 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 688 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 704 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 720 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 736 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 752 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 768 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 784 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 800 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 816 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 832 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 848 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 864 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 880 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 896 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 912 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 928 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 944 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 960 @@ -246,59 +246,59 @@ VisualTest { } Frame { msec: 976 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 992 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1008 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1024 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1040 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1056 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1072 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1088 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1104 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1120 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1136 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1152 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1168 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1184 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Key { type: 6 @@ -310,42 +310,42 @@ VisualTest { } Frame { msec: 1200 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1216 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1232 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1248 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1264 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1280 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1296 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1312 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1328 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } Frame { msec: 1344 - hash: "d553014bc56a46787e30459b0f44f57a" + hash: "9f3d0a505dec1982d9b405be72c265f8" } } diff --git a/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.0.png b/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.0.png index 2910670..c2ddee1 100644 Binary files a/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.0.png and b/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.0.png differ diff --git a/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.qml b/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.qml index d55ad90..e971809 100644 --- a/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.qml +++ b/tests/auto/declarative/visual/qfxtext/font/data-MAC/richtext.qml @@ -6,239 +6,239 @@ VisualTest { } Frame { msec: 16 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 32 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 48 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 64 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 80 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 96 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 112 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 128 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 144 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 160 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 176 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 192 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 208 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 224 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 240 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 256 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 272 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 288 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 304 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 320 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 336 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 352 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 368 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 384 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 400 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 416 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 432 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 448 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 464 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 480 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 496 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 512 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 528 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 544 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 560 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 576 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 592 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 608 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 624 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 640 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 656 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 672 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 688 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 704 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 720 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 736 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 752 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 768 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 784 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 800 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 816 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 832 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 848 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 864 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 880 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 896 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 912 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 928 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 944 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 960 @@ -246,51 +246,51 @@ VisualTest { } Frame { msec: 976 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 992 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1008 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1024 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1040 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1056 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1072 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1088 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1104 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1120 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1136 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1152 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Key { type: 6 @@ -302,58 +302,58 @@ VisualTest { } Frame { msec: 1168 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1184 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1200 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1216 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1232 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1248 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1264 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1280 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1296 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1312 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1328 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1344 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1360 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } Frame { msec: 1376 - hash: "dfea78484b840b8cab690e277b960723" + hash: "259cc9829171ea866dac4ffe8ef6b489" } } diff --git a/tests/auto/declarative/visual/qfxtext/font/plaintext.qml b/tests/auto/declarative/visual/qfxtext/font/plaintext.qml index c58b95c..f219e09 100644 --- a/tests/auto/declarative/visual/qfxtext/font/plaintext.qml +++ b/tests/auto/declarative/visual/qfxtext/font/plaintext.qml @@ -1,7 +1,7 @@ import Qt 4.6 Rectangle { - id: s; width: 800; height: 800; color: "lightsteelblue" + id: s; width: 800; height: 1000; color: "lightsteelblue" property string text: "The quick brown fox jumps over the lazy dog." Column { @@ -16,7 +16,7 @@ Rectangle { text: s.text; font.pointSize: 25 } Text { - text: s.text; color: "red" + text: s.text; color: "red"; smooth: true } Text { text: s.text; font.capitalization: "AllUppercase" @@ -25,7 +25,7 @@ Rectangle { text: s.text; font.underline: true } Text { - text: s.text; font.overline: true + text: s.text; font.overline: true; smooth: true } Text { text: s.text; font.strikeout: true @@ -72,5 +72,14 @@ Rectangle { Text { text: s.text; elide: Text.ElideRight; width: 200 } + Text { + text: s.text; elide: Text.ElideLeft; width: 200; wrap: true + } + Text { + text: s.text; elide: Text.ElideMiddle; width: 200; wrap: true + } + Text { + text: s.text; elide: Text.ElideRight; width: 200; wrap: true + } } } diff --git a/tests/auto/declarative/visual/qfxtext/font/richtext.qml b/tests/auto/declarative/visual/qfxtext/font/richtext.qml index 390527a..00a9749 100644 --- a/tests/auto/declarative/visual/qfxtext/font/richtext.qml +++ b/tests/auto/declarative/visual/qfxtext/font/richtext.qml @@ -1,7 +1,7 @@ import Qt 4.6 Rectangle { - id: s; width: 800; height: 800; color: "lightsteelblue" + id: s; width: 800; height: 1000; color: "lightsteelblue" property string text: "The quick brown fox jumps over the lazy dog." Column { @@ -16,7 +16,7 @@ Rectangle { text: s.text; font.pointSize: 25 } Text { - text: s.text; color: "red" + text: s.text; color: "red"; smooth: true } Text { text: s.text; font.capitalization: "AllUppercase" @@ -25,7 +25,7 @@ Rectangle { text: s.text; font.underline: true } Text { - text: s.text; font.overline: true + text: s.text; font.overline: true; smooth: true } Text { text: s.text; font.strikeout: true @@ -72,5 +72,14 @@ Rectangle { Text { text: s.text; elide: Text.ElideRight; width: 200 } + Text { + text: s.text; elide: Text.ElideLeft; width: 200; wrap: true + } + Text { + text: s.text; elide: Text.ElideMiddle; width: 200; wrap: true + } + Text { + text: s.text; elide: Text.ElideRight; width: 200; wrap: true + } } } -- cgit v0.12 From e1f01000ec127dd5a949eabf9b436f649597bf01 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 5 Nov 2009 15:16:51 +1000 Subject: Add listview test file. --- .../listview/data/listview-sections.qml | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/auto/declarative/listview/data/listview-sections.qml diff --git a/tests/auto/declarative/listview/data/listview-sections.qml b/tests/auto/declarative/listview/data/listview-sections.qml new file mode 100644 index 0000000..56700be --- /dev/null +++ b/tests/auto/declarative/listview/data/listview-sections.qml @@ -0,0 +1,59 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: myDelegate + Item { + id: wrapper + objectName: "wrapper" + height: ListView.prevSection != ListView.section ? 40 : 20; + width: 240 + Rectangle { + y: wrapper.ListView.prevSection != wrapper.ListView.section ? 20 : 0 + height: 20 + width: parent.width + color: wrapper.ListView.isCurrentItem ? "lightsteelblue" : "white" + Text { + text: index + } + Text { + x: 30 + id: textName + objectName: "textName" + text: name + } + Text { + x: 120 + id: textNumber + objectName: "textNumber" + text: number + } + Text { + x: 200 + text: wrapper.y + } + } + Rectangle { + color: "#99bb99" + height: wrapper.ListView.prevSection != wrapper.ListView.section ? 20 : 0 + width: parent.width + visible: wrapper.ListView.prevSection != wrapper.ListView.section ? true : false + Text { text: wrapper.ListView.section } + } + } + } + ] + ListView { + id: list + objectName: "list" + width: 240 + height: 320 + model: testModel + delegate: myDelegate + sectionExpression: "Math.floor(index/5)" + } +} -- cgit v0.12 From 34dcd4a715ca3f43901c245322e7c42dea646b8d Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 5 Nov 2009 15:41:40 +1000 Subject: fillmode visual test --- .../visual/fillmode/data-MAC/fillmode.0.png | Bin 0 -> 26099 bytes .../visual/fillmode/data-MAC/fillmode.qml | 279 +++++++++++++++++++++ .../visual/fillmode/data/fillmode.0.png | Bin 0 -> 26099 bytes .../declarative/visual/fillmode/data/fillmode.qml | 279 +++++++++++++++++++++ tests/auto/declarative/visual/fillmode/face.png | Bin 0 -> 905 bytes .../auto/declarative/visual/fillmode/fillmode.qml | 16 ++ 6 files changed, 574 insertions(+) create mode 100644 tests/auto/declarative/visual/fillmode/data-MAC/fillmode.0.png create mode 100644 tests/auto/declarative/visual/fillmode/data-MAC/fillmode.qml create mode 100644 tests/auto/declarative/visual/fillmode/data/fillmode.0.png create mode 100644 tests/auto/declarative/visual/fillmode/data/fillmode.qml create mode 100644 tests/auto/declarative/visual/fillmode/face.png create mode 100644 tests/auto/declarative/visual/fillmode/fillmode.qml diff --git a/tests/auto/declarative/visual/fillmode/data-MAC/fillmode.0.png b/tests/auto/declarative/visual/fillmode/data-MAC/fillmode.0.png new file mode 100644 index 0000000..9c9ceae Binary files /dev/null and b/tests/auto/declarative/visual/fillmode/data-MAC/fillmode.0.png differ diff --git a/tests/auto/declarative/visual/fillmode/data-MAC/fillmode.qml b/tests/auto/declarative/visual/fillmode/data-MAC/fillmode.qml new file mode 100644 index 0000000..7ac6f51 --- /dev/null +++ b/tests/auto/declarative/visual/fillmode/data-MAC/fillmode.qml @@ -0,0 +1,279 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 32 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 48 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 64 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 80 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 96 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 112 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 128 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 144 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 160 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 176 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 192 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 208 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 224 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 240 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 256 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 272 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 288 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 304 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 320 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 336 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 352 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 368 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 384 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 400 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 416 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 432 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 448 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 464 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 480 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 496 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 512 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 528 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 544 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 560 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 576 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 592 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 608 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 624 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 640 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 656 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 672 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 688 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 704 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Key { + type: 6 + key: 16777249 + modifiers: 0 + text: "" + autorep: false + count: 1 + } + Frame { + msec: 720 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 736 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 752 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 768 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 784 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 800 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 816 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 832 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 848 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 864 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 880 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 896 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 912 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 928 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 944 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 960 + image: "fillmode.0.png" + } + Frame { + msec: 976 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 992 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 1008 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 1024 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 1040 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 1056 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } +} diff --git a/tests/auto/declarative/visual/fillmode/data/fillmode.0.png b/tests/auto/declarative/visual/fillmode/data/fillmode.0.png new file mode 100644 index 0000000..9c9ceae Binary files /dev/null and b/tests/auto/declarative/visual/fillmode/data/fillmode.0.png differ diff --git a/tests/auto/declarative/visual/fillmode/data/fillmode.qml b/tests/auto/declarative/visual/fillmode/data/fillmode.qml new file mode 100644 index 0000000..58af8e8 --- /dev/null +++ b/tests/auto/declarative/visual/fillmode/data/fillmode.qml @@ -0,0 +1,279 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 32 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 48 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 64 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 80 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 96 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 112 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 128 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 144 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 160 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 176 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 192 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 208 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 224 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 240 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 256 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 272 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 288 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 304 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 320 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 336 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 352 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 368 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 384 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 400 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 416 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 432 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 448 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 464 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 480 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 496 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 512 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 528 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 544 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 560 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 576 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 592 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 608 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 624 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 640 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 656 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 672 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 688 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 704 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Key { + type: 6 + key: 16777249 + modifiers: 67108864 + text: "" + autorep: false + count: 1 + } + Frame { + msec: 720 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 736 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 752 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 768 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 784 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 800 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 816 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 832 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 848 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 864 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 880 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 896 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 912 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 928 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 944 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 960 + image: "fillmode.0.png" + } + Frame { + msec: 976 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 992 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 1008 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 1024 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 1040 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } + Frame { + msec: 1056 + hash: "c8cb8d51ca04231dc272133faaf2fb6d" + } +} diff --git a/tests/auto/declarative/visual/fillmode/face.png b/tests/auto/declarative/visual/fillmode/face.png new file mode 100644 index 0000000..9623b1a Binary files /dev/null and b/tests/auto/declarative/visual/fillmode/face.png differ diff --git a/tests/auto/declarative/visual/fillmode/fillmode.qml b/tests/auto/declarative/visual/fillmode/fillmode.qml new file mode 100644 index 0000000..8450bf2 --- /dev/null +++ b/tests/auto/declarative/visual/fillmode/fillmode.qml @@ -0,0 +1,16 @@ +import Qt 4.6 + +Rectangle { + id: screen; width: 750; height: 600; color: "gray" + property string source: "face.png" + + Grid { + columns: 3 + Image { width: 250; height: 300; source: screen.source; fillMode: Image.Stretch } + Image { width: 250; height: 300; source: screen.source; fillMode: Image.PreserveAspectFit; smooth: true } + Image { width: 250; height: 300; source: screen.source; fillMode: Image.PreserveAspectCrop } + Image { width: 250; height: 300; source: screen.source; fillMode: Image.Tile; smooth: true } + Image { width: 250; height: 300; source: screen.source; fillMode: Image.TileHorizontally } + Image { width: 250; height: 300; source: screen.source; fillMode: Image.TileVertically } + } +} -- cgit v0.12 From cec070f3905bcf6127e4e14236d5c61f09e3a61f Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Thu, 5 Nov 2009 15:59:53 +1000 Subject: Document the vector3d type in QML Task-number: QTBUG-5334 Reviewed-by: Aaron Kennedy --- doc/src/declarative/basictypes.qdoc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/src/declarative/basictypes.qdoc b/doc/src/declarative/basictypes.qdoc index 80ec211..0551443 100644 --- a/doc/src/declarative/basictypes.qdoc +++ b/doc/src/declarative/basictypes.qdoc @@ -233,4 +233,25 @@ \endqml \c Child1, \c Child2 and \c Child3 will all be added to the children list in the order in which they appear. + + \target basicqmlvector3d + \section1 vector3d + + A \c vector3d is specified in \c "x,y,z" format: + + \qml + Rotation { angle: 60; axis: "0,1,0" } + \endqml + + or with the \c{Qt.vector3d()} helper function: + + \qml + Rotation { angle: 60; axis: Qt.vector3d(0, 1, 0) } + \endqml + + or as separate \c x, \c y, and \c z components: + + \qml + Rotation { angle: 60; axis.x: 0; axis.y: 1; axis.z: 0 } + \endqml */ -- cgit v0.12 From a1f47211146629f702457150235da4475c1163ed Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 5 Nov 2009 16:46:17 +1000 Subject: qmlsystempalette autotests --- src/declarative/util/qmlsystempalette.cpp | 26 +--- src/declarative/util/qmlsystempalette_p.h | 13 +- tests/auto/declarative/declarative.pro | 1 + .../qmlsystempalette/qmlsystempalette.pro | 5 + .../qmlsystempalette/tst_qmlsystempalette.cpp | 154 +++++++++++++++++++++ 5 files changed, 171 insertions(+), 28 deletions(-) create mode 100644 tests/auto/declarative/qmlsystempalette/qmlsystempalette.pro create mode 100644 tests/auto/declarative/qmlsystempalette/tst_qmlsystempalette.cpp diff --git a/src/declarative/util/qmlsystempalette.cpp b/src/declarative/util/qmlsystempalette.cpp index bb3ec70..4ddc82d 100644 --- a/src/declarative/util/qmlsystempalette.cpp +++ b/src/declarative/util/qmlsystempalette.cpp @@ -256,39 +256,23 @@ QColor QmlSystemPalette::highlightedText() const } /*! - \qmlproperty color SystemPalette::lighter -*/ -QColor QmlSystemPalette::lighter(const QColor& color) const -{ - return color.lighter(); -} - -/*! - \qmlproperty color SystemPalette::darker -*/ -QColor QmlSystemPalette::darker(const QColor& color) const -{ - return color.darker(); -} - -/*! - \qmlproperty QPalette::ColorGroup SystemPalette::colorGroup + \qmlproperty QmlSystemPalette::ColorGroup SystemPalette::colorGroup The color group of the palette. It can be Active, Inactive or Disabled. Active is the default. \sa QPalette::ColorGroup */ -QPalette::ColorGroup QmlSystemPalette::colorGroup() const +QmlSystemPalette::ColorGroup QmlSystemPalette::colorGroup() const { Q_D(const QmlSystemPalette); - return d->group; + return (QmlSystemPalette::ColorGroup)d->group; } -void QmlSystemPalette::setColorGroup(QPalette::ColorGroup colorGroup) +void QmlSystemPalette::setColorGroup(QmlSystemPalette::ColorGroup colorGroup) { Q_D(QmlSystemPalette); - d->group = colorGroup; + d->group = (QPalette::ColorGroup)colorGroup; emit paletteChanged(); } diff --git a/src/declarative/util/qmlsystempalette_p.h b/src/declarative/util/qmlsystempalette_p.h index e87534e..6abbfe0 100644 --- a/src/declarative/util/qmlsystempalette_p.h +++ b/src/declarative/util/qmlsystempalette_p.h @@ -56,9 +56,10 @@ class QmlSystemPalettePrivate; class Q_DECLARATIVE_EXPORT QmlSystemPalette : public QObject { Q_OBJECT + Q_ENUMS(ColorGroup) Q_DECLARE_PRIVATE(QmlSystemPalette) - Q_PROPERTY(QPalette::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY paletteChanged) + Q_PROPERTY(QmlSystemPalette::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY paletteChanged) Q_PROPERTY(QColor window READ window NOTIFY paletteChanged) Q_PROPERTY(QColor windowText READ windowText NOTIFY paletteChanged) Q_PROPERTY(QColor base READ base NOTIFY paletteChanged) @@ -78,6 +79,8 @@ public: QmlSystemPalette(QObject *parent=0); ~QmlSystemPalette(); + enum ColorGroup { Active = QPalette::Active, Inactive = QPalette::Inactive, Disabled = QPalette::Disabled }; + QColor window() const; QColor windowText() const; @@ -97,12 +100,8 @@ public: QColor highlight() const; QColor highlightedText() const; - QPalette::ColorGroup colorGroup() const; - void setColorGroup(QPalette::ColorGroup); - - // FIXME: Move to utility class? - Q_INVOKABLE QColor lighter(const QColor&) const; - Q_INVOKABLE QColor darker(const QColor&) const; + QmlSystemPalette::ColorGroup colorGroup() const; + void setColorGroup(QmlSystemPalette::ColorGroup); Q_SIGNALS: void paletteChanged(); diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index b9f59d6..1625a15 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -30,6 +30,7 @@ SUBDIRS += \ qmlpixmapcache \ # Cover qmlpropertymap \ # Cover qmlqt \ # Cover + qmlsystempalette \ # Cover qmltimer \ # Cover qmlxmllistmodel \ # Cover repeater \ # Cover diff --git a/tests/auto/declarative/qmlsystempalette/qmlsystempalette.pro b/tests/auto/declarative/qmlsystempalette/qmlsystempalette.pro new file mode 100644 index 0000000..4d55b46 --- /dev/null +++ b/tests/auto/declarative/qmlsystempalette/qmlsystempalette.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlsystempalette.cpp diff --git a/tests/auto/declarative/qmlsystempalette/tst_qmlsystempalette.cpp b/tests/auto/declarative/qmlsystempalette/tst_qmlsystempalette.cpp new file mode 100644 index 0000000..039eaa8 --- /dev/null +++ b/tests/auto/declarative/qmlsystempalette/tst_qmlsystempalette.cpp @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include "../../../shared/util.h" + +class tst_qmlsystempalette : public QObject + +{ + Q_OBJECT +public: + tst_qmlsystempalette(); + +private slots: + void activePalette(); + void inactivePalette(); + void disabledPalette(); + +private: + QmlEngine engine; +}; + +tst_qmlsystempalette::tst_qmlsystempalette() +{ +} + +void tst_qmlsystempalette::activePalette() +{ + QString componentStr = "import Qt 4.6\nSystemPalette { }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlSystemPalette *object = qobject_cast(component.create()); + + QVERIFY(object != 0); + + QPalette palette; + palette.setCurrentColorGroup(QPalette::Active); + QCOMPARE(palette.window().color(), object->window()); + QCOMPARE(palette.windowText().color(), object->windowText()); + QCOMPARE(palette.base().color(), object->base()); + QCOMPARE(palette.text().color(), object->text()); + QCOMPARE(palette.alternateBase().color(), object->alternateBase()); + QCOMPARE(palette.button().color(), object->button()); + QCOMPARE(palette.buttonText().color(), object->buttonText()); + QCOMPARE(palette.light().color(), object->light()); + QCOMPARE(palette.midlight().color(), object->midlight()); + QCOMPARE(palette.dark().color(), object->dark()); + QCOMPARE(palette.mid().color(), object->mid()); + QCOMPARE(palette.shadow().color(), object->shadow()); + QCOMPARE(palette.highlight().color(), object->highlight()); + QCOMPARE(palette.highlightedText().color(), object->highlightedText()); + + delete object; +} + +void tst_qmlsystempalette::inactivePalette() +{ + QString componentStr = "import Qt 4.6\nSystemPalette { colorGroup: SystemPalette.Inactive }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlSystemPalette *object = qobject_cast(component.create()); + + QVERIFY(object != 0); + + QPalette palette; + palette.setCurrentColorGroup(QPalette::Inactive); + QCOMPARE(palette.window().color(), object->window()); + QCOMPARE(palette.windowText().color(), object->windowText()); + QCOMPARE(palette.base().color(), object->base()); + QCOMPARE(palette.text().color(), object->text()); + QCOMPARE(palette.alternateBase().color(), object->alternateBase()); + QCOMPARE(palette.button().color(), object->button()); + QCOMPARE(palette.buttonText().color(), object->buttonText()); + QCOMPARE(palette.light().color(), object->light()); + QCOMPARE(palette.midlight().color(), object->midlight()); + QCOMPARE(palette.dark().color(), object->dark()); + QCOMPARE(palette.mid().color(), object->mid()); + QCOMPARE(palette.shadow().color(), object->shadow()); + QCOMPARE(palette.highlight().color(), object->highlight()); + QCOMPARE(palette.highlightedText().color(), object->highlightedText()); + + delete object; +} + +void tst_qmlsystempalette::disabledPalette() +{ + QString componentStr = "import Qt 4.6\nSystemPalette { colorGroup: SystemPalette.Disabled }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlSystemPalette *object = qobject_cast(component.create()); + + QVERIFY(object != 0); + + QPalette palette; + palette.setCurrentColorGroup(QPalette::Disabled); + QCOMPARE(palette.window().color(), object->window()); + QCOMPARE(palette.windowText().color(), object->windowText()); + QCOMPARE(palette.base().color(), object->base()); + QCOMPARE(palette.text().color(), object->text()); + QCOMPARE(palette.alternateBase().color(), object->alternateBase()); + QCOMPARE(palette.button().color(), object->button()); + QCOMPARE(palette.buttonText().color(), object->buttonText()); + QCOMPARE(palette.light().color(), object->light()); + QCOMPARE(palette.midlight().color(), object->midlight()); + QCOMPARE(palette.dark().color(), object->dark()); + QCOMPARE(palette.mid().color(), object->mid()); + QCOMPARE(palette.shadow().color(), object->shadow()); + QCOMPARE(palette.highlight().color(), object->highlight()); + QCOMPARE(palette.highlightedText().color(), object->highlightedText()); + + delete object; +} + +QTEST_MAIN(tst_qmlsystempalette) + +#include "tst_qmlsystempalette.moc" -- cgit v0.12 From 01d7ae66da344f9aaef039310ac241015ec4cad5 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 5 Nov 2009 16:56:14 +1000 Subject: Use darker() and lighter() functions from global Qt object rather than from SystemPalette. --- demos/declarative/calculator/CalcButton.qml | 2 +- demos/declarative/calculator/calculator.qml | 2 +- demos/declarative/samegame/content/Button.qml | 2 +- demos/declarative/samegame/samegame.qml | 2 +- examples/declarative/dynamic/dynamic.qml | 2 +- examples/declarative/dynamic/qml/Button.qml | 2 +- examples/declarative/loader/Browser.qml | 4 ++-- examples/declarative/tutorials/samegame/samegame1/Button.qml | 2 +- examples/declarative/tutorials/samegame/samegame1/samegame.qml | 2 +- examples/declarative/tutorials/samegame/samegame2/Button.qml | 2 +- examples/declarative/tutorials/samegame/samegame2/samegame.qml | 2 +- examples/declarative/tutorials/samegame/samegame3/Button.qml | 2 +- examples/declarative/tutorials/samegame/samegame3/samegame.qml | 2 +- examples/declarative/tutorials/samegame/samegame4/content/Button.qml | 2 +- examples/declarative/tutorials/samegame/samegame4/samegame.qml | 2 +- 15 files changed, 16 insertions(+), 16 deletions(-) diff --git a/demos/declarative/calculator/CalcButton.qml b/demos/declarative/calculator/CalcButton.qml index c2e3a81..03ede9c 100644 --- a/demos/declarative/calculator/CalcButton.qml +++ b/demos/declarative/calculator/CalcButton.qml @@ -9,7 +9,7 @@ Rectangle { id: button; width: 50; height: 30 border.color: palette.mid; radius: 6 gradient: Gradient { - GradientStop { id: G1; position: 0.0; color: palette.lighter(palette.button) } + GradientStop { id: G1; position: 0.0; color: Qt.lighter(palette.button) } GradientStop { id: G2; position: 1.0; color: palette.button } } diff --git a/demos/declarative/calculator/calculator.qml b/demos/declarative/calculator/calculator.qml index 8041025..18ee5b9 100644 --- a/demos/declarative/calculator/calculator.qml +++ b/demos/declarative/calculator/calculator.qml @@ -3,7 +3,7 @@ import Qt 4.6 Rectangle { width: 320; height: 270; color: palette.window - SystemPalette { id: palette; colorGroup: Qt.Active } + SystemPalette { id: palette } Script { source: "calculator.js" } Column { diff --git a/demos/declarative/samegame/content/Button.qml b/demos/declarative/samegame/content/Button.qml index 301124e..63cd555 100644 --- a/demos/declarative/samegame/content/Button.qml +++ b/demos/declarative/samegame/content/Button.qml @@ -8,7 +8,7 @@ Rectangle { color: activePalette.button; smooth: true width: txtItem.width + 20; height: txtItem.height + 6 - border.width: 1; border.color: activePalette.darker(activePalette.button); radius: 8; + border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml index 4560b56..19b929f 100644 --- a/demos/declarative/samegame/samegame.qml +++ b/demos/declarative/samegame/samegame.qml @@ -5,7 +5,7 @@ Rectangle { id: screen width: 490; height: 720 - SystemPalette { id: activePalette; colorGroup: Qt.Active } + SystemPalette { id: activePalette } Item { width: parent.width; anchors.top: parent.top; anchors.bottom: toolBar.top diff --git a/examples/declarative/dynamic/dynamic.qml b/examples/declarative/dynamic/dynamic.qml index 0166b4c..f420a1c 100644 --- a/examples/declarative/dynamic/dynamic.qml +++ b/examples/declarative/dynamic/dynamic.qml @@ -46,7 +46,7 @@ Item { ColorAnimation { duration: 3000 } } - SystemPalette { id: activePalette; colorGroup: Qt.Active } + SystemPalette { id: activePalette } // toolbox Rectangle { diff --git a/examples/declarative/dynamic/qml/Button.qml b/examples/declarative/dynamic/qml/Button.qml index 2769cd8..cf2ffa7 100644 --- a/examples/declarative/dynamic/qml/Button.qml +++ b/examples/declarative/dynamic/qml/Button.qml @@ -6,7 +6,7 @@ Rectangle { property var text signal clicked - SystemPalette { id: activePalette; colorGroup: Qt.Active } + SystemPalette { id: activePalette } height: text.height + 10 width: text.width + 20 border.width: 1 diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml index f2cbd3d..9139346 100644 --- a/examples/declarative/loader/Browser.qml +++ b/examples/declarative/loader/Browser.qml @@ -19,7 +19,7 @@ Rectangle { folder: "file:///E:/" // Documents on your S60 phone (or Windows E: drive) } - SystemPalette { id: palette; colorGroup: Qt.Active } + SystemPalette { id: palette } Script { function down(path) { @@ -72,7 +72,7 @@ Rectangle { anchors.fill: parent gradient: Gradient { GradientStop { id: t1; position: 0.0; color: palette.highlight } - GradientStop { id: t2; position: 1.0; color: palette.lighter(palette.highlight) } + GradientStop { id: t2; position: 1.0; color: Qt.lighter(palette.highlight) } } } Item { diff --git a/examples/declarative/tutorials/samegame/samegame1/Button.qml b/examples/declarative/tutorials/samegame/samegame1/Button.qml index 3846cf7..9792a22 100644 --- a/examples/declarative/tutorials/samegame/samegame1/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame1/Button.qml @@ -9,7 +9,7 @@ Rectangle { color: activePalette.button; smooth: true width: txtItem.width + 20; height: txtItem.height + 6 - border.width: 1; border.color: activePalette.darker(activePalette.button); radius: 8; + border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { diff --git a/examples/declarative/tutorials/samegame/samegame1/samegame.qml b/examples/declarative/tutorials/samegame/samegame1/samegame.qml index b5546d0..289579a 100644 --- a/examples/declarative/tutorials/samegame/samegame1/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame1/samegame.qml @@ -5,7 +5,7 @@ Rectangle { id: Screen width: 490; height: 720 - SystemPalette { id: activePalette; colorGroup: Qt.Active } + SystemPalette { id: activePalette } Item { width: parent.width; anchors.top: parent.top; anchors.bottom: ToolBar.top diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml index 2354218..9e515e0 100644 --- a/examples/declarative/tutorials/samegame/samegame2/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml @@ -8,7 +8,7 @@ Rectangle { color: activePalette.button; smooth: true width: txtItem.width + 20; height: txtItem.height + 6 - border.width: 1; border.color: activePalette.darker(activePalette.button); radius: 8; + border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.qml b/examples/declarative/tutorials/samegame/samegame2/samegame.qml index 257e0de..e0e467a 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.qml @@ -4,7 +4,7 @@ Rectangle { id: Screen width: 490; height: 720 - SystemPalette { id: activePalette; colorGroup: Qt.Active } + SystemPalette { id: activePalette } //![2] Script { source: "samegame.js" } //![2] diff --git a/examples/declarative/tutorials/samegame/samegame3/Button.qml b/examples/declarative/tutorials/samegame/samegame3/Button.qml index 2354218..9e515e0 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Button.qml @@ -8,7 +8,7 @@ Rectangle { color: activePalette.button; smooth: true width: txtItem.width + 20; height: txtItem.height + 6 - border.width: 1; border.color: activePalette.darker(activePalette.button); radius: 8; + border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml index 0a7ec0f..e1eb542 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml @@ -5,7 +5,7 @@ Rectangle { id: Screen width: 490; height: 720 - SystemPalette { id: activePalette; colorGroup: Qt.Active } + SystemPalette { id: activePalette } Script { source: "samegame.js" } Item { diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml index 2354218..9e515e0 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml @@ -8,7 +8,7 @@ Rectangle { color: activePalette.button; smooth: true width: txtItem.width + 20; height: txtItem.height + 6 - border.width: 1; border.color: activePalette.darker(activePalette.button); radius: 8; + border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml index e519912..89dc945 100644 --- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml @@ -7,7 +7,7 @@ Rectangle { Script { source: "content/samegame.js" } - SystemPalette { id: activePalette; colorGroup: Qt.Active } + SystemPalette { id: activePalette } Item { width: parent.width; anchors.top: parent.top; anchors.bottom: ToolBar.top -- cgit v0.12 From e6a682189c4cd7f291648b9190b68cce79106b86 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 5 Nov 2009 16:58:20 +1000 Subject: Add test for GridView, and fix bug. --- .../graphicsitems/qmlgraphicsgridview.cpp | 46 +- .../graphicsitems/qmlgraphicslistview.cpp | 7 +- tests/auto/declarative/declarative.pro | 1 + .../qmlgraphicsgridview/data/gridview.qml | 49 ++ .../qmlgraphicsgridview/qmlgraphicsgridview.pro | 8 + .../tst_qmlgraphicsgridview.cpp | 585 +++++++++++++++++++++ 6 files changed, 672 insertions(+), 24 deletions(-) create mode 100644 tests/auto/declarative/qmlgraphicsgridview/data/gridview.qml create mode 100644 tests/auto/declarative/qmlgraphicsgridview/qmlgraphicsgridview.pro create mode 100644 tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 9f9b336..7427266 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -578,29 +578,35 @@ void QmlGraphicsGridViewPrivate::createHighlight() highlightYAnimator = 0; } - if (!highlightComponent) - return; - if (currentItem) { - QmlContext *highlightContext = new QmlContext(qmlContext(q)); - QObject *nobj = highlightComponent->create(highlightContext); - if (nobj) { - highlightContext->setParent(nobj); - QmlGraphicsItem *item = qobject_cast(nobj); - if (item) { - item->setParent(q->viewport()); - highlight = new FxGridItem(item, q); - highlightXAnimator = new QmlEaseFollow(q); - highlightXAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("x"))); - highlightXAnimator->setDuration(150); - highlightXAnimator->setEnabled(autoHighlight); - highlightYAnimator = new QmlEaseFollow(q); - highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); - highlightYAnimator->setDuration(150); - highlightYAnimator->setEnabled(autoHighlight); + QmlGraphicsItem *item = 0; + if (highlightComponent) { + QmlContext *highlightContext = new QmlContext(qmlContext(q)); + QObject *nobj = highlightComponent->create(highlightContext); + if (nobj) { + highlightContext->setParent(nobj); + item = qobject_cast(nobj); + if (!item) + delete nobj; } else { delete highlightContext; } + } else { + item = new QmlGraphicsItem; + item->setParent(q->viewport()); + } + if (item) { + item->setZValue(0); + item->setParent(q->viewport()); + highlight = new FxGridItem(item, q); + highlightXAnimator = new QmlEaseFollow(q); + highlightXAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("x"))); + highlightXAnimator->setDuration(150); + highlightXAnimator->setEnabled(autoHighlight); + highlightYAnimator = new QmlEaseFollow(q); + highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); + highlightYAnimator->setDuration(150); + highlightYAnimator->setEnabled(autoHighlight); } } } @@ -1500,6 +1506,8 @@ void QmlGraphicsGridView::itemsMoved(int from, int to, int count) if (item->index > from && item->index != -1) { // move everything after the moved items. item->index -= count; + if (item->index < d->visibleIndex) + d->visibleIndex = item->index; } ++it; } diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index fc1ec4a..f9d4190 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -662,19 +662,16 @@ void QmlGraphicsListViewPrivate::createHighlight() if (nobj) { highlightContext->setParent(nobj); item = qobject_cast(nobj); - if (!item) { + if (!item) delete nobj; - } else { - item->setParent(q->viewport()); - } } else { delete highlightContext; } } else { item = new QmlGraphicsItem; - item->setParent(q->viewport()); } if (item) { + item->setParent(q->viewport()); item->setZValue(0); highlight = new FxListItem(item, q); if (orient == QmlGraphicsListView::Vertical) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index b9f59d6..e586925 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -8,6 +8,7 @@ SUBDIRS += \ examples \ layouts \ # Cover listview \ # Cover + qmlgraphicsgridview \ # Cover numberformatter \ # Cover pathview \ # Cover qfxloader \ # Cover diff --git a/tests/auto/declarative/qmlgraphicsgridview/data/gridview.qml b/tests/auto/declarative/qmlgraphicsgridview/data/gridview.qml new file mode 100644 index 0000000..37eb622 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsgridview/data/gridview.qml @@ -0,0 +1,49 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + width: 80 + height: 60 + border.color: "blue" + Text { + text: index + } + Text { + x: 40 + text: wrapper.x + ", " + wrapper.y + } + Text { + y: 20 + id: textName + objectName: "textName" + text: name + } + Text { + y: 40 + id: textNumber + objectName: "textNumber" + text: number + } + color: GridView.isCurrentItem ? "lightsteelblue" : "white" + } + } + ] + GridView { + id: grid + objectName: "grid" + width: 240 + height: 320 + cellWidth: 80 + cellHeight: 60 + model: testModel + delegate: myDelegate + } +} diff --git a/tests/auto/declarative/qmlgraphicsgridview/qmlgraphicsgridview.pro b/tests/auto/declarative/qmlgraphicsgridview/qmlgraphicsgridview.pro new file mode 100644 index 0000000..8eae8ae --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsgridview/qmlgraphicsgridview.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicsgridview.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp new file mode 100644 index 0000000..c6ea25a --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp @@ -0,0 +1,585 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +class tst_QmlGraphicsGridView : public QObject +{ + Q_OBJECT +public: + tst_QmlGraphicsGridView(); + +private slots: + void items(); + void changed(); + void inserted(); + void removed(); + void moved(); + +private: + QmlView *createView(const QString &filename); + template + T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); + template + QList findItems(QmlGraphicsItem *parent, const QString &objectName); +}; + +class TestModel : public QAbstractListModel +{ +public: + enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; + + TestModel(QObject *parent=0) : QAbstractListModel(parent) { + QHash roles; + roles[Name] = "name"; + roles[Number] = "number"; + setRoleNames(roles); + } + + int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { + QVariant rv; + if (role == Name) + rv = list.at(index.row()).first; + else if (role == Number) + rv = list.at(index.row()).second; + + return rv; + } + + int count() const { return rowCount(); } + QString name(int index) const { return list.at(index).first; } + QString number(int index) const { return list.at(index).second; } + + void addItem(const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), list.count(), list.count()); + list.append(QPair(name, number)); + emit endInsertRows(); + } + + void insertItem(int index, const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), index, index); + list.insert(index, QPair(name, number)); + emit endInsertRows(); + } + + void removeItem(int index) { + emit beginRemoveRows(QModelIndex(), index, index); + list.removeAt(index); + emit endRemoveRows(); + } + + void moveItem(int from, int to) { + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); + } + + void modifyItem(int idx, const QString &name, const QString &number) { + list[idx] = QPair(name, number); + emit dataChanged(index(idx,0), index(idx,0)); + } + +private: + QList > list; +}; + +tst_QmlGraphicsGridView::tst_QmlGraphicsGridView() +{ +} + +void tst_QmlGraphicsGridView::items() +{ + QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + + TestModel model; + model.addItem("Fred", "12345"); + model.addItem("John", "2345"); + model.addItem("Bob", "54321"); + model.addItem("Billy", "22345"); + model.addItem("Sam", "2945"); + model.addItem("Ben", "04321"); + model.addItem("Jim", "0780"); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QVERIFY(gridview != 0); + + QmlGraphicsItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + QCOMPARE(gridview->count(), model.count()); + QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + + for (int i = 0; i < model.count(); ++i) { + QmlGraphicsText *name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + QmlGraphicsText *number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + gridview->moveCurrentIndexRight(); + QCOMPARE(gridview->currentIndex(), 1); + gridview->moveCurrentIndexDown(); + QCOMPARE(gridview->currentIndex(), 4); + gridview->moveCurrentIndexUp(); + QCOMPARE(gridview->currentIndex(), 1); + gridview->moveCurrentIndexLeft(); + QCOMPARE(gridview->currentIndex(), 0); + + // set an empty model and confirm that items are destroyed + TestModel model2; + ctxt->setContextProperty("testModel", &model2); + + int itemCount = findItems(viewport, "wrapper").count(); + QVERIFY(itemCount == 0); + + delete canvas; +} + +void tst_QmlGraphicsGridView::changed() +{ + QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + + TestModel model; + model.addItem("Fred", "12345"); + model.addItem("John", "2345"); + model.addItem("Bob", "54321"); + model.addItem("Billy", "22345"); + model.addItem("Sam", "2945"); + model.addItem("Ben", "04321"); + model.addItem("Jim", "0780"); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsFlickable *gridview = findItem(canvas->root(), "grid"); + QVERIFY(gridview != 0); + + QmlGraphicsItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + model.modifyItem(1, "Will", "9876"); + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + delete canvas; +} + +void tst_QmlGraphicsGridView::inserted() +{ + QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + + TestModel model; + model.addItem("Fred", "12345"); + model.addItem("John", "2345"); + model.addItem("Bob", "54321"); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QVERIFY(gridview != 0); + + QmlGraphicsItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + model.insertItem(1, "Will", "9876"); + + // let transitions settle. + QTest::qWait(300); + + QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + // Confirm items positioned correctly + for (int i = 0; i < model.count(); ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + QVERIFY(item->x() == (i%3)*80); + QVERIFY(item->y() == (i/3)*60); + } + + model.insertItem(0, "Foo", "1111"); // zero index, and current item + + // let transitions settle. + QTest::qWait(300); + + QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + + name = findItem(viewport, "textName", 0); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(0)); + number = findItem(viewport, "textNumber", 0); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(0)); + + QCOMPARE(gridview->currentIndex(), 1); + + // Confirm items positioned correctly + for (int i = 0; i < model.count(); ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + QVERIFY(item->x() == (i%3)*80); + QVERIFY(item->y() == (i/3)*60); + } + + for (int i = model.count(); i < 30; ++i) + model.insertItem(i, "Hello", QString::number(i)); + QTest::qWait(300); + + gridview->setViewportY(120); + QTest::qWait(300); + + // Insert item outside visible area + model.insertItem(1, "Hello", "1324"); + QTest::qWait(300); + + QVERIFY(gridview->viewportY() == 120); + + delete canvas; +} + +void tst_QmlGraphicsGridView::removed() +{ + QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QVERIFY(gridview != 0); + + QmlGraphicsItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + model.removeItem(1); + + // let transitions settle. + QTest::qWait(300); + + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->x() == (i%3)*80); + QVERIFY(item->y() == (i/3)*60); + } + + // Remove first item (which is the current item); + model.removeItem(0); + + // let transitions settle. + QTest::qWait(300); + + name = findItem(viewport, "textName", 0); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(0)); + number = findItem(viewport, "textNumber", 0); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(0)); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->x() == (i%3)*80); + QVERIFY(item->y() == (i/3)*60); + } + + // Remove items not visible + model.removeItem(25); + // let transitions settle. + QTest::qWait(300); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->x() == (i%3)*80); + QVERIFY(item->y() == (i/3)*60); + } + + // Remove items before visible + gridview->setViewportY(120); + gridview->setCurrentIndex(10); + + model.removeItem(1); + // let transitions settle. + QTest::qWait(300); + + // Confirm items positioned correctly + for (int i = 6; i < 18; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->x() == (i%3)*80); + QVERIFY(item->y() == (i/3)*60); + } + + gridview->setViewportY(0); + // let transitions settle. + QTest::qWait(300); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->x() == (i%3)*80); + QVERIFY(item->y() == (i/3)*60); + } + + delete canvas; +} + +void tst_QmlGraphicsGridView::moved() +{ + QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsGridView *gridview = findItem(canvas->root(), "grid"); + QVERIFY(gridview != 0); + + QmlGraphicsItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + model.moveItem(1, 8); + + // let transitions settle. + QTest::qWait(300); + + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + name = findItem(viewport, "textName", 8); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(8)); + number = findItem(viewport, "textNumber", 8); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(8)); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->x() == (i%3)*80); + QVERIFY(item->y() == (i/3)*60); + } + + gridview->setViewportY(120); + + // move outside visible area + model.moveItem(1, 25); + + // let transitions settle. + QTest::qWait(300); + + // Confirm items positioned correctly and indexes correct + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->x(), qreal((i%3)*80)); + QCOMPARE(item->y(), qreal((i/3)*60 + 60)); + name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + // move from outside visible into visible + model.moveItem(28, 8); + + // let transitions settle. + QTest::qWait(300); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->x() == (i%3)*80); + QVERIFY(item->y() == (i/3)*60 + 60); + name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + delete canvas; +} + +QmlView *tst_QmlGraphicsGridView::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString qml = file.readAll(); + canvas->setQml(qml, filename); + + return canvas; +} + +/* + Find an item with the specified objectName. If index is supplied then the + item must also evaluate the {index} expression equal to index +*/ +template +T *tst_QmlGraphicsGridView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) +{ + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { + if (index != -1) { + QmlExpression e(qmlContext(item), "index", item); + e.setTrackChange(false); + if (e.value().toInt() == index) + return static_cast(item); + } else { + return static_cast(item); + } + } + item = findItem(item, objectName, index); + if (item) + return static_cast(item); + } + + return 0; +} + +template +QList tst_QmlGraphicsGridView::findItems(QmlGraphicsItem *parent, const QString &objectName) +{ + QList items; + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) + items.append(static_cast(item)); + items += findItems(item, objectName); + } + + return items; +} + + +QTEST_MAIN(tst_QmlGraphicsGridView) + +#include "tst_qmlgraphicsgridview.moc" -- cgit v0.12 From 26cae0653332caf0b4e315fd35fd59469c66bac9 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 5 Nov 2009 16:59:33 +1000 Subject: Compile. --- tests/auto/declarative/valuetypes/testtypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/valuetypes/testtypes.cpp b/tests/auto/declarative/valuetypes/testtypes.cpp index d57afaf..f0fdaf8 100644 --- a/tests/auto/declarative/valuetypes/testtypes.cpp +++ b/tests/auto/declarative/valuetypes/testtypes.cpp @@ -40,4 +40,4 @@ ****************************************************************************/ #include "testtypes.h" -QML_DEFINE_TYPE(Test, 1, 0, 0, MyTypeObject, MyTypeObject); +QML_DEFINE_TYPE(Test, 1, 0, MyTypeObject, MyTypeObject); -- cgit v0.12 From 8b40fac7e97a629ddaf1c0f6de2ebb504f004060 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 5 Nov 2009 17:03:08 +1000 Subject: value types autotest --- src/declarative/qml/qmlvaluetype_p.h | 20 +- tests/auto/declarative/valuetypes/testtypes.cpp | 4 +- tests/auto/declarative/valuetypes/testtypes.h | 40 +++- .../auto/declarative/valuetypes/tst_valuetypes.cpp | 207 ++++++++++++++++++++- 4 files changed, 244 insertions(+), 27 deletions(-) diff --git a/src/declarative/qml/qmlvaluetype_p.h b/src/declarative/qml/qmlvaluetype_p.h index 0af3813..e7566f9 100644 --- a/src/declarative/qml/qmlvaluetype_p.h +++ b/src/declarative/qml/qmlvaluetype_p.h @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE -class QmlValueType : public QObject +class Q_AUTOTEST_EXPORT QmlValueType : public QObject { Q_OBJECT public: @@ -73,7 +73,7 @@ public: virtual void setValue(QVariant) = 0; }; -class QmlValueTypeFactory +class Q_AUTOTEST_EXPORT QmlValueTypeFactory { public: QmlValueTypeFactory(); @@ -84,7 +84,7 @@ public: QmlValueType *operator[](int idx) const { return valueTypes[idx]; } }; -class QmlPointFValueType : public QmlValueType +class Q_AUTOTEST_EXPORT QmlPointFValueType : public QmlValueType { Q_PROPERTY(qreal x READ x WRITE setX) Q_PROPERTY(qreal y READ y WRITE setY) @@ -106,7 +106,7 @@ private: QPointF point; }; -class QmlPointValueType : public QmlValueType +class Q_AUTOTEST_EXPORT QmlPointValueType : public QmlValueType { Q_PROPERTY(int x READ x WRITE setX) Q_PROPERTY(int y READ y WRITE setY) @@ -128,7 +128,7 @@ private: QPoint point; }; -class QmlSizeFValueType : public QmlValueType +class Q_AUTOTEST_EXPORT QmlSizeFValueType : public QmlValueType { Q_PROPERTY(qreal width READ width WRITE setWidth) Q_PROPERTY(qreal height READ height WRITE setHeight) @@ -150,7 +150,7 @@ private: QSizeF size; }; -class QmlSizeValueType : public QmlValueType +class Q_AUTOTEST_EXPORT QmlSizeValueType : public QmlValueType { Q_PROPERTY(int width READ width WRITE setWidth) Q_PROPERTY(int height READ height WRITE setHeight) @@ -172,7 +172,7 @@ private: QSize size; }; -class QmlRectFValueType : public QmlValueType +class Q_AUTOTEST_EXPORT QmlRectFValueType : public QmlValueType { Q_PROPERTY(qreal x READ x WRITE setX) Q_PROPERTY(qreal y READ y WRITE setY) @@ -201,7 +201,7 @@ private: QRectF rect; }; -class QmlRectValueType : public QmlValueType +class Q_AUTOTEST_EXPORT QmlRectValueType : public QmlValueType { Q_PROPERTY(int x READ x WRITE setX) Q_PROPERTY(int y READ y WRITE setY) @@ -230,7 +230,7 @@ private: QRect rect; }; -class QmlVector3DValueType : public QmlValueType +class Q_AUTOTEST_EXPORT QmlVector3DValueType : public QmlValueType { Q_PROPERTY(qreal x READ x WRITE setX) Q_PROPERTY(qreal y READ y WRITE setY) @@ -255,7 +255,7 @@ private: QVector3D vector; }; -class QmlFontValueType : public QmlValueType +class Q_AUTOTEST_EXPORT QmlFontValueType : public QmlValueType { Q_OBJECT Q_ENUMS(FontWeight) diff --git a/tests/auto/declarative/valuetypes/testtypes.cpp b/tests/auto/declarative/valuetypes/testtypes.cpp index d57afaf..565eb1c 100644 --- a/tests/auto/declarative/valuetypes/testtypes.cpp +++ b/tests/auto/declarative/valuetypes/testtypes.cpp @@ -40,4 +40,6 @@ ****************************************************************************/ #include "testtypes.h" -QML_DEFINE_TYPE(Test, 1, 0, 0, MyTypeObject, MyTypeObject); +QML_DEFINE_TYPE(Test, 1, 0, MyTypeObject, MyTypeObject); +QML_DEFINE_TYPE(Test, 1, 0, MyConstantValueSource, MyConstantValueSource); +QML_DEFINE_TYPE(Test, 1, 0, MyOffsetValueInterceptor, MyOffsetValueInterceptor); diff --git a/tests/auto/declarative/valuetypes/testtypes.h b/tests/auto/declarative/valuetypes/testtypes.h index cc98d7c..67e32f5 100644 --- a/tests/auto/declarative/valuetypes/testtypes.h +++ b/tests/auto/declarative/valuetypes/testtypes.h @@ -51,6 +51,7 @@ #include #include #include +#include class MyTypeObject : public QObject { @@ -90,39 +91,62 @@ public: QPoint m_point; QPoint point() const { return m_point; } - void setPoint(const QPoint &v) { m_point = v; } + void setPoint(const QPoint &v) { m_point = v; emit changed(); } QPointF m_pointf; QPointF pointf() const { return m_pointf; } - void setPointf(const QPointF &v) { m_pointf = v; } + void setPointf(const QPointF &v) { m_pointf = v; emit changed(); } QSize m_size; QSize size() const { return m_size; } - void setSize(const QSize &v) { m_size = v; } + void setSize(const QSize &v) { m_size = v; emit changed(); } QSizeF m_sizef; QSizeF sizef() const { return m_sizef; } - void setSizef(const QSizeF &v) { m_sizef = v; } + void setSizef(const QSizeF &v) { m_sizef = v; emit changed(); } QRect m_rect; QRect rect() const { return m_rect; } - void setRect(const QRect &v) { m_rect = v; } + void setRect(const QRect &v) { m_rect = v; emit changed(); } QRectF m_rectf; QRectF rectf() const { return m_rectf; } - void setRectf(const QRectF &v) { m_rectf = v; } + void setRectf(const QRectF &v) { m_rectf = v; emit changed(); } QVector3D m_vector; QVector3D vector() const { return m_vector; } - void setVector(const QVector3D &v) { m_vector = v; } + void setVector(const QVector3D &v) { m_vector = v; emit changed(); } QFont m_font; QFont font() const { return m_font; } - void setFont(const QFont &v) { m_font = v; } + void setFont(const QFont &v) { m_font = v; emit changed(); } + + void emitRunScript() { emit runScript(); } signals: void changed(); + void runScript(); }; QML_DECLARE_TYPE(MyTypeObject); +class MyConstantValueSource : public QObject, public QmlPropertyValueSource +{ + Q_OBJECT +public: + virtual void setTarget(const QmlMetaProperty &p) { p.write(3345); } +}; +QML_DECLARE_TYPE(MyConstantValueSource); + +class MyOffsetValueInterceptor : public QObject, public QmlPropertyValueInterceptor +{ + Q_OBJECT +public: + virtual void setTarget(const QmlMetaProperty &p) { prop = p; } + virtual void write(const QVariant &value) { prop.write(value.toInt() + 13, QmlMetaProperty::BypassInterceptor); } + +private: + QmlMetaProperty prop; +}; +QML_DECLARE_TYPE(MyOffsetValueInterceptor); + #endif // TESTTYPES_H diff --git a/tests/auto/declarative/valuetypes/tst_valuetypes.cpp b/tests/auto/declarative/valuetypes/tst_valuetypes.cpp index a338e47..d09bdf5 100644 --- a/tests/auto/declarative/valuetypes/tst_valuetypes.cpp +++ b/tests/auto/declarative/valuetypes/tst_valuetypes.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include "testtypes.h" class tst_valuetypes : public QObject @@ -61,14 +62,16 @@ private slots: void vector3d(); void font(); - // ### - // Test binding assignment - // Test static assignment - // Test JS assignment - // Test "font.x: blah; font: blah2;" conflict - // Test constant binding removal - // Test value sources - // Test behaviours + void bindingAssignment(); + void bindingRead(); + void staticAssignment(); + void scriptAccess(); + void autoBindingRemoval(); + void valueSources(); + void valueInterceptors(); + void bindingConflict(); + void cppClasses(); + private: QmlEngine engine; }; @@ -312,6 +315,8 @@ void tst_valuetypes::font() QVERIFY(object != 0); QCOMPARE(object->font().pixelSize(), 10); + + delete object; } // Test pixelSize and pointSize @@ -322,9 +327,195 @@ void tst_valuetypes::font() QVERIFY(object != 0); QCOMPARE(object->font().pixelSize(), 10); + + delete object; } } +// Test bindings can write to value types +void tst_valuetypes::bindingAssignment() +{ + QmlComponent component(&engine, TEST_FILE("bindingAssignment.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->rect().x(), 10); + + object->setProperty("value", QVariant(92)); + + QCOMPARE(object->rect().x(), 92); + + delete object; +} + +// Test bindings can read from value types +void tst_valuetypes::bindingRead() +{ + QmlComponent component(&engine, TEST_FILE("bindingRead.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("value").toInt(), 2); + + object->setRect(QRect(19, 3, 88, 2)); + + QCOMPARE(object->property("value").toInt(), 19); + + delete object; +} + +// Test static values can assign to value types +void tst_valuetypes::staticAssignment() +{ + QmlComponent component(&engine, TEST_FILE("staticAssignment.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->rect().x(), 9); + + delete object; +} + +// Test scripts can read/write value types +void tst_valuetypes::scriptAccess() +{ + QmlComponent component(&engine, TEST_FILE("scriptAccess.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("valuePre").toInt(), 2); + QCOMPARE(object->rect().x(), 19); + QCOMPARE(object->property("valuePost").toInt(), 19); + + delete object; +} + +// Test that assigning a constant from script removes any binding +void tst_valuetypes::autoBindingRemoval() +{ + { + QmlComponent component(&engine, TEST_FILE("autoBindingRemoval.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->rect().x(), 10); + + object->setProperty("value", QVariant(13)); + + QCOMPARE(object->rect().x(), 13); + + object->emitRunScript(); + + QCOMPARE(object->rect().x(), 42); + + object->setProperty("value", QVariant(92)); + + QCOMPARE(object->rect().x(), 42); + + delete object; + } + + { + QmlComponent component(&engine, TEST_FILE("autoBindingRemoval.2.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->rect().x(), 10); + + object->setProperty("value", QVariant(13)); + + QCOMPARE(object->rect().x(), 13); + + object->emitRunScript(); + + QCOMPARE(object->rect(), QRect(10, 10, 10, 10)); + + object->setProperty("value", QVariant(92)); + + QCOMPARE(object->rect(), QRect(10, 10, 10, 10)); + + delete object; + } + + { + QmlComponent component(&engine, TEST_FILE("autoBindingRemoval.3.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + object->setProperty("value", QVariant(QRect(9, 22, 33, 44))); + + QCOMPARE(object->rect(), QRect(9, 22, 33, 44)); + + object->emitRunScript(); + + QCOMPARE(object->rect(), QRect(44, 22, 33, 44)); + + object->setProperty("value", QVariant(QRect(19, 3, 4, 8))); + + QCOMPARE(object->rect(), QRect(44, 22, 33, 44)); + + delete object; + } + +} + +// Test that property value sources assign to value types +void tst_valuetypes::valueSources() +{ + QmlComponent component(&engine, TEST_FILE("valueSources.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->rect().x(), 3345); + + delete object; +} + +// Test that property value interceptors can be applied to value types +void tst_valuetypes::valueInterceptors() +{ + QmlComponent component(&engine, TEST_FILE("valueInterceptors.qml")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->rect().x(), 26); + + object->setProperty("value", 99); + + QCOMPARE(object->rect().x(), 112); + + delete object; +} + +// Test that you can't assign a binding to the "root" value type, and a sub-property +void tst_valuetypes::bindingConflict() +{ + QmlComponent component(&engine, TEST_FILE("bindingConflict.qml")); + QCOMPARE(component.isError(), true); +} + +#define CPP_TEST(type, v) \ +{ \ + type *t = new type; \ + QVariant value(v); \ + t->setValue(value); \ + QCOMPARE(t->value(), value); \ + delete t; \ +} + +// Test that the value type classes can be used manually +void tst_valuetypes::cppClasses() +{ + CPP_TEST(QmlPointValueType, QPoint(19, 33)); + CPP_TEST(QmlPointFValueType, QPointF(33.6, -23)); + CPP_TEST(QmlSizeValueType, QSize(-100, 18)); + CPP_TEST(QmlSizeFValueType, QSizeF(-100.7, 18.2)); + CPP_TEST(QmlRectValueType, QRect(13, 39, 10928, 88)); + CPP_TEST(QmlRectFValueType, QRectF(88.2, -90.1, 103.2, 118)); + CPP_TEST(QmlVector3DValueType, QVector3D(18.2, 19.7, 1002)); + CPP_TEST(QmlFontValueType, QFont("Helvetica")); + +} QTEST_MAIN(tst_valuetypes) #include "tst_valuetypes.moc" -- cgit v0.12 From 0bc45e6b54f67a3f5e8b7c3b780a124de1d9570d Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Thu, 5 Nov 2009 17:16:29 +1000 Subject: fix calculator --- demos/declarative/calculator/calculator.qml | 34 +++++++++++++---------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/demos/declarative/calculator/calculator.qml b/demos/declarative/calculator/calculator.qml index 18ee5b9..54af7ad 100644 --- a/demos/declarative/calculator/calculator.qml +++ b/demos/declarative/calculator/calculator.qml @@ -45,7 +45,7 @@ Rectangle { } Item { - width: 320 + width: 320; height: 160 Item { id: basicButtons @@ -106,23 +106,19 @@ Rectangle { } } - states: [ - State { - name: "Advanced"; when: advancedCheckBox.toggled == true - PropertyChanges { target: basicButtons; x: 0 } - PropertyChanges { target: simpleOperations; y: 32 } - PropertyChanges { target: bksp; opacity: 1 } - PropertyChanges { target: c; x: 69; width: 67 } - PropertyChanges { target: ac; x: 138; width: 67 } - PropertyChanges { target: equals; width: 50 } - PropertyChanges { target: advancedButtons; x: 210; opacity: 1 } - } - ] + states: State { + name: "Advanced"; when: advancedCheckBox.toggled == true + PropertyChanges { target: basicButtons; x: 0 } + PropertyChanges { target: simpleOperations; y: 32 } + PropertyChanges { target: bksp; opacity: 1 } + PropertyChanges { target: c; x: 69; width: 67 } + PropertyChanges { target: ac; x: 138; width: 67 } + PropertyChanges { target: equals; width: 50 } + PropertyChanges { target: advancedButtons; x: 210; opacity: 1 } + } - transitions: [ - Transition { - NumberAnimation { properties: "x,y,width"; easing: "easeOutBounce"; duration: 500 } - NumberAnimation { properties: "opacity"; easing: "easeInOutQuad"; duration: 500 } - } - ] + transitions: Transition { + NumberAnimation { properties: "x,y,width"; easing: "easeOutBounce"; duration: 500 } + NumberAnimation { properties: "opacity"; easing: "easeInOutQuad"; duration: 500 } + } } -- cgit v0.12 From 7dc306a32b12dcd783714fbb6078e100bc52f32e Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 5 Nov 2009 17:32:34 +1000 Subject: Test the currentSection property --- src/declarative/graphicsitems/qmlgraphicslistview.cpp | 4 ++++ tests/auto/declarative/listview/tst_listview.cpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index f9d4190..1f5d51d 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -1461,6 +1461,10 @@ void QmlGraphicsListView::setSectionExpression(const QString &expression) } } +/*! + \qmlproperty string ListView::currentSection + This property holds the section that is currently at the beginning of the view. +*/ QString QmlGraphicsListView::currentSection() const { Q_D(const QmlGraphicsListView); diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index b8f87b7..5575ace 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -671,6 +671,7 @@ void tst_QmlGraphicsListView::spacing() } listview->setSpacing(10); + QVERIFY(listview->spacing() == 10); // Confirm items positioned correctly itemCount = findItems(viewport, "wrapper").count(); @@ -723,6 +724,11 @@ void tst_QmlGraphicsListView::sections() QCOMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); } + QVERIFY(listview->currentSection() == "0"); + + listview->setViewportY(140); + QVERIFY(listview->currentSection() == "1"); + delete canvas; } -- cgit v0.12 From f8423b94bbf439831577644cd07d2aa4e997396a Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 5 Nov 2009 17:39:43 +1000 Subject: QmlGraphicsparticles visual test --- .../qmlgraphicsparticles/data/particles.0.png | Bin 0 -> 10022 bytes .../qmlgraphicsparticles/data/particles.1.png | Bin 0 -> 14142 bytes .../qmlgraphicsparticles/data/particles.2.png | Bin 0 -> 14214 bytes .../visual/qmlgraphicsparticles/data/particles.qml | 783 +++++++++++++++++++++ .../visual/qmlgraphicsparticles/particles.qml | 48 ++ .../visual/qmlgraphicsparticles/star.png | Bin 0 -> 262 bytes 6 files changed, 831 insertions(+) create mode 100644 tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.0.png create mode 100644 tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.1.png create mode 100644 tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.2.png create mode 100644 tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.qml create mode 100644 tests/auto/declarative/visual/qmlgraphicsparticles/particles.qml create mode 100644 tests/auto/declarative/visual/qmlgraphicsparticles/star.png diff --git a/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.0.png b/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.0.png new file mode 100644 index 0000000..30bdefd Binary files /dev/null and b/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.0.png differ diff --git a/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.1.png b/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.1.png new file mode 100644 index 0000000..799e028 Binary files /dev/null and b/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.1.png differ diff --git a/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.2.png b/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.2.png new file mode 100644 index 0000000..ed267c2 Binary files /dev/null and b/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.2.png differ diff --git a/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.qml b/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.qml new file mode 100644 index 0000000..3199f31 --- /dev/null +++ b/tests/auto/declarative/visual/qmlgraphicsparticles/data/particles.qml @@ -0,0 +1,783 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "b4df49cbd7cf972af9879399808f6c53" + } + Frame { + msec: 32 + hash: "1c129b1c4a39412bed2f23d712f2bc90" + } + Frame { + msec: 48 + hash: "fbcc4bc3fea46a43453aa39b032264c6" + } + Frame { + msec: 64 + hash: "2cb13275faca414b7c8ba9d70067fd1f" + } + Frame { + msec: 80 + hash: "b017afb05f96085ee3395d62e62e457b" + } + Frame { + msec: 96 + hash: "642851d10c549c8ae72c057563e99e64" + } + Frame { + msec: 112 + hash: "494c0942f7410d455a4b113fb908e570" + } + Frame { + msec: 128 + hash: "cb0a2f9980f27757c0c1d62ef3dcfde0" + } + Frame { + msec: 144 + hash: "2fb9cf782ea106006af8bcd66c62869c" + } + Frame { + msec: 160 + hash: "bf68518323f03e4f407831e8b34f247b" + } + Frame { + msec: 176 + hash: "c99abe9c0384ae339fdfa0c75dc8047d" + } + Frame { + msec: 192 + hash: "96f2eb402633c1aca8a1a2b0d60af5fb" + } + Frame { + msec: 208 + hash: "6cba51a856f1ba54ee702761f196b915" + } + Frame { + msec: 224 + hash: "9188926caa6c6ba8cb3aee04de635b96" + } + Frame { + msec: 240 + hash: "81132a5e8768de0630311813170f166e" + } + Frame { + msec: 256 + hash: "a638698d7ccb73f20f6eeba3857f417c" + } + Frame { + msec: 272 + hash: "4761ba6847f6f0769b916106c5f3245b" + } + Frame { + msec: 288 + hash: "13bc0c681962bada7fcb3b722895ffaa" + } + Frame { + msec: 304 + hash: "505c5824be16d812b7c339f1f9b8a10b" + } + Frame { + msec: 320 + hash: "d191d502d9c685f8497583669147ee73" + } + Frame { + msec: 336 + hash: "c17f55cc5d7bf541e235791a157aa8b9" + } + Frame { + msec: 352 + hash: "3ef401f87830c53b9b277d4420a9a742" + } + Frame { + msec: 368 + hash: "d04816400e66ebbf797f9985a53f7cfb" + } + Frame { + msec: 384 + hash: "d7a7df7c2a92449f42d61c0572e7dbac" + } + Frame { + msec: 400 + hash: "f49a3bcf3842f554136ff9bd5bb470ef" + } + Frame { + msec: 416 + hash: "27bccc5933d7bfaad6d5f6a10efd283b" + } + Frame { + msec: 432 + hash: "3067ac00a4d58c67bb96d813c344871d" + } + Frame { + msec: 448 + hash: "d38d7192688feecc38fd63285d37ce49" + } + Frame { + msec: 464 + hash: "4172d1b74cdd6ea89be718977775a9e0" + } + Frame { + msec: 480 + hash: "2761a7e58cbfa46fc6d306c8270e4f10" + } + Frame { + msec: 496 + hash: "58a851b9fbcb98afc7c1bc58c2f45e4a" + } + Frame { + msec: 512 + hash: "0f7789f04bf20708d9d6f1e818b6b88a" + } + Frame { + msec: 528 + hash: "8d8b8d109dce4c7b05ecb603b4718859" + } + Frame { + msec: 544 + hash: "0fc6fde589932ac41787e8ebfe3fcbe3" + } + Frame { + msec: 560 + hash: "e08bffd5a56795488f090a475513e5db" + } + Frame { + msec: 576 + hash: "e089ab7c5feefd3d745bb665e2ff49ee" + } + Frame { + msec: 592 + hash: "e7b787fb1b21e991c19ec88b3d985b69" + } + Frame { + msec: 608 + hash: "a6f4f32287bd926e0eeff68717b80512" + } + Frame { + msec: 624 + hash: "3344ca9c97473bd922bd8efd5d6ab212" + } + Frame { + msec: 640 + hash: "a330510a9f62acb4f2163728939d0bb5" + } + Frame { + msec: 656 + hash: "1ec473936f2279f13675b6b5fe2ee392" + } + Frame { + msec: 672 + hash: "b193b7d2917ee00c4cb29bf244186bef" + } + Frame { + msec: 688 + hash: "75137e977941e357bad2ad9af2cbc898" + } + Frame { + msec: 704 + hash: "31773ba8979a31b1691860b7dafe28dc" + } + Frame { + msec: 720 + hash: "d8922452edbba4f1092b83e87c0330ea" + } + Frame { + msec: 736 + hash: "982c80305b54236d1259f5672098652d" + } + Frame { + msec: 752 + hash: "d8b23fb0867fb75558960216c8d0f2aa" + } + Frame { + msec: 768 + hash: "daf7833f93a216d1e025c9129b3a7caa" + } + Frame { + msec: 784 + hash: "bb08e8fe2ce74018fc702e5dad8927fe" + } + Frame { + msec: 800 + hash: "22a30051c87d4de7e734d9de6ce7eed8" + } + Frame { + msec: 816 + hash: "d8625628587feace367fc97c1f11aff8" + } + Frame { + msec: 832 + hash: "e9dbbf715fc094cb22ecd5c6df602f95" + } + Frame { + msec: 848 + hash: "ca69b2b9f8e6b16e3bc6d93598b6c75a" + } + Frame { + msec: 864 + hash: "87e09752e39df5042aef163fe4ed0b47" + } + Frame { + msec: 880 + hash: "80adfaf02838c8bd372e53d0483fbac5" + } + Frame { + msec: 896 + hash: "9934a1aece14ba7369b00cf2620cd207" + } + Frame { + msec: 912 + hash: "954a70a949fdcca4e4412174f30653c3" + } + Frame { + msec: 928 + hash: "850fa936516f8b145465eac39c9a74a6" + } + Frame { + msec: 944 + hash: "1d844e8a7c710ccbf31f47470cc9abf2" + } + Frame { + msec: 960 + image: "particles.0.png" + } + Frame { + msec: 976 + hash: "33f4eee3f6e3fb715463254d727ef898" + } + Frame { + msec: 992 + hash: "68648a3f75f58b34dd9770a9edc2caea" + } + Frame { + msec: 1008 + hash: "ad0d431ab7e6cfbb43053050a1cf5e40" + } + Frame { + msec: 1024 + hash: "d1ae74c9bf3826d30fb461ca2fd8e36a" + } + Frame { + msec: 1040 + hash: "bda9d77c68a30d491abdfbfcf854c5ea" + } + Frame { + msec: 1056 + hash: "386ea303f8102339f8cd5ae88fd5f6bc" + } + Frame { + msec: 1072 + hash: "8c81d3992851ebeb3cb820bc4510af66" + } + Frame { + msec: 1088 + hash: "566813e312ffdde4a7d3af4276bc8cdd" + } + Frame { + msec: 1104 + hash: "d9c8b391b12ee40aa393f4fb39c12a16" + } + Frame { + msec: 1120 + hash: "f2bf70bda626089437f0ab67ad62d8f6" + } + Frame { + msec: 1136 + hash: "88b2d1ecd7d51d0bf8c947a3433b7013" + } + Frame { + msec: 1152 + hash: "e93e0553c5dcc6dcd21dad0932d1e3fa" + } + Frame { + msec: 1168 + hash: "c1ec148772d399ea4934cdfc514f6980" + } + Frame { + msec: 1184 + hash: "14f286793de5452f4677e8b6fd5c1e7e" + } + Frame { + msec: 1200 + hash: "220a7df0af53fc9a2442956128091ad8" + } + Frame { + msec: 1216 + hash: "84c49512f5e9f138901b3833a5adbcab" + } + Frame { + msec: 1232 + hash: "b05410caa120f5a4191a44b84aa17a8c" + } + Frame { + msec: 1248 + hash: "e1f6db204f62394205c1d4d56bbf9f52" + } + Frame { + msec: 1264 + hash: "f45033d1350009e09f62e81aeec297a5" + } + Frame { + msec: 1280 + hash: "dfd88b1dba38ab8260e00b3810b89318" + } + Frame { + msec: 1296 + hash: "17503276f68e365cde03607d66fe4c8e" + } + Frame { + msec: 1312 + hash: "28f03c5c0fe5c4647c5b9d3b72a07c76" + } + Frame { + msec: 1328 + hash: "ea2082529b50543fab22497e01938102" + } + Frame { + msec: 1344 + hash: "a700a2f3721625b1ec68107884d1ce67" + } + Frame { + msec: 1360 + hash: "ce717f1f1d98158aeef1cc6a9485dc80" + } + Frame { + msec: 1376 + hash: "7febe7c67e1c159881de72f62800a505" + } + Frame { + msec: 1392 + hash: "474931cb44a8e18426b9c2cc9f6df482" + } + Frame { + msec: 1408 + hash: "1085b4873b9a4934882a163be72a2710" + } + Frame { + msec: 1424 + hash: "59e7911800e915e6f159cb111ce61a54" + } + Frame { + msec: 1440 + hash: "6d0d780ffc726b04f9885c25b08d1009" + } + Frame { + msec: 1456 + hash: "bf896d6403dc1ad26536cc1165e71e9e" + } + Frame { + msec: 1472 + hash: "86397c7dcf5ed34edbbaa465ae6eab43" + } + Frame { + msec: 1488 + hash: "ed1b4967bf14eead9cb4d2dcfbdb46c2" + } + Frame { + msec: 1504 + hash: "67b7e59c8f945d1f3bdb1944fa736ecf" + } + Frame { + msec: 1520 + hash: "b5f95e89f39d1c4821ba38547b0f2e3b" + } + Frame { + msec: 1536 + hash: "5bc91c9e35afa255a2dda28db9802b1e" + } + Frame { + msec: 1552 + hash: "84fab4042e0ff891ca1998cbfbb60e5a" + } + Frame { + msec: 1568 + hash: "7c5ef5025a06e990171dac3e8fd93977" + } + Frame { + msec: 1584 + hash: "ab4cd0e103d71a35250668ad850a5213" + } + Frame { + msec: 1600 + hash: "aa974c4b2290f7febb121344623de86d" + } + Frame { + msec: 1616 + hash: "ff6ee1b50ca356dc98038a459e318b32" + } + Frame { + msec: 1632 + hash: "022fe9c391514fdd98bc1c38bc383df2" + } + Frame { + msec: 1648 + hash: "b1a33c9c9cbdcc1c8c9c982eef041ccd" + } + Frame { + msec: 1664 + hash: "0945e66ab5aa81beacf662eb82ec39ed" + } + Frame { + msec: 1680 + hash: "ae293f675dbdd88dec8f924140033cc9" + } + Frame { + msec: 1696 + hash: "5ace5013e3d51a8db338f65011dd10f8" + } + Frame { + msec: 1712 + hash: "9466a4e96d647f2bd8845697fce89399" + } + Frame { + msec: 1728 + hash: "73bbbfc57e020c6a0acbd5fdfa711c30" + } + Frame { + msec: 1744 + hash: "d71d7182107c3d6b004a57a321caee96" + } + Frame { + msec: 1760 + hash: "0902867c89e536cffcde69bde2eb1994" + } + Frame { + msec: 1776 + hash: "39fc26943f6077272c36e93b7cbf6994" + } + Frame { + msec: 1792 + hash: "92931d5a6e57fb9df60785a64d3a6f78" + } + Frame { + msec: 1808 + hash: "fffd632552f88f2979ef85de0ce585c2" + } + Frame { + msec: 1824 + hash: "9f97bfcffbb5d127c5eee852b30a13c4" + } + Frame { + msec: 1840 + hash: "ea9ee0293fbc45d3467e29c09e42adcd" + } + Frame { + msec: 1856 + hash: "b5b75c50f8fae3fb3b88efad536c911b" + } + Frame { + msec: 1872 + hash: "25dcd3fa30c057d1a42c19cee1ce444b" + } + Frame { + msec: 1888 + hash: "862d42abe7abd49d4a38e38a8c33a657" + } + Frame { + msec: 1904 + hash: "a335f3c8c797c1bb5537b57f952c19d1" + } + Frame { + msec: 1920 + image: "particles.1.png" + } + Frame { + msec: 1936 + hash: "da1cf98fdfe5acbe30cfbe66389aa240" + } + Frame { + msec: 1952 + hash: "088f3209c0363c06cf0607c58d00ca2d" + } + Frame { + msec: 1968 + hash: "47ba3bf2604b21f331a2e00f05926aaf" + } + Frame { + msec: 1984 + hash: "5ff0de383abdefad76380af144bd9d80" + } + Frame { + msec: 2000 + hash: "b972d1c85d3d8777f84b54dc118172fd" + } + Frame { + msec: 2016 + hash: "37581c3fbef2088b7d14b6c7bbf3cdc3" + } + Frame { + msec: 2032 + hash: "4ad6a06ac6de9dea66e9ce873a6618c1" + } + Frame { + msec: 2048 + hash: "3a0379ad966235044508c144ffbc336b" + } + Frame { + msec: 2064 + hash: "cb5a9510400943d77c9a296066f037e2" + } + Frame { + msec: 2080 + hash: "7bd5673a1d2ad8079df2569149e5811e" + } + Frame { + msec: 2096 + hash: "bd327ff6b8a4081b3a41cb0035403037" + } + Frame { + msec: 2112 + hash: "f0f9f559251f7648cd60e66ac745962d" + } + Frame { + msec: 2128 + hash: "18827630a859b0ce497f682e33558fae" + } + Frame { + msec: 2144 + hash: "e22d8110cbe34acddba799942872645d" + } + Frame { + msec: 2160 + hash: "11564e7221524cc3655c2c5f1d7e42b6" + } + Frame { + msec: 2176 + hash: "6468721ee38209aaf2c82a320bcd122e" + } + Frame { + msec: 2192 + hash: "19772d0f422fd206645ae6cf0be30b59" + } + Frame { + msec: 2208 + hash: "48b6c7e1317b9a66238c17afceb5121f" + } + Frame { + msec: 2224 + hash: "82a1af78709b78cce2d9b4eed7f8477c" + } + Frame { + msec: 2240 + hash: "36e2366eccbdd2d16c19829c34fbff87" + } + Frame { + msec: 2256 + hash: "271db39ca46c59ddc279fb41a9d191af" + } + Frame { + msec: 2272 + hash: "ee279a90e86aa89b1c3d745ab030180d" + } + Frame { + msec: 2288 + hash: "14e8c72d770644f4cec99e65aeff0d75" + } + Frame { + msec: 2304 + hash: "56fa1756eb11a30f07f8f31c22c99973" + } + Frame { + msec: 2320 + hash: "165af677ff3921f06b89b2c8d76a7924" + } + Frame { + msec: 2336 + hash: "d64aa248d9b207b87e5ba14bdabf2f6c" + } + Frame { + msec: 2352 + hash: "33e9716eb9ca62fe5c5cb1b1ee0e9e68" + } + Frame { + msec: 2368 + hash: "cff2316820c469b84c3bacabfcf1a551" + } + Frame { + msec: 2384 + hash: "9f1359c4bab95244602254ca3954e2b7" + } + Frame { + msec: 2400 + hash: "d6246d2aaea895755eab4c839c35ca9d" + } + Frame { + msec: 2416 + hash: "d446e1ac91fec10482b0c6d38ce86d17" + } + Frame { + msec: 2432 + hash: "99f443af76a9e0d2d03638bc9927fda3" + } + Frame { + msec: 2448 + hash: "a9169e293b8154947332d9754fd23af3" + } + Frame { + msec: 2464 + hash: "cc6851cc5864615c000fbc8d552eb593" + } + Frame { + msec: 2480 + hash: "58a3a6edb5842c88cb73b79a8a187717" + } + Frame { + msec: 2496 + hash: "42bcf77c98c9a80508446bd8c66e935b" + } + Frame { + msec: 2512 + hash: "0f99350ae151591fbda95158c046e072" + } + Frame { + msec: 2528 + hash: "9e817e2fd8377b7117f908c4e87d4d57" + } + Frame { + msec: 2544 + hash: "72c105bce75feeeb7a86f823945b4ff9" + } + Frame { + msec: 2560 + hash: "653b858445bdd8afdf8abd27f5e53fb8" + } + Frame { + msec: 2576 + hash: "18bf39154fbf4b42c4d3303e018a2f27" + } + Frame { + msec: 2592 + hash: "5ed5d52ab7da7ae77e97f3ace09b3b8d" + } + Frame { + msec: 2608 + hash: "1d382462e5746ee9b6df980364b1c96b" + } + Frame { + msec: 2624 + hash: "2a0a561f38c113a0f177b1c2b99ee5e1" + } + Frame { + msec: 2640 + hash: "0605d3e2dd9132d9c1d25b75a870d647" + } + Frame { + msec: 2656 + hash: "a1def1576f386c90bb80d46e254bd384" + } + Frame { + msec: 2672 + hash: "cf38d4ae577047048d2bd0a4005abfe2" + } + Frame { + msec: 2688 + hash: "d7cb6715cd89978bbca5ce4c93b488e5" + } + Frame { + msec: 2704 + hash: "9a5075ee794af14d4f17a52bdbc47f1e" + } + Frame { + msec: 2720 + hash: "fd3d803a1e5e9e3eeae7d5edcddd0072" + } + Frame { + msec: 2736 + hash: "445114e7d10581a475989e469323d83d" + } + Frame { + msec: 2752 + hash: "58328c1d4c0ee7fca78b684697f1922c" + } + Frame { + msec: 2768 + hash: "433df4d872b9565b43af5afce1b42e15" + } + Frame { + msec: 2784 + hash: "3b694f15722a087c2c9a860cad8bb6de" + } + Frame { + msec: 2800 + hash: "1986c8036bd548ca06a32aa98ab4fc83" + } + Frame { + msec: 2816 + hash: "7845dbb0e38145f54a9e4e0bfbd608db" + } + Frame { + msec: 2832 + hash: "caed393910ae7467c307a314bdf459ef" + } + Frame { + msec: 2848 + hash: "f3f6b41b7ed04dbc1693c169bdae3b13" + } + Frame { + msec: 2864 + hash: "b9a87d15d48f951b0a1d6962fb1d5995" + } + Frame { + msec: 2880 + image: "particles.2.png" + } + Frame { + msec: 2896 + hash: "954300274b6a5785e03a6cdae67238e9" + } + Frame { + msec: 2912 + hash: "5b7f51afad796107289369c7d3494843" + } + Frame { + msec: 2928 + hash: "41164f28cbb94528eda719d590d1cf75" + } + Frame { + msec: 2944 + hash: "5953d4c9a4b4c83ba1dfd83a57ec2742" + } + Frame { + msec: 2960 + hash: "0be7c6187a26b44f12bf71587372a6c7" + } + Frame { + msec: 2976 + hash: "a7cab1faf0cdd5649c8ea3c26d2e80d0" + } + Frame { + msec: 2992 + hash: "5f91bef1865623030aea20805993319a" + } + Frame { + msec: 3008 + hash: "69d34e2a27c471ad44f8aba8d906a961" + } + Frame { + msec: 3024 + hash: "5a987879aff30d6c6712c0631bc2f43d" + } + Frame { + msec: 3040 + hash: "62b9132c58cd5fdcfe7f1bc5e64885cf" + } + Frame { + msec: 3056 + hash: "d394ef9b504abf94c1d28a9fb7f3c28b" + } + Frame { + msec: 3072 + hash: "a559cc25af950227fa5fdf70be7fd94c" + } + Frame { + msec: 3088 + hash: "318dde40fc72c5f8ee45b865a68922b1" + } + Frame { + msec: 3104 + hash: "3cbfd55773e52f48f01fe66c28c0b992" + } +} diff --git a/tests/auto/declarative/visual/qmlgraphicsparticles/particles.qml b/tests/auto/declarative/visual/qmlgraphicsparticles/particles.qml new file mode 100644 index 0000000..8fb793f --- /dev/null +++ b/tests/auto/declarative/visual/qmlgraphicsparticles/particles.qml @@ -0,0 +1,48 @@ +import Qt 4.6 + +Rectangle { + width: 640; height: 480; color: "black" + + Particles { id:particlesA + y:0; width: 260; height:30; source: "star.png"; + lifeSpan:1000; count: 50; angle:70; angleDeviation:36; + velocity:30; velocityDeviation:10; emissionRate: 10 + ParticleMotionWander { xvariance:30; pace:100 } + } + + Particles { id:particlesB + y:280; x:180; width:1; height:1; lifeSpan:1000; source: "star.png" + count: 100; angle:270; angleDeviation:45; velocity:50; velocityDeviation:30; + emissionRate: 0 + ParticleMotionGravity { yattractor: 1000; xattractor:0; acceleration:25 } + } + + Timer { running: true; interval: 1000; repeat: true; onTriggered: particlesB.burst(200, 2000); } + + Column{ + x: 340; + Repeater{ + model: 5 + delegate: Component{ + Item{ + width: 100; height: 100 + Rectangle{ + color: "blue" + width: 2; height: 2; + x: 49; y:49; + } + Particles{ + x: 50; y:50; width: 0; height: 0; + fadeInDuration: 0; fadeOutDuration: 0 + lifeSpan: 1000; lifeSpanDeviation:0; + source: "star.png" + count: -1; emissionRate: 120; + emissionVariance: index/2; + velocity: 250; velocityDeviation: 0; + angle: 0; angleDeviation: 0; + } + } + } + } + } +} diff --git a/tests/auto/declarative/visual/qmlgraphicsparticles/star.png b/tests/auto/declarative/visual/qmlgraphicsparticles/star.png new file mode 100644 index 0000000..defbde5 Binary files /dev/null and b/tests/auto/declarative/visual/qmlgraphicsparticles/star.png differ -- cgit v0.12 From 34aaa28047656a43132933eb86cfdd8f2e63a5b5 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 5 Nov 2009 17:59:55 +1000 Subject: Missing files for 8b40fac7e97a629ddaf1c0f6de2ebb504f004060 --- .../auto/declarative/valuetypes/data/autoBindingRemoval.2.qml | 9 +++++++++ .../auto/declarative/valuetypes/data/autoBindingRemoval.3.qml | 10 ++++++++++ tests/auto/declarative/valuetypes/data/autoBindingRemoval.qml | 9 +++++++++ tests/auto/declarative/valuetypes/data/bindingAssignment.qml | 7 +++++++ tests/auto/declarative/valuetypes/data/bindingConflict.qml | 8 ++++++++ tests/auto/declarative/valuetypes/data/bindingRead.qml | 5 +++++ tests/auto/declarative/valuetypes/data/scriptAccess.qml | 9 +++++++++ tests/auto/declarative/valuetypes/data/staticAssignment.qml | 5 +++++ tests/auto/declarative/valuetypes/data/valueInterceptors.qml | 8 ++++++++ tests/auto/declarative/valuetypes/data/valueSources.qml | 5 +++++ 10 files changed, 75 insertions(+) create mode 100644 tests/auto/declarative/valuetypes/data/autoBindingRemoval.2.qml create mode 100644 tests/auto/declarative/valuetypes/data/autoBindingRemoval.3.qml create mode 100644 tests/auto/declarative/valuetypes/data/autoBindingRemoval.qml create mode 100644 tests/auto/declarative/valuetypes/data/bindingAssignment.qml create mode 100644 tests/auto/declarative/valuetypes/data/bindingConflict.qml create mode 100644 tests/auto/declarative/valuetypes/data/bindingRead.qml create mode 100644 tests/auto/declarative/valuetypes/data/scriptAccess.qml create mode 100644 tests/auto/declarative/valuetypes/data/staticAssignment.qml create mode 100644 tests/auto/declarative/valuetypes/data/valueInterceptors.qml create mode 100644 tests/auto/declarative/valuetypes/data/valueSources.qml diff --git a/tests/auto/declarative/valuetypes/data/autoBindingRemoval.2.qml b/tests/auto/declarative/valuetypes/data/autoBindingRemoval.2.qml new file mode 100644 index 0000000..ce2e82d --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/autoBindingRemoval.2.qml @@ -0,0 +1,9 @@ +import Test 1.0 + +MyTypeObject { + property int value: 10 + rect.x: value + + onRunScript: { rect = Qt.rect(10, 10, 10, 10) } +} + diff --git a/tests/auto/declarative/valuetypes/data/autoBindingRemoval.3.qml b/tests/auto/declarative/valuetypes/data/autoBindingRemoval.3.qml new file mode 100644 index 0000000..c82b533 --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/autoBindingRemoval.3.qml @@ -0,0 +1,10 @@ +import Test 1.0 + +MyTypeObject { + property var value + + rect: value + + onRunScript: { rect.x = 44 } +} + diff --git a/tests/auto/declarative/valuetypes/data/autoBindingRemoval.qml b/tests/auto/declarative/valuetypes/data/autoBindingRemoval.qml new file mode 100644 index 0000000..a8a72f5 --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/autoBindingRemoval.qml @@ -0,0 +1,9 @@ +import Test 1.0 + +MyTypeObject { + property int value: 10 + rect.x: value + + onRunScript: { rect.x = 42; } +} + diff --git a/tests/auto/declarative/valuetypes/data/bindingAssignment.qml b/tests/auto/declarative/valuetypes/data/bindingAssignment.qml new file mode 100644 index 0000000..a652186 --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/bindingAssignment.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + property int value: 10 + + rect.x: value +} diff --git a/tests/auto/declarative/valuetypes/data/bindingConflict.qml b/tests/auto/declarative/valuetypes/data/bindingConflict.qml new file mode 100644 index 0000000..fd25c9f --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/bindingConflict.qml @@ -0,0 +1,8 @@ +import Test 1.0 + +MyTypeObject { + property int value: 13 + + rect.x: value + rect: "10,10,10x10" +} diff --git a/tests/auto/declarative/valuetypes/data/bindingRead.qml b/tests/auto/declarative/valuetypes/data/bindingRead.qml new file mode 100644 index 0000000..538d776 --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/bindingRead.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + property int value: rect.x +} diff --git a/tests/auto/declarative/valuetypes/data/scriptAccess.qml b/tests/auto/declarative/valuetypes/data/scriptAccess.qml new file mode 100644 index 0000000..96592eb --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/scriptAccess.qml @@ -0,0 +1,9 @@ +import Qt 4.6 +import Test 1.0 + +MyTypeObject { + property int valuePre; + property int valuePost; + + Component.onCompleted: { valuePre = rect.x; rect.x = 19; valuePost = rect.x; } +} diff --git a/tests/auto/declarative/valuetypes/data/staticAssignment.qml b/tests/auto/declarative/valuetypes/data/staticAssignment.qml new file mode 100644 index 0000000..b687f89 --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/staticAssignment.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + rect.x: 9 +} diff --git a/tests/auto/declarative/valuetypes/data/valueInterceptors.qml b/tests/auto/declarative/valuetypes/data/valueInterceptors.qml new file mode 100644 index 0000000..026ae83 --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/valueInterceptors.qml @@ -0,0 +1,8 @@ +import Test 1.0 + +MyTypeObject { + property int value: 13; + + rect.x: MyOffsetValueInterceptor {} + rect.x: value +} diff --git a/tests/auto/declarative/valuetypes/data/valueSources.qml b/tests/auto/declarative/valuetypes/data/valueSources.qml new file mode 100644 index 0000000..d4d4391 --- /dev/null +++ b/tests/auto/declarative/valuetypes/data/valueSources.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + rect.x: MyConstantValueSource {} +} -- cgit v0.12 From 9bb160d8cee882bec25d7654a4d0554a755265c5 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 5 Nov 2009 18:27:18 +1000 Subject: Get tests passing on Mac There was inconsistent rounding of text widths. Task-number: QT-4200 QT-4201 --- .../graphicsitems/qmlgraphicsparticles.cpp | 22 +++++++++++----------- .../declarative/qfxtextedit/tst_qfxtextedit.cpp | 6 ++++-- .../declarative/qfxtextinput/tst_qfxtextinput.cpp | 4 ++-- .../qmlgraphicstext/tst_qmlgraphicstext.cpp | 6 ++++-- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsparticles.cpp b/src/declarative/graphicsitems/qmlgraphicsparticles.cpp index 92943e8..4ac02b4 100644 --- a/src/declarative/graphicsitems/qmlgraphicsparticles.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsparticles.cpp @@ -302,7 +302,7 @@ void QmlGraphicsParticleMotionWander::advance(QmlGraphicsParticle &p, int interv qreal xdiff = p.x_velocity - d->x_targetV; if ((xdiff > d->x_peak && d->x_var > 0.0) || (xdiff < -d->x_peak && d->x_var < 0.0)) { d->x_var = -d->x_var; - d->x_peak = _xvariance + _xvariance * qreal(rand()) / RAND_MAX; + d->x_peak = _xvariance + _xvariance * qreal(qrand()) / RAND_MAX; } p.x_velocity += d->x_var * interval; } @@ -312,7 +312,7 @@ void QmlGraphicsParticleMotionWander::advance(QmlGraphicsParticle &p, int interv qreal ydiff = p.y_velocity - d->y_targetV; if ((ydiff > d->y_peak && d->y_var > 0.0) || (ydiff < -d->y_peak && d->y_var < 0.0)) { d->y_var = -d->y_var; - d->y_peak = _yvariance + _yvariance * qreal(rand()) / RAND_MAX; + d->y_peak = _yvariance + _yvariance * qreal(qrand()) / RAND_MAX; } p.y_velocity += d->y_var * interval; } @@ -329,8 +329,8 @@ void QmlGraphicsParticleMotionWander::created(QmlGraphicsParticle &p) d->y_targetV = p.y_velocity; d->x_peak = _xvariance; d->y_peak = _yvariance; - d->x_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; - d->y_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; + d->x_var = _pace * qreal(qrand()) / RAND_MAX / 1000.0; + d->y_var = _pace * qreal(qrand()) / RAND_MAX / 1000.0; } } @@ -456,7 +456,7 @@ void QmlGraphicsParticlesPrivate::tick(int time) if (emissionRate != -1){ qreal variance = 1.; if (emissionVariance > 0.){ - variance += (qreal(rand())/RAND_MAX) * emissionVariance * (rand()%2?-1.:1.); + variance += (qreal(qrand())/RAND_MAX) * emissionVariance * (qrand()%2?-1.:1.); } qreal emission = emissionRate * (qreal(interval)/1000.); emission = emission * variance + emissionCarry; @@ -478,7 +478,7 @@ void QmlGraphicsParticlesPrivate::tick(int time) }else{ qreal variance = 1.; if (emissionVariance > 0.){ - variance += (qreal(rand())/RAND_MAX) * emissionVariance * (rand()%2?-1.:1.); + variance += (qreal(qrand())/RAND_MAX) * emissionVariance * (qrand()%2?-1.:1.); } qreal workingEmission = bursts[i].second * (qreal(interval)/1000.); workingEmission *= variance; @@ -510,11 +510,11 @@ void QmlGraphicsParticlesPrivate::createParticle(int time) #endif Q_Q(QmlGraphicsParticles); QmlGraphicsParticle p(time); - p.x = q->x() + q->width() * qreal(rand()) / RAND_MAX - image.width()/2.0; - p.y = q->y() + q->height() * qreal(rand()) / RAND_MAX - image.height()/2.0; + p.x = q->x() + q->width() * qreal(qrand()) / RAND_MAX - image.width()/2.0; + p.y = q->y() + q->height() * qreal(qrand()) / RAND_MAX - image.height()/2.0; p.lifeSpan = lifeSpan; if (lifeSpanDev) - p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(rand()) / RAND_MAX); + p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(qrand()) / RAND_MAX); p.fadeOutAge = p.lifeSpan - fadeOutDur; if (fadeInDur == 0.) { p.state= QmlGraphicsParticle::Solid; @@ -522,12 +522,12 @@ void QmlGraphicsParticlesPrivate::createParticle(int time) } qreal a = angle; if (angleDev) - a += angleDev/2 - angleDev * qreal(rand()) / RAND_MAX; + a += angleDev/2 - angleDev * qreal(qrand()) / RAND_MAX; if (a > M_PI) a = a - 2 * M_PI; qreal v = velocity; if (velocityDev) - v += velocityDev/2 - velocityDev * qreal(rand()) / RAND_MAX; + v += velocityDev/2 - velocityDev * qreal(qrand()) / RAND_MAX; p.x_velocity = v * fastCos(a); p.y_velocity = v * fastSin(a); particles.append(p); diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp index 7bc6121..19d5998 100644 --- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp +++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include #include "../../../shared/util.h" +#include #include #include #include @@ -183,8 +184,9 @@ void tst_qfxtextedit::width() for (int i = 0; i < standard.size(); i++) { QFont f; - QFontMetrics fm(f); - int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); + QFontMetricsF fm(f); + qreal metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); + metricWidth = floor(metricWidth); QString componentStr = "import Qt 4.6\nTextEdit { text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); diff --git a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp index 2dc096d..8eeb22d 100644 --- a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp +++ b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp @@ -132,8 +132,8 @@ void tst_qfxtextinput::width() for (int i = 0; i < standard.size(); i++) { QFont f; - QFontMetrics fm(f); - int metricWidth = fm.width(standard.at(i)); + QFontMetricsF fm(f); + qreal metricWidth = fm.width(standard.at(i)); QString componentStr = "import Qt 4.6\nTextInput { text: \"" + standard.at(i) + "\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp index ba5c835..2a3cdde 100644 --- a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -45,6 +45,7 @@ #include #include #include +#include class tst_qmlgraphicstext : public QObject @@ -201,8 +202,9 @@ void tst_qmlgraphicstext::width() QVERIFY(!Qt::mightBeRichText(standard.at(i))); // self-test QFont f; - QFontMetrics fm(f); - int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); + QFontMetricsF fm(f); + qreal metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); + metricWidth = floor(metricWidth); QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); -- cgit v0.12 From 1a7cee240904a3aea112fc102901066fe26d45d6 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 5 Nov 2009 18:30:55 +1000 Subject: More error-case tests --- .../declarative/qmllanguage/data/invalidImportID.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/invalidImportID.qml | 4 ++++ .../declarative/qmllanguage/data/invalidRoot.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/invalidRoot.qml | 2 ++ .../auto/declarative/qmllanguage/data/property.1.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/property.1.qml | 5 +++++ .../auto/declarative/qmllanguage/data/property.2.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/property.2.qml | 6 ++++++ .../auto/declarative/qmllanguage/data/property.3.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/property.3.qml | 7 +++++++ .../auto/declarative/qmllanguage/data/property.4.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/property.4.qml | 5 +++++ .../auto/declarative/qmllanguage/data/property.5.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/property.5.qml | 6 ++++++ .../auto/declarative/qmllanguage/data/script.12.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/script.12.qml | 6 ++++++ tests/auto/declarative/qmllanguage/data/signal.1.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/signal.1.qml | 5 +++++ tests/auto/declarative/qmllanguage/data/signal.2.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/signal.2.qml | 6 ++++++ tests/auto/declarative/qmllanguage/data/signal.3.errors.txt | 1 + tests/auto/declarative/qmllanguage/data/signal.3.qml | 6 ++++++ tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 13 +++++++++++++ 23 files changed, 82 insertions(+) create mode 100644 tests/auto/declarative/qmllanguage/data/invalidImportID.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidImportID.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidRoot.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidRoot.qml create mode 100644 tests/auto/declarative/qmllanguage/data/property.1.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/property.1.qml create mode 100644 tests/auto/declarative/qmllanguage/data/property.2.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/property.2.qml create mode 100644 tests/auto/declarative/qmllanguage/data/property.3.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/property.3.qml create mode 100644 tests/auto/declarative/qmllanguage/data/property.4.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/property.4.qml create mode 100644 tests/auto/declarative/qmllanguage/data/property.5.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/property.5.qml create mode 100644 tests/auto/declarative/qmllanguage/data/script.12.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/script.12.qml create mode 100644 tests/auto/declarative/qmllanguage/data/signal.1.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/signal.1.qml create mode 100644 tests/auto/declarative/qmllanguage/data/signal.2.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/signal.2.qml create mode 100644 tests/auto/declarative/qmllanguage/data/signal.3.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/signal.3.qml diff --git a/tests/auto/declarative/qmllanguage/data/invalidImportID.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidImportID.errors.txt new file mode 100644 index 0000000..a65f5fd --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidImportID.errors.txt @@ -0,0 +1 @@ +2:18:Invalid import qualifier ID diff --git a/tests/auto/declarative/qmllanguage/data/invalidImportID.qml b/tests/auto/declarative/qmllanguage/data/invalidImportID.qml new file mode 100644 index 0000000..75aa06d --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidImportID.qml @@ -0,0 +1,4 @@ +import Qt 4.6 +import Qt 4.6 as qt + +Object {} diff --git a/tests/auto/declarative/qmllanguage/data/invalidRoot.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidRoot.errors.txt new file mode 100644 index 0000000..4bcc948 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidRoot.errors.txt @@ -0,0 +1 @@ +1:1:Expected type name diff --git a/tests/auto/declarative/qmllanguage/data/invalidRoot.qml b/tests/auto/declarative/qmllanguage/data/invalidRoot.qml new file mode 100644 index 0000000..427827c --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidRoot.qml @@ -0,0 +1,2 @@ +foo { +} diff --git a/tests/auto/declarative/qmllanguage/data/property.1.errors.txt b/tests/auto/declarative/qmllanguage/data/property.1.errors.txt new file mode 100644 index 0000000..3ae6c46 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.1.errors.txt @@ -0,0 +1 @@ +4:14:Expected property type diff --git a/tests/auto/declarative/qmllanguage/data/property.1.qml b/tests/auto/declarative/qmllanguage/data/property.1.qml new file mode 100644 index 0000000..62178e5 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.1.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Object { + property blah a; +} diff --git a/tests/auto/declarative/qmllanguage/data/property.2.errors.txt b/tests/auto/declarative/qmllanguage/data/property.2.errors.txt new file mode 100644 index 0000000..a18e21a --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.2.errors.txt @@ -0,0 +1 @@ +4:14:Unexpected property type modifier diff --git a/tests/auto/declarative/qmllanguage/data/property.2.qml b/tests/auto/declarative/qmllanguage/data/property.2.qml new file mode 100644 index 0000000..1d6d015 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.2.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Object { + property invalidmodifier a; +} + diff --git a/tests/auto/declarative/qmllanguage/data/property.3.errors.txt b/tests/auto/declarative/qmllanguage/data/property.3.errors.txt new file mode 100644 index 0000000..5e09a25 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.3.errors.txt @@ -0,0 +1 @@ +4:14:Invalid property type modifier diff --git a/tests/auto/declarative/qmllanguage/data/property.3.qml b/tests/auto/declarative/qmllanguage/data/property.3.qml new file mode 100644 index 0000000..1b14b86 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.3.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Object { + property invalidmodifier a; +} + + diff --git a/tests/auto/declarative/qmllanguage/data/property.4.errors.txt b/tests/auto/declarative/qmllanguage/data/property.4.errors.txt new file mode 100644 index 0000000..b447186 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.4.errors.txt @@ -0,0 +1 @@ +5:1:Syntax error diff --git a/tests/auto/declarative/qmllanguage/data/property.4.qml b/tests/auto/declarative/qmllanguage/data/property.4.qml new file mode 100644 index 0000000..d256c96 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.4.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Object { + readonly property int a +} diff --git a/tests/auto/declarative/qmllanguage/data/property.5.errors.txt b/tests/auto/declarative/qmllanguage/data/property.5.errors.txt new file mode 100644 index 0000000..32a8dc1 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.5.errors.txt @@ -0,0 +1 @@ +4:5:Readonly not yet supported diff --git a/tests/auto/declarative/qmllanguage/data/property.5.qml b/tests/auto/declarative/qmllanguage/data/property.5.qml new file mode 100644 index 0000000..c3aaf5e --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/property.5.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Object { + readonly property int a: value +} + diff --git a/tests/auto/declarative/qmllanguage/data/script.12.errors.txt b/tests/auto/declarative/qmllanguage/data/script.12.errors.txt new file mode 100644 index 0000000..85c8396 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/script.12.errors.txt @@ -0,0 +1 @@ +4:5:QmlJS declaration outside Script element diff --git a/tests/auto/declarative/qmllanguage/data/script.12.qml b/tests/auto/declarative/qmllanguage/data/script.12.qml new file mode 100644 index 0000000..ea6c482 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/script.12.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Object { + var a +} + diff --git a/tests/auto/declarative/qmllanguage/data/signal.1.errors.txt b/tests/auto/declarative/qmllanguage/data/signal.1.errors.txt new file mode 100644 index 0000000..78d9960 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/signal.1.errors.txt @@ -0,0 +1 @@ +4:12:Expected parameter type diff --git a/tests/auto/declarative/qmllanguage/data/signal.1.qml b/tests/auto/declarative/qmllanguage/data/signal.1.qml new file mode 100644 index 0000000..d0ad155 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/signal.1.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Object { + signal mySignal(nontype a) +} diff --git a/tests/auto/declarative/qmllanguage/data/signal.2.errors.txt b/tests/auto/declarative/qmllanguage/data/signal.2.errors.txt new file mode 100644 index 0000000..fce8928 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/signal.2.errors.txt @@ -0,0 +1 @@ +4:21:Unexpected token `;' diff --git a/tests/auto/declarative/qmllanguage/data/signal.2.qml b/tests/auto/declarative/qmllanguage/data/signal.2.qml new file mode 100644 index 0000000..aa45ae9 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/signal.2.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Object { + signal mySignal(,) +} + diff --git a/tests/auto/declarative/qmllanguage/data/signal.3.errors.txt b/tests/auto/declarative/qmllanguage/data/signal.3.errors.txt new file mode 100644 index 0000000..bf043ac --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/signal.3.errors.txt @@ -0,0 +1 @@ +4:22:Expected token `identifier' diff --git a/tests/auto/declarative/qmllanguage/data/signal.3.qml b/tests/auto/declarative/qmllanguage/data/signal.3.qml new file mode 100644 index 0000000..f38ccc5 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/signal.3.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Object { + signal mySignal(a) +} + diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 0fa36a1..c646583 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -246,6 +246,17 @@ void tst_qmllanguage::errors_data() QTest::newRow("importNamespaceConflict") << "importNamespaceConflict.qml" << "importNamespaceConflict.errors.txt" << false; QTest::newRow("importVersionMissing (builtin)") << "importVersionMissingBuiltIn.qml" << "importVersionMissingBuiltIn.errors.txt" << false; QTest::newRow("importVersionMissing (installed)") << "importVersionMissingInstalled.qml" << "importVersionMissingInstalled.errors.txt" << false; + QTest::newRow("invalidImportID") << "invalidImportID.qml" << "invalidImportID.errors.txt" << false; + + QTest::newRow("signal.1") << "signal.1.qml" << "signal.1.errors.txt" << false; + QTest::newRow("signal.2") << "signal.2.qml" << "signal.2.errors.txt" << false; + QTest::newRow("signal.3") << "signal.3.qml" << "signal.3.errors.txt" << false; + + QTest::newRow("property.1") << "property.1.qml" << "property.1.errors.txt" << false; + QTest::newRow("property.2") << "property.2.qml" << "property.2.errors.txt" << false; + QTest::newRow("property.3") << "property.3.qml" << "property.3.errors.txt" << false; + QTest::newRow("property.4") << "property.4.qml" << "property.4.errors.txt" << false; + QTest::newRow("property.5") << "property.5.qml" << "property.5.errors.txt" << false; QTest::newRow("Script.1") << "script.1.qml" << "script.1.errors.txt" << false; QTest::newRow("Script.2") << "script.2.qml" << "script.2.errors.txt" << false; @@ -258,6 +269,7 @@ void tst_qmllanguage::errors_data() QTest::newRow("Script.9") << "script.9.qml" << "script.9.errors.txt" << false; QTest::newRow("Script.10") << "script.10.qml" << "script.10.errors.txt" << false; QTest::newRow("Script.11") << "script.11.qml" << "script.11.errors.txt" << false; + QTest::newRow("Script.12") << "script.12.qml" << "script.12.errors.txt" << false; QTest::newRow("Component.1") << "component.1.qml" << "component.1.errors.txt" << false; QTest::newRow("Component.2") << "component.2.qml" << "component.2.errors.txt" << false; @@ -270,6 +282,7 @@ void tst_qmllanguage::errors_data() QTest::newRow("defaultGrouped") << "defaultGrouped.qml" << "defaultGrouped.errors.txt" << false; QTest::newRow("emptySignal") << "emptySignal.qml" << "emptySignal.errors.txt" << false; QTest::newRow("doubleSignal") << "doubleSignal.qml" << "doubleSignal.errors.txt" << false; + QTest::newRow("invalidRoot") << "invalidRoot.qml" << "invalidRoot.errors.txt" << false; } void tst_qmllanguage::errors() -- cgit v0.12 From 315d460e6a4ce5fa8c9fcb90474d43174b5e0b0d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 5 Nov 2009 19:56:22 +1000 Subject: Tests --- src/declarative/qml/qmlmetatype.cpp | 45 +---- src/declarative/qml/qmlmetatype.h | 3 - src/declarative/qml/qmlprivate.h | 3 +- .../declarative/qmlmetatype/tst_qmlmetatype.cpp | 225 +++++++++++++++++++++ 4 files changed, 231 insertions(+), 45 deletions(-) diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index 6ecaa9f..5fb2f50 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -134,7 +134,6 @@ public: QmlCustomParser *m_customParser; mutable volatile bool m_isSetup:1; mutable QList m_metaObjects; - mutable QByteArray m_hash; }; QmlTypePrivate::QmlTypePrivate() @@ -259,27 +258,6 @@ void QmlTypePrivate::init() const m_metaObjects.at(ii).metaObject->methodOffset(); } - // Calculate hash - QByteArray hashData; - - const QMetaObject *myMetaObject = m_metaObjects.isEmpty()?m_baseMetaObject:m_metaObjects.first().metaObject; - - for (int ii = 0; ii < myMetaObject->propertyCount(); ++ii) { - QMetaProperty prop = myMetaObject->property(ii); - hashData.append(prop.type()); - hashData.append("|"); - hashData.append(prop.name()); - hashData.append("|"); - } - - for (int ii = 0; ii < myMetaObject->methodCount(); ++ii) { - QMetaMethod method = myMetaObject->method(ii); - hashData.append(method.signature()); - hashData.append("|"); - } - - m_hash = QCryptographicHash::hash(hashData, QCryptographicHash::Md5); - m_isSetup = true; lock.unlock(); } @@ -297,13 +275,6 @@ QByteArray QmlType::qmlTypeName() const return d->m_name; } -QByteArray QmlType::hash() const -{ - d->init(); - - return d->m_hash; -} - QObject *QmlType::create() const { d->init(); @@ -804,17 +775,6 @@ const char *QmlMetaType::interfaceIId(int userType) return 0; } -bool QmlMetaType::isObject(const QMetaObject *mo) -{ - // ### Huh? - while(mo) { - if (mo == &QObject::staticMetaObject) - return true; - mo = mo->superClass(); - } - return false; -} - bool QmlMetaType::isQmlList(int userType) { QReadLocker lock(metaTypeDataLock()); @@ -851,6 +811,9 @@ int QmlMetaType::listCount(const QVariant &v) QVariant QmlMetaType::listAt(const QVariant &v, int idx) { + if (idx < 0) + return QVariant(); + int userType = v.userType(); QReadLocker lock(metaTypeDataLock()); @@ -861,7 +824,7 @@ QVariant QmlMetaType::listAt(const QVariant &v, int idx) if (type && type->qListTypeId() == userType) return type->listAt(v, idx); else - return 0; + return QVariant(); } /*! diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h index e90c367..1f493f8 100644 --- a/src/declarative/qml/qmlmetatype.h +++ b/src/declarative/qml/qmlmetatype.h @@ -97,7 +97,6 @@ public: static bool isInterface(int); static const char *interfaceIId(int); static bool isObject(int); - static bool isObject(const QMetaObject *); static bool isList(int); static bool isList(const QVariant &); static bool isQmlList(int); @@ -121,8 +120,6 @@ public: int minorVersion() const; bool availableInVersion(int vmajor, int vminor) const; - QByteArray hash() const; - QObject *create() const; QmlCustomParser *customParser() const; diff --git a/src/declarative/qml/qmlprivate.h b/src/declarative/qml/qmlprivate.h index e5b1060..0eec43c 100644 --- a/src/declarative/qml/qmlprivate.h +++ b/src/declarative/qml/qmlprivate.h @@ -283,7 +283,8 @@ int QmlPrivate::list_op(QmlPrivate::ListOp op, int val, } break; case QmlPrivate::Value: - *((QVariant *)*out) = QVariant::fromValue(list->at(val)); + if (list->count() <= val) *((QVariant *)*out) = QVariant(); + else *((QVariant *)*out) = QVariant::fromValue(list->at(val)); break; } return 0; diff --git a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp index ed102a5..b481ce4 100644 --- a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp +++ b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp @@ -51,6 +51,7 @@ #include #include #include +#include class tst_qmlmetatype : public QObject { @@ -60,8 +61,62 @@ public: private slots: void copy(); + + void qmlParserStatusCast(); + void qmlPropertyValueSourceCast(); + void qmlPropertyValueInterceptorCast(); + + void isList(); + void isQmlList(); + + void listCount(); + void listAt(); + + void defaultObject(); }; +class TestType : public QObject +{ + Q_OBJECT + Q_PROPERTY(int foo READ foo); + + Q_CLASSINFO("DefaultProperty", "foo"); +public: + int foo() { return 0; } +}; +QML_DECLARE_TYPE(TestType); +QML_DEFINE_TYPE(Test, 1, 0, TestType, TestType); + +class ParserStatusTestType : public QObject, public QmlParserStatus +{ + Q_OBJECT + Q_CLASSINFO("DefaultProperty", "foo"); // Missing default property +}; +QML_DECLARE_TYPE(ParserStatusTestType); +QML_DEFINE_TYPE(Test, 1, 0, ParserStatusTestType, ParserStatusTestType); + +class ValueSourceTestType : public QObject, public QmlPropertyValueSource +{ + Q_OBJECT + Q_INTERFACES(QmlPropertyValueSource) +public: + virtual void setTarget(const QmlMetaProperty &) {} +}; +QML_DECLARE_TYPE(ValueSourceTestType); +QML_DEFINE_TYPE(Test, 1, 0, ValueSourceTestType, ValueSourceTestType); + +class ValueInterceptorTestType : public QObject, public QmlPropertyValueInterceptor +{ + Q_OBJECT + Q_INTERFACES(QmlPropertyValueInterceptor) +public: + virtual void setTarget(const QmlMetaProperty &) {} + virtual void write(const QVariant &) {} +}; +QML_DECLARE_TYPE(ValueInterceptorTestType); +QML_DEFINE_TYPE(Test, 1, 0, ValueInterceptorTestType, ValueInterceptorTestType); + + #define COPY_TEST(cpptype, metatype, value, defaultvalue) \ { \ cpptype v = (value); cpptype v2 = (value); \ @@ -181,6 +236,7 @@ void tst_qmlmetatype::copy() QT_COPY_TEST(QKeySequence, QKeySequence("Ctrl+O")); QT_COPY_TEST(QPen, QPen(Qt::red)); QT_COPY_TEST(QTextLength, QTextLength(QTextLength::FixedLength, 10.2)); + QT_COPY_TEST(QTextFormat, QTextFormat(QTextFormat::ListFormat)); QT_COPY_TEST(QMatrix, QMatrix().translate(10, 10)); QT_COPY_TEST(QTransform, QTransform().translate(10, 10)); QT_COPY_TEST(QMatrix4x4, QMatrix4x4().translate(10, 10)); @@ -204,6 +260,175 @@ void tst_qmlmetatype::copy() COPY_TEST(QObject *, QObjectStar, &objectValue, 0); COPY_TEST(QWidget *, QWidgetStar, &widgetValue, 0); COPY_TEST(qreal, QReal, 10.2, 0); + + { + QVariant tv = QVariant::fromValue(QVariant(10)); + QVariant v(tv); QVariant v2(tv); + QVERIFY(QmlMetaType::copy(qMetaTypeId(), &v, 0)); + QVERIFY(v == QVariant()); + QVERIFY(QmlMetaType::copy(qMetaTypeId(), &v, &v2)); + QVERIFY(v == tv); + } + + { + TestType t; QVariant tv = QVariant::fromValue(&t); + + QVariant v(tv); QVariant v2(tv); + QVERIFY(QmlMetaType::copy(qMetaTypeId(), &v, 0)); + QVERIFY(v == QVariant::fromValue((TestType *)0)); + QVERIFY(QmlMetaType::copy(qMetaTypeId(), &v, &v2)); + QVERIFY(v == tv); + } +} + +void tst_qmlmetatype::qmlParserStatusCast() +{ + QCOMPARE(QmlMetaType::qmlParserStatusCast(QVariant::Int), -1); + QCOMPARE(QmlMetaType::qmlParserStatusCast(qMetaTypeId()), -1); + QCOMPARE(QmlMetaType::qmlParserStatusCast(qMetaTypeId()), -1); + + int cast = QmlMetaType::qmlParserStatusCast(qMetaTypeId()); + QVERIFY(cast != -1); + QVERIFY(cast != 0); + + ParserStatusTestType t; + QVERIFY(reinterpret_cast((QObject *)&t) != reinterpret_cast((QmlParserStatus *)&t)); + + QmlParserStatus *status = reinterpret_cast(reinterpret_cast((QObject *)&t) + cast); + QCOMPARE(status, &t); +} + +void tst_qmlmetatype::qmlPropertyValueSourceCast() +{ + QCOMPARE(QmlMetaType::qmlPropertyValueSourceCast(QVariant::Int), -1); + QCOMPARE(QmlMetaType::qmlPropertyValueSourceCast(qMetaTypeId()), -1); + QCOMPARE(QmlMetaType::qmlPropertyValueSourceCast(qMetaTypeId()), -1); + + int cast = QmlMetaType::qmlPropertyValueSourceCast(qMetaTypeId()); + QVERIFY(cast != -1); + QVERIFY(cast != 0); + + ValueSourceTestType t; + QVERIFY(reinterpret_cast((QObject *)&t) != reinterpret_cast((QmlPropertyValueSource *)&t)); + + QmlPropertyValueSource *source = reinterpret_cast(reinterpret_cast((QObject *)&t) + cast); + QCOMPARE(source, &t); +} + +void tst_qmlmetatype::qmlPropertyValueInterceptorCast() +{ + QCOMPARE(QmlMetaType::qmlPropertyValueInterceptorCast(QVariant::Int), -1); + QCOMPARE(QmlMetaType::qmlPropertyValueInterceptorCast(qMetaTypeId()), -1); + QCOMPARE(QmlMetaType::qmlPropertyValueInterceptorCast(qMetaTypeId()), -1); + + int cast = QmlMetaType::qmlPropertyValueInterceptorCast(qMetaTypeId()); + QVERIFY(cast != -1); + QVERIFY(cast != 0); + + ValueInterceptorTestType t; + QVERIFY(reinterpret_cast((QObject *)&t) != reinterpret_cast((QmlPropertyValueInterceptor *)&t)); + + QmlPropertyValueInterceptor *interceptor = reinterpret_cast(reinterpret_cast((QObject *)&t) + cast); + QCOMPARE(interceptor, &t); +} + +void tst_qmlmetatype::isList() +{ + QCOMPARE(QmlMetaType::isList(QVariant()), false); + QCOMPARE(QmlMetaType::isList(QVariant::Invalid), false); + QCOMPARE(QmlMetaType::isList(QVariant::Int), false); + QCOMPARE(QmlMetaType::isList(QVariant(10)), false); + + QList list; + QmlConcreteList qmllist; + + QCOMPARE(QmlMetaType::isList(qMetaTypeId*>()), true); + QCOMPARE(QmlMetaType::isList(QVariant::fromValue(&list)), true); + QCOMPARE(QmlMetaType::isList(qMetaTypeId*>()), false); + QCOMPARE(QmlMetaType::isList(QVariant::fromValue((QmlList*)&qmllist)), false); +} + +void tst_qmlmetatype::isQmlList() +{ + QCOMPARE(QmlMetaType::isQmlList(QVariant::Invalid), false); + QCOMPARE(QmlMetaType::isQmlList(QVariant::Int), false); + + QCOMPARE(QmlMetaType::isQmlList(qMetaTypeId*>()), false); + QCOMPARE(QmlMetaType::isQmlList(qMetaTypeId*>()), true); +} + +void tst_qmlmetatype::listCount() +{ + QCOMPARE(QmlMetaType::listCount(QVariant()), 0); + QCOMPARE(QmlMetaType::listCount(QVariant(10)), 0); + + QList list; + QVariant listVar = QVariant::fromValue(&list); + QmlConcreteList qmllist; + QVariant qmllistVar = QVariant::fromValue((QmlList*)&qmllist); + + QCOMPARE(QmlMetaType::listCount(listVar), 0); + QCOMPARE(QmlMetaType::listCount(qmllistVar), 0); + + list.append(0); list.append(0); list.append(0); + qmllist.append(0); qmllist.append(0); qmllist.append(0); + + QCOMPARE(QmlMetaType::listCount(listVar), 3); + QCOMPARE(QmlMetaType::listCount(qmllistVar), 0); +} + +void tst_qmlmetatype::listAt() +{ + QCOMPARE(QmlMetaType::listAt(QVariant(), 0), QVariant()); + QCOMPARE(QmlMetaType::listAt(QVariant(10), 0), QVariant()); + QCOMPARE(QmlMetaType::listAt(QVariant(), 10), QVariant()); + QCOMPARE(QmlMetaType::listAt(QVariant(10), 10), QVariant()); + QCOMPARE(QmlMetaType::listAt(QVariant(), -10), QVariant()); + QCOMPARE(QmlMetaType::listAt(QVariant(10), -10), QVariant()); + + QList list; + QVariant listVar = QVariant::fromValue(&list); + QmlConcreteList qmllist; + QVariant qmllistVar = QVariant::fromValue((QmlList*)&qmllist); + + QCOMPARE(QmlMetaType::listAt(listVar, 0), QVariant()); + QCOMPARE(QmlMetaType::listAt(listVar, 2), QVariant()); + QCOMPARE(QmlMetaType::listAt(listVar, -1), QVariant()); + + QCOMPARE(QmlMetaType::listAt(qmllistVar, 0), QVariant()); + QCOMPARE(QmlMetaType::listAt(qmllistVar, 2), QVariant()); + QCOMPARE(QmlMetaType::listAt(qmllistVar, -1), QVariant()); + + TestType ttype; + QVariant ttypeVar = QVariant::fromValue(&ttype); + QVariant nullttypeVar = QVariant::fromValue((TestType *)0); + + list.append(0); list.append(&ttype); list.append(0); + qmllist.append(0); qmllist.append(&ttype); qmllist.append(0); + + QCOMPARE(QmlMetaType::listAt(listVar, 0), nullttypeVar); + QCOMPARE(QmlMetaType::listAt(listVar, 1), ttypeVar); + QCOMPARE(QmlMetaType::listAt(listVar, -1), QVariant()); + + QCOMPARE(QmlMetaType::listAt(qmllistVar, 0), QVariant()); + QCOMPARE(QmlMetaType::listAt(qmllistVar, 2), QVariant()); + QCOMPARE(QmlMetaType::listAt(qmllistVar, -1), QVariant()); +} + +void tst_qmlmetatype::defaultObject() +{ + QVERIFY(QmlMetaType::defaultProperty(&QObject::staticMetaObject).name() == 0); + QVERIFY(QmlMetaType::defaultProperty(&ParserStatusTestType::staticMetaObject).name() == 0); + QCOMPARE(QString(QmlMetaType::defaultProperty(&TestType::staticMetaObject).name()), QString("foo")); + + QObject o; + TestType t; + ParserStatusTestType p; + + QVERIFY(QmlMetaType::defaultProperty((QObject *)0).name() == 0); + QVERIFY(QmlMetaType::defaultProperty(&o).name() == 0); + QVERIFY(QmlMetaType::defaultProperty(&p).name() == 0); + QCOMPARE(QString(QmlMetaType::defaultProperty(&t).name()), QString("foo")); } QTEST_MAIN(tst_qmlmetatype) -- cgit v0.12 From 39b3fcba96d6f9d7d7b96d3c875ef569a3083898 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 5 Nov 2009 20:16:25 +1000 Subject: QmlError test --- tests/auto/declarative/declarative.pro | 1 + tests/auto/declarative/qmlerror/qmlerror.pro | 6 + tests/auto/declarative/qmlerror/test.txt | 3 + tests/auto/declarative/qmlerror/tst_qmlerror.cpp | 242 +++++++++++++++++++++++ 4 files changed, 252 insertions(+) create mode 100644 tests/auto/declarative/qmlerror/qmlerror.pro create mode 100644 tests/auto/declarative/qmlerror/test.txt create mode 100644 tests/auto/declarative/qmlerror/tst_qmlerror.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 02d5a55..716d278 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -19,6 +19,7 @@ SUBDIRS += \ qmlcontext \ # Cover qmldom \ # Cover qmlecmascript \ # Cover + qmlerror \ # Cover qmlfontloader \ # Cover qmlgraphicsborderimage \ # Cover qmlgraphicsparticles \ # Cover diff --git a/tests/auto/declarative/qmlerror/qmlerror.pro b/tests/auto/declarative/qmlerror/qmlerror.pro new file mode 100644 index 0000000..fa9b79e --- /dev/null +++ b/tests/auto/declarative/qmlerror/qmlerror.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmlerror.cpp +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlerror/test.txt b/tests/auto/declarative/qmlerror/test.txt new file mode 100644 index 0000000..cdafd9e --- /dev/null +++ b/tests/auto/declarative/qmlerror/test.txt @@ -0,0 +1,3 @@ +Line Content +Line2 Content +Line3 Content diff --git a/tests/auto/declarative/qmlerror/tst_qmlerror.cpp b/tests/auto/declarative/qmlerror/tst_qmlerror.cpp new file mode 100644 index 0000000..70fef1d --- /dev/null +++ b/tests/auto/declarative/qmlerror/tst_qmlerror.cpp @@ -0,0 +1,242 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +class tst_qmlerror : public QObject +{ + Q_OBJECT +private slots: + void url(); + void description(); + void line(); + void column(); + void toString(); + + void copy(); + void debug(); +}; + +void tst_qmlerror::url() +{ + QmlError error; + + QCOMPARE(error.url(), QUrl()); + + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + + QCOMPARE(error.url(), QUrl("http://www.nokia.com/main.qml")); + + QmlError error2 = error; + + QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml")); + + error.setUrl(QUrl("http://qt.nokia.com/main.qml")); + + QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml")); + QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml")); +} + +void tst_qmlerror::description() +{ + QmlError error; + + QCOMPARE(error.description(), QString()); + + error.setDescription("An Error"); + + QCOMPARE(error.description(), QString("An Error")); + + QmlError error2 = error; + + QCOMPARE(error2.description(), QString("An Error")); + + error.setDescription("Another Error"); + + QCOMPARE(error.description(), QString("Another Error")); + QCOMPARE(error2.description(), QString("An Error")); +} + +void tst_qmlerror::line() +{ + QmlError error; + + QCOMPARE(error.line(), -1); + + error.setLine(102); + + QCOMPARE(error.line(), 102); + + QmlError error2 = error; + + QCOMPARE(error2.line(), 102); + + error.setLine(4); + + QCOMPARE(error.line(), 4); + QCOMPARE(error2.line(), 102); +} + +void tst_qmlerror::column() +{ + QmlError error; + + QCOMPARE(error.column(), -1); + + error.setColumn(16); + + QCOMPARE(error.column(), 16); + + QmlError error2 = error; + + QCOMPARE(error2.column(), 16); + + error.setColumn(3); + + QCOMPARE(error.column(), 3); + QCOMPARE(error2.column(), 16); +} + +void tst_qmlerror::toString() +{ + { + QmlError error; + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + error.setDescription("An Error"); + error.setLine(92); + error.setColumn(13); + + QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92:13: An Error")); + } + + { + QmlError error; + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + error.setDescription("An Error"); + error.setLine(92); + + QCOMPARE(error.toString(), QString("http://www.nokia.com/main.qml:92: An Error")); + } +} + +void tst_qmlerror::copy() +{ + QmlError error; + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + error.setDescription("An Error"); + error.setLine(92); + error.setColumn(13); + + QmlError error2(error); + QmlError error3; + error3 = error; + + error.setUrl(QUrl("http://qt.nokia.com/main.qml")); + error.setDescription("Another Error"); + error.setLine(2); + error.setColumn(33); + + QCOMPARE(error.url(), QUrl("http://qt.nokia.com/main.qml")); + QCOMPARE(error.description(), QString("Another Error")); + QCOMPARE(error.line(), 2); + QCOMPARE(error.column(), 33); + + QCOMPARE(error2.url(), QUrl("http://www.nokia.com/main.qml")); + QCOMPARE(error2.description(), QString("An Error")); + QCOMPARE(error2.line(), 92); + QCOMPARE(error2.column(), 13); + + QCOMPARE(error3.url(), QUrl("http://www.nokia.com/main.qml")); + QCOMPARE(error3.description(), QString("An Error")); + QCOMPARE(error3.line(), 92); + QCOMPARE(error3.column(), 13); + +} + +void tst_qmlerror::debug() +{ + { + QmlError error; + error.setUrl(QUrl("http://www.nokia.com/main.qml")); + error.setDescription("An Error"); + error.setLine(92); + error.setColumn(13); + + QTest::ignoreMessage(QtWarningMsg, "http://www.nokia.com/main.qml:92:13: An Error "); + qWarning() << error; + } + + { + QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("test.txt"))); + QmlError error; + error.setUrl(url); + error.setDescription("An Error"); + error.setLine(2); + error.setColumn(5); + + QString out = url.toString() + ":2:5: An Error \n Line2 Content \n ^ "; + QTest::ignoreMessage(QtWarningMsg, qPrintable(out)); + + qWarning() << error; + } + + { + QUrl url(QUrl::fromLocalFile(QString(SRCDIR) + "/").resolved(QUrl("foo.txt"))); + QmlError error; + error.setUrl(url); + error.setDescription("An Error"); + error.setLine(2); + error.setColumn(5); + + QString out = url.toString() + ":2:5: An Error "; + QTest::ignoreMessage(QtWarningMsg, qPrintable(out)); + + qWarning() << error; + } +} + + + +QTEST_MAIN(tst_qmlerror) + +#include "tst_qmlerror.moc" -- cgit v0.12 From 4328004a78fedc33c09e352c2e7f7f9958952a16 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Thu, 5 Nov 2009 14:09:16 +0100 Subject: qdoc3: Fixed a linking problem for qml methods. Note the Invalid Syntax errors for some uses of \qmlmethod and \qmlsignal. A syntactically correct signature is now required as the argument. --- tools/qdoc3/cppcodemarker.cpp | 8 ++-- tools/qdoc3/cppcodeparser.cpp | 70 ++++++++++++++++++++++++-------- tools/qdoc3/cppcodeparser.h | 14 ++++++- tools/qdoc3/htmlgenerator.cpp | 4 +- tools/qdoc3/node.cpp | 92 ++++++++++++++++++++++++++++++------------- tools/qdoc3/node.h | 39 +++++------------- tools/qdoc3/tree.cpp | 13 +++--- 7 files changed, 152 insertions(+), 88 deletions(-) diff --git a/tools/qdoc3/cppcodemarker.cpp b/tools/qdoc3/cppcodemarker.cpp index c07be8b..f3188bd 100644 --- a/tools/qdoc3/cppcodemarker.cpp +++ b/tools/qdoc3/cppcodemarker.cpp @@ -1154,14 +1154,14 @@ QList
CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, } } else if ((*c)->type() == Node::QmlSignal) { - const QmlSignalNode* sn = static_cast(*c); + const FunctionNode* sn = static_cast(*c); if (sn->isAttached()) insert(qmlattachedsignals,*c,style,Okay); else insert(qmlsignals,*c,style,Okay); } else if ((*c)->type() == Node::QmlMethod) { - const QmlMethodNode* mn = static_cast(*c); + const FunctionNode* mn = static_cast(*c); if (mn->isAttached()) insert(qmlattachedmethods,*c,style,Okay); else @@ -1193,14 +1193,14 @@ QList
CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, insert(qmlproperties,*c,style,Okay); } else if ((*c)->type() == Node::QmlSignal) { - const QmlSignalNode* sn = static_cast(*c); + const FunctionNode* sn = static_cast(*c); if (sn->isAttached()) insert(qmlattachedsignals,*c,style,Okay); else insert(qmlsignals,*c,style,Okay); } else if ((*c)->type() == Node::QmlMethod) { - const QmlMethodNode* mn = static_cast(*c); + const FunctionNode* mn = static_cast(*c); if (mn->isAttached()) insert(qmlattachedmethods,*c,style,Okay); else diff --git a/tools/qdoc3/cppcodeparser.cpp b/tools/qdoc3/cppcodeparser.cpp index cabbe38..90d83ca 100644 --- a/tools/qdoc3/cppcodeparser.cpp +++ b/tools/qdoc3/cppcodeparser.cpp @@ -693,13 +693,13 @@ Node *CppCodeParser::processTopicCommand(const Doc& doc, if (n && n->subType() == Node::QmlClass) { qmlClass = static_cast(n); if (command == COMMAND_QMLSIGNAL) - return new QmlSignalNode(qmlClass,name,false); + return makeFunctionNode(doc,arg,qmlClass,Node::QmlSignal,false,COMMAND_QMLSIGNAL); else if (command == COMMAND_QMLATTACHEDSIGNAL) - return new QmlSignalNode(qmlClass,name,true); + return makeFunctionNode(doc,arg,qmlClass,Node::QmlSignal,true,COMMAND_QMLATTACHEDSIGNAL); else if (command == COMMAND_QMLMETHOD) - return new QmlMethodNode(qmlClass,name,false); + return makeFunctionNode(doc,arg,qmlClass,Node::QmlMethod,false,COMMAND_QMLMETHOD); else if (command == COMMAND_QMLATTACHEDMETHOD) - return new QmlMethodNode(qmlClass,name,true); + return makeFunctionNode(doc,arg,qmlClass,Node::QmlMethod,true,COMMAND_QMLATTACHEDMETHOD); else return 0; // never get here. } @@ -1265,7 +1265,9 @@ bool CppCodeParser::matchParameter(FunctionNode *func) bool CppCodeParser::matchFunctionDecl(InnerNode *parent, QStringList *parentPathPtr, FunctionNode **funcPtr, - const QString &templateStuff) + const QString &templateStuff, + Node::Type type, + bool attached) { CodeChunk returnType; QStringList parentPath; @@ -1295,8 +1297,9 @@ bool CppCodeParser::matchFunctionDecl(InnerNode *parent, if (tokenizer->parsingFnOrMacro() && (match(Tok_Q_DECLARE_FLAGS) || match(Tok_Q_PROPERTY))) returnType = CodeChunk(previousLexeme()); - else + else { return false; + } } if (returnType.toString() == "QBool") @@ -1326,8 +1329,9 @@ bool CppCodeParser::matchFunctionDecl(InnerNode *parent, readToken(); } } - if (tok != Tok_LeftParen) + if (tok != Tok_LeftParen) { return false; + } } else if (tok == Tok_LeftParen) { // constructor or destructor @@ -1373,8 +1377,9 @@ bool CppCodeParser::matchFunctionDecl(InnerNode *parent, returnType.append(lexeme()); readToken(); } - if (tok != Tok_Semicolon) + if (tok != Tok_Semicolon) { return false; + } } else if (tok == Tok_Colon) { returnType.appendHotspot(); @@ -1383,8 +1388,9 @@ bool CppCodeParser::matchFunctionDecl(InnerNode *parent, returnType.append(lexeme()); readToken(); } - if (tok != Tok_Semicolon) + if (tok != Tok_Semicolon) { return false; + } } VariableNode *var = new VariableNode(parent, name); @@ -1397,12 +1403,13 @@ bool CppCodeParser::matchFunctionDecl(InnerNode *parent, var->setStatic(sta); return false; } - if (tok != Tok_LeftParen) + if (tok != Tok_LeftParen) { return false; + } } readToken(); - FunctionNode *func = new FunctionNode(parent, name); + FunctionNode *func = new FunctionNode(type, parent, name, attached); func->setAccess(access); func->setLocation(location()); func->setReturnType(returnType.toString()); @@ -1423,12 +1430,14 @@ bool CppCodeParser::matchFunctionDecl(InnerNode *parent, if (tok != Tok_RightParen) { do { - if (!matchParameter(func)) + if (!matchParameter(func)) { return false; + } } while (match(Tok_Comma)); } - if (!match(Tok_RightParen)) + if (!match(Tok_RightParen)) { return false; + } func->setConst(match(Tok_const)); @@ -1444,8 +1453,9 @@ bool CppCodeParser::matchFunctionDecl(InnerNode *parent, if (!match(Tok_Semicolon) && tok != Tok_Eoi) { int braceDepth0 = tokenizer->braceDepth(); - if (!match(Tok_LeftBrace)) + if (!match(Tok_LeftBrace)) { return false; + } while (tokenizer->braceDepth() >= braceDepth0 && tok != Tok_Eoi) readToken(); match(Tok_RightBrace); @@ -2092,7 +2102,9 @@ bool CppCodeParser::matchDocsAndStuff() bool CppCodeParser::makeFunctionNode(const QString& synopsis, QStringList *parentPathPtr, FunctionNode **funcPtr, - InnerNode *root) + InnerNode *root, + Node::Type type, + bool attached) { Tokenizer *outerTokenizer = tokenizer; int outerTok = tok; @@ -2104,15 +2116,39 @@ bool CppCodeParser::makeFunctionNode(const QString& synopsis, tokenizer = &stringTokenizer; readToken(); - bool ok = matchFunctionDecl(root, parentPathPtr, funcPtr); + bool ok = matchFunctionDecl(root, parentPathPtr, funcPtr, QString(), type, attached); // potential memory leak with funcPtr tokenizer = outerTokenizer; tok = outerTok; - return ok; } +/*! + Create a new FunctionNode for a QML method or signal, as + specified by \a type, as a child of \a parent. \a sig is + the complete signature, and if \a attached is true, the + method or signal is "attached". \a qdoctag is the text of + the \a type. + */ +FunctionNode* CppCodeParser::makeFunctionNode(const Doc& doc, + const QString& sig, + InnerNode* parent, + Node::Type type, + bool attached, + QString qdoctag) +{ + QStringList pp; + FunctionNode* fn = 0; + if (!makeFunctionNode(sig,&pp,&fn,parent,type,attached) && + !makeFunctionNode("void "+sig,&pp,&fn,parent,type,attached)) { + doc.location().warning(tr("Invalid syntax in '\\%1'").arg(qdoctag)); + } + if (fn) + return fn; + return 0; +} + void CppCodeParser::parseQiteratorDotH(const Location &location, const QString &filePath) { diff --git a/tools/qdoc3/cppcodeparser.h b/tools/qdoc3/cppcodeparser.h index 233ac09..87c1b69 100644 --- a/tools/qdoc3/cppcodeparser.h +++ b/tools/qdoc3/cppcodeparser.h @@ -127,7 +127,9 @@ class CppCodeParser : public CodeParser bool matchFunctionDecl(InnerNode *parent, QStringList *parentPathPtr = 0, FunctionNode **funcPtr = 0, - const QString &templateStuff = QString()); + const QString &templateStuff = QString(), + Node::Type type = Node::Function, + bool attached = false); bool matchBaseSpecifier(ClassNode *classe, bool isClass); bool matchBaseList(ClassNode *classe, bool isClass); bool matchClassDecl(InnerNode *parent, @@ -143,7 +145,15 @@ class CppCodeParser : public CodeParser bool makeFunctionNode(const QString &synopsis, QStringList *parentPathPtr, FunctionNode **funcPtr, - InnerNode *root = 0); + InnerNode *root = 0, + Node::Type type = Node::Function, + bool attached = false); + FunctionNode* makeFunctionNode(const Doc& doc, + const QString& sig, + InnerNode* parent, + Node::Type type, + bool attached, + QString qdoctag); void parseQiteratorDotH(const Location &location, const QString &filePath); void instantiateIteratorMacro(const QString &container, const QString &includeFile, diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index afd1e74..ae47fc0 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -4219,7 +4219,7 @@ void HtmlGenerator::generateDetailedQmlMember(const Node *node, out() << ""; } else if (node->type() == Node::QmlSignal) { - const QmlSignalNode* qsn = static_cast(node); + const FunctionNode* qsn = static_cast(node); out() << "
"; out() << ""; out() << "
"; @@ -4230,7 +4230,7 @@ void HtmlGenerator::generateDetailedQmlMember(const Node *node, out() << ""; } else if (node->type() == Node::QmlMethod) { - const QmlMethodNode* qmn = static_cast(node); + const FunctionNode* qmn = static_cast(node); out() << "
"; out() << ""; out() << "
"; diff --git a/tools/qdoc3/node.cpp b/tools/qdoc3/node.cpp index ecb4a44..1217042 100644 --- a/tools/qdoc3/node.cpp +++ b/tools/qdoc3/node.cpp @@ -218,6 +218,7 @@ Node *InnerNode::findNode(const QString& name, Type type) } /*! + Find the function node in this node for the function named \a name. */ FunctionNode *InnerNode::findFunctionNode(const QString& name) { @@ -225,6 +226,7 @@ FunctionNode *InnerNode::findFunctionNode(const QString& name) } /*! + Find the function node in this node that has the same name as \a clone. */ FunctionNode *InnerNode::findFunctionNode(const FunctionNode *clone) { @@ -248,6 +250,34 @@ FunctionNode *InnerNode::findFunctionNode(const FunctionNode *clone) } /*! + Returns the list of keys from the primary function map. + */ +QStringList InnerNode::primaryKeys() +{ + QStringList t; + QMap::iterator i = primaryFunctionMap.begin(); + while (i != primaryFunctionMap.end()) { + t.append(i.key()); + ++i; + } + return t; +} + +/*! + Returns the list of keys from the secondary function map. + */ +QStringList InnerNode::secondaryKeys() +{ + QStringList t; + QMap::iterator i = secondaryFunctionMap.begin(); + while (i != secondaryFunctionMap.end()) { + t.append(i.key()); + ++i; + } + return t; +} + +/*! */ void InnerNode::setOverload(const FunctionNode *func, bool overlode) { @@ -392,6 +422,7 @@ const Node *InnerNode::findNode(const QString& name, Type type) const } /*! + Find the function node in this node that has the given \a name. */ const FunctionNode *InnerNode::findFunctionNode(const QString& name) const { @@ -400,9 +431,9 @@ const FunctionNode *InnerNode::findFunctionNode(const QString& name) const } /*! + Find the function node in this node that has the same name as \a clone. */ -const FunctionNode *InnerNode::findFunctionNode( - const FunctionNode *clone) const +const FunctionNode *InnerNode::findFunctionNode(const FunctionNode *clone) const { InnerNode *that = (InnerNode *) this; return that->findFunctionNode(clone); @@ -520,7 +551,7 @@ bool InnerNode::isSameSignature(const FunctionNode *f1, const FunctionNode *f2) void InnerNode::addChild(Node *child) { children.append(child); - if (child->type() == Function) { + if ((child->type() == Function) || (child->type() == QmlMethod)) { FunctionNode *func = (FunctionNode *) child; if (!primaryFunctionMap.contains(func->name())) { primaryFunctionMap.insert(func->name(), func); @@ -896,11 +927,40 @@ QString Parameter::reconstruct(bool value) const */ /*! + Construct a function node for a C++ function. It's parent + is \a parent, and it's name is \a name. */ FunctionNode::FunctionNode(InnerNode *parent, const QString& name) - : LeafNode(Function, parent, name), met(Plain), vir(NonVirtual), - con(false), sta(false), ove(false), rf(0), ap(0) + : LeafNode(Function, parent, name), + met(Plain), + vir(NonVirtual), + con(false), + sta(false), + ove(false), + att(false), + rf(0), + ap(0) +{ + // nothing. +} + +/*! + Construct a function node for a QML method or signal, specified + by \a type. It's parent is \a parent, and it's name is \a name. + If \a attached is true, it is an attached method or signal. + */ +FunctionNode::FunctionNode(Type type, InnerNode *parent, const QString& name, bool attached) + : LeafNode(type, parent, name), + met(Plain), + vir(NonVirtual), + con(false), + sta(false), + ove(false), + att(attached), + rf(0), + ap(0) { + // nothing. } /*! @@ -1208,28 +1268,6 @@ bool QmlPropertyNode::fromTrool(Trool troolean, bool defaultValue) return defaultValue; } } - -/*! - Constructor for the QML signal node. - */ -QmlSignalNode::QmlSignalNode(QmlClassNode *parent, - const QString& name, - bool attached) - : LeafNode(QmlSignal, parent, name), att(attached) -{ - // nothing. -} - -/*! - Constructor for the QML method node. - */ -QmlMethodNode::QmlMethodNode(QmlClassNode *parent, - const QString& name, - bool attached) - : LeafNode(QmlMethod, parent, name), att(attached) -{ - // nothing. -} #endif QT_END_NAMESPACE diff --git a/tools/qdoc3/node.h b/tools/qdoc3/node.h index 5712879..3f5be6c 100644 --- a/tools/qdoc3/node.h +++ b/tools/qdoc3/node.h @@ -151,6 +151,7 @@ class Node virtual bool isInnerNode() const = 0; virtual bool isReimp() const { return false; } + virtual bool isFunction() const { return false; } Type type() const { return typ; } virtual SubType subType() const { return NoSubType; } InnerNode *parent() const { return par; } @@ -239,6 +240,9 @@ class InnerNode : public Node NodeList overloads(const QString &funcName) const; const QStringList& includes() const { return inc; } + QStringList primaryKeys(); + QStringList secondaryKeys(); + protected: InnerNode(Type type, InnerNode *parent, const QString& name); @@ -421,36 +425,6 @@ class QmlPropertyNode : public LeafNode Trool wri; bool att; }; - -class QmlSignalNode : public LeafNode -{ - public: - QmlSignalNode(QmlClassNode* parent, - const QString& name, - bool attached); - virtual ~QmlSignalNode() { } - - const QString& element() const { return parent()->name(); } - bool isAttached() const { return att; } - - private: - bool att; -}; - -class QmlMethodNode : public LeafNode -{ - public: - QmlMethodNode(QmlClassNode* parent, - const QString& name, - bool attached); - virtual ~QmlMethodNode() { } - - const QString& element() const { return parent()->name(); } - bool isAttached() const { return att; } - - private: - bool att; -}; #endif class EnumItem @@ -564,6 +538,7 @@ class FunctionNode : public LeafNode enum Virtualness { NonVirtual, ImpureVirtual, PureVirtual }; FunctionNode(InnerNode *parent, const QString &name); + FunctionNode(Type type, InnerNode *parent, const QString &name, bool attached); virtual ~FunctionNode() { } void setReturnType(const QString& returnType) { rt = returnType; } @@ -589,6 +564,7 @@ class FunctionNode : public LeafNode bool isStatic() const { return sta; } bool isOverload() const { return ove; } bool isReimp() const { return reimp; } + bool isFunction() const { return true; } int overloadNumber() const; int numOverloads() const; const QList& parameters() const { return params; } @@ -600,6 +576,8 @@ class FunctionNode : public LeafNode QStringList reconstructParams(bool values = false) const; QString signature(bool values = false) const; + const QString& element() const { return parent()->name(); } + bool isAttached() const { return att; } private: void setAssociatedProperty(PropertyNode *property); @@ -620,6 +598,7 @@ class FunctionNode : public LeafNode bool sta : 1; bool ove : 1; bool reimp: 1; + bool att: 1; QList params; const FunctionNode *rf; const PropertyNode *ap; diff --git a/tools/qdoc3/tree.cpp b/tools/qdoc3/tree.cpp index bcd9709..4d401de 100644 --- a/tools/qdoc3/tree.cpp +++ b/tools/qdoc3/tree.cpp @@ -225,6 +225,7 @@ const FunctionNode *Tree::findFunctionNode(const QStringList &path, { if (!relative) relative = root(); + do { const Node *node = relative; int i; @@ -244,8 +245,7 @@ const FunctionNode *Tree::findFunctionNode(const QStringList &path, NodeList baseClasses = allBaseClasses(static_cast(node)); foreach (const Node *baseClass, baseClasses) { if (i == path.size() - 1) - next = static_cast(baseClass)-> - findFunctionNode(path.at(i)); + next = static_cast(baseClass)->findFunctionNode(path.at(i)); else next = static_cast(baseClass)->findNode(path.at(i)); @@ -256,11 +256,10 @@ const FunctionNode *Tree::findFunctionNode(const QStringList &path, node = next; } - if (node && i == path.size() && node->type() == Node::Function) { + if (node && i == path.size() && node->isFunction()) { // CppCodeParser::processOtherMetaCommand ensures that reimplemented // functions are private. const FunctionNode *func = static_cast(node); - while (func->access() == Node::Private) { const FunctionNode *from = func->reimplementedFrom(); if (from != 0) { @@ -268,7 +267,8 @@ const FunctionNode *Tree::findFunctionNode(const QStringList &path, return from; else func = from; - } else + } + else break; } return func; @@ -303,7 +303,8 @@ const FunctionNode *Tree::findFunctionNode(const QStringList &parentPath, const Node *parent = findNode(parentPath, relative, findFlags); if (parent == 0 || !parent->isInnerNode()) { return 0; - } else { + } + else { return ((InnerNode *)parent)->findFunctionNode(clone); } } -- cgit v0.12 From 96f3abd4df881789bd2677100a2417c96fd2edb4 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 6 Nov 2009 08:36:53 +1000 Subject: fix javascript errors in samegame tutorials --- .../tutorials/samegame/samegame2/samegame.js | 6 +- .../tutorials/samegame/samegame3/samegame.js | 10 +- .../samegame/samegame4/content/samegame.js | 103 ++++++++++++++------- .../tutorials/samegame/samegame4/samegame.qml | 40 ++++---- 4 files changed, 102 insertions(+), 57 deletions(-) diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js index 2bf68b5..2c02c61 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js @@ -22,8 +22,8 @@ function initBoard() //Initialize Board board = new Array(maxIndex); - for(xIdx=0; xIdx=0; yIdx--){ if(board[index(xIdx,yIdx)] == null){ diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js index ce9c169..58de55f 100755 --- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js @@ -1,14 +1,14 @@ /* This script file handles the game logic */ //Note that X/Y referred to here are in game coordinates -var maxX = 10;//Nums are for tileSize 40 +var maxX = 10;//Nums are for gameCanvas.tileSize 40 var maxY = 15; -var tileSize = 40; var maxIndex = maxX*maxY; var board = new Array(maxIndex); var tileSrc = "content/BoomBlock.qml"; var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php"; +var scoresURL = ""; var timer; -var component; +var component = createComponent(tileSrc); //Index function used instead of a 2D array function index(xIdx,yIdx) { @@ -22,33 +22,41 @@ function timeStr(msecs) { return ret; } +function getTileSize() +{ + return tileSize; +} + function initBoard() { - for(i = 0; i= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) return; if(board[index(xIdx, yIdx)] == null) @@ -103,15 +111,15 @@ function floodFill(xIdx,yIdx,type) function shuffleDown() { //Fall down - for(xIdx=0; xIdx=0; yIdx--){ + for(var xIdx=0; xIdx=0; yIdx--){ if(board[index(xIdx,yIdx)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - obj = board[index(xIdx,yIdx)]; - obj.targetY += fallDist * tileSize; + var obj = board[index(xIdx,yIdx)]; + obj.targetY += fallDist * gameCanvas.tileSize; board[index(xIdx,yIdx+fallDist)] = obj; board[index(xIdx,yIdx)] = null; } @@ -129,7 +137,7 @@ function shuffleDown() obj = board[index(xIdx,yIdx)]; if(obj == null) continue; - obj.targetX -= fallDist * tileSize; + obj.targetX -= fallDist * gameCanvas.tileSize; board[index(xIdx-fallDist,yIdx)] = obj; board[index(xIdx,yIdx)] = null; } @@ -141,8 +149,8 @@ function shuffleDown() function victoryCheck() { //awards bonuses for no tiles left - deservesBonus = true; - for(xIdx=maxX-1; xIdx>=0; xIdx--) + var deservesBonus = true; + for(var xIdx=maxX-1; xIdx>=0; xIdx--) if(board[index(xIdx, maxY - 1)] != null) deservesBonus = false; if(deservesBonus) @@ -150,10 +158,8 @@ function victoryCheck() //Checks for game over if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){ timer = new Date() - timer; - if(scoresURL != "") - scoreName.show("You've won! Please enter your name: "); - else - dialog.show("Game Over. Your score is " + gameCanvas.score); + scoreName.show("You won! Please enter your name: "); + //dialog.show("Game Over. Your score is " + gameCanvas.score); } } @@ -164,7 +170,7 @@ function floodMoveCheck(xIdx, yIdx, type) return false; if(board[index(xIdx, yIdx)] == null) return false; - myType = board[index(xIdx, yIdx)].type; + var myType = board[index(xIdx, yIdx)].type; if(type == myType) return true; return floodMoveCheck(xIdx + 1, yIdx, myType) || @@ -172,15 +178,12 @@ function floodMoveCheck(xIdx, yIdx, type) } function createBlock(xIdx,yIdx){ - if(component==null) - component = createComponent(tileSrc); - // Note that we don't wait for the component to become ready. This will // only work if the block QML is a local file. Otherwise the component will // not be ready immediately. There is a statusChanged signal on the // component you could use if you want to wait to load remote files. if(component.isReady){ - dynamicObject = component.createObject(); + var dynamicObject = component.createObject(); if(dynamicObject == null){ print("error creating block"); print(component.errorsString()); @@ -188,11 +191,11 @@ function createBlock(xIdx,yIdx){ } dynamicObject.type = Math.floor(Math.random() * 3); dynamicObject.parent = gameCanvas; - dynamicObject.x = xIdx*tileSize; - dynamicObject.targetX = xIdx*tileSize; - dynamicObject.targetY = yIdx*tileSize; - dynamicObject.width = tileSize; - dynamicObject.height = tileSize; + dynamicObject.x = xIdx*gameCanvas.tileSize; + dynamicObject.targetX = xIdx*gameCanvas.tileSize; + dynamicObject.targetY = yIdx*gameCanvas.tileSize; + dynamicObject.width = gameCanvas.tileSize; + dynamicObject.height = gameCanvas.tileSize; dynamicObject.spawned = true; board[index(xIdx,yIdx)] = dynamicObject; }else{//isError or isLoading @@ -203,6 +206,42 @@ function createBlock(xIdx,yIdx){ return true; } +function saveHighScore(name) { + if(scoresURL!="") + sendHighScore(name); + //OfflineStorage + var db = openDatabase("SameGameScores", "1.0", "Local SameGame High Scores",100); + var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)"; + var data = [name, gameCanvas.score, maxX+"x"+maxY ,Math.floor(timer/1000)]; + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)',[]); + tx.executeSql(dataStr, data); + + tx.executeSql('SELECT * FROM Scores WHERE gridSize = "12x17" ORDER BY score desc LIMIT 10',[], + function(tx, rs) { + var r = "\nHIGH SCORES for a standard sized grid\n\n" + for(var i = 0; i < rs.rows.length; i++){ + r += (i+1)+". " + rs.rows.item(i).name +' got ' + + rs.rows.item(i).score + ' points in ' + + rs.rows.item(i).time + ' seconds.\n'; + } + dialog.show(r); + }, + function(tx, error) { + print("ERROR:", error.message); + } + ); + }, + function() { + print("ERROR in transaction"); + }, + function() { + //print("Transaction successful"); + } + ); +} + //![1] function sendHighScore(name) { var postman = new XMLHttpRequest() diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml index 89dc945..19b929f 100644 --- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml @@ -2,15 +2,13 @@ import Qt 4.6 import "content" Rectangle { - id: Screen + id: screen width: 490; height: 720 - Script { source: "content/samegame.js" } - SystemPalette { id: activePalette } Item { - width: parent.width; anchors.top: parent.top; anchors.bottom: ToolBar.top + width: parent.width; anchors.top: parent.top; anchors.bottom: toolBar.top Image { id: background @@ -21,10 +19,13 @@ Rectangle { Item { id: gameCanvas property int score: 0 + property int tileSize: 40 + + Script { source: "content/samegame.js" } z: 20; anchors.centerIn: parent - width: parent.width - (parent.width % tileSize); - height: parent.height - (parent.height % tileSize); + width: parent.width - (parent.width % getTileSize()); + height: parent.height - (parent.height % getTileSize()); MouseRegion { id: gameMR @@ -34,26 +35,31 @@ Rectangle { } Dialog { id: dialog; anchors.centerIn: parent; z: 21 } - Dialog { - id: scoreName; anchors.centerIn: parent; z: 22; + Dialog { + id: scoreName; anchors.centerIn: parent; z: 22; + Text { + id: spacer + opacity: 0 + text: " You won! Please enter your name:" + } TextInput { - id: Editor - onAccepted: { - if(scoreName.opacity==1&&Editor.text!="") - sendHighScore(Editor.text); - scoreName.forceClose(); + id: editor + onAccepted: { + if(scoreName.opacity==1&&editor.text!="") + saveHighScore(editor.text); + scoreName.forceClose(); } anchors.verticalCenter: parent.verticalCenter width: 72; focus: true - anchors.right: scoreName.right + anchors.left: spacer.right } } Rectangle { - id: ToolBar + id: toolBar color: activePalette.window height: 32; width: parent.width - anchors.bottom: Screen.bottom + anchors.bottom: screen.bottom Button { id: btnA; text: "New Game"; onClicked: {initBoard();} @@ -62,7 +68,7 @@ Rectangle { } Text { - id: Score + id: score text: "Score: " + gameCanvas.score; font.bold: true anchors.right: parent.right; anchors.rightMargin: 3 anchors.verticalCenter: parent.verticalCenter -- cgit v0.12