From 29af49fc979b888f5b5ea20616f3f6da48b009b0 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 4 Aug 2011 10:30:46 +1000 Subject: Add enabled property to Transition. Task-number: QTBUG-14488 Change-Id: I3619a0d26e99e2c19f50a63013dedc151b07154c Reviewed-on: http://codereview.qt.nokia.com/2591 Reviewed-by: Qt Sanity Bot Reviewed-by: Martin Jones --- .../data/disabledTransition.qml | 30 ++++++++++++++++ .../tst_qdeclarativeanimations.cpp | 27 ++++++++++++++ .../data/horizontal-animated-disabled.qml | 40 +++++++++++++++++++++ .../qsgpositioners/data/horizontal-animated.qml | 3 ++ .../qsgpositioners/tst_qsgpositioners.cpp | 41 ++++++++++++++++++++++ 5 files changed, 141 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeanimations/data/disabledTransition.qml create mode 100644 tests/auto/declarative/qsgpositioners/data/horizontal-animated-disabled.qml (limited to 'tests') diff --git a/tests/auto/declarative/qdeclarativeanimations/data/disabledTransition.qml b/tests/auto/declarative/qdeclarativeanimations/data/disabledTransition.qml new file mode 100644 index 0000000000..0fbafead8b --- /dev/null +++ b/tests/auto/declarative/qdeclarativeanimations/data/disabledTransition.qml @@ -0,0 +1,30 @@ +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + } + + states: State { + name: "moved" + PropertyChanges { + target: theRect + x: 200 + } + } + transitions: Transition { + enabled: false + NumberAnimation { targets: theRect; properties: "x" } + } + + MouseArea { + anchors.fill: parent + onClicked: parent.state = "moved" + } +} diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index bd9c3e0d7a..367de014b4 100644 --- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -77,6 +77,7 @@ private slots: void mixedTypes(); void properties(); void propertiesTransition(); + void disabledTransition(); void invalidDuration(); void attached(); void propertyValueSourceDefaultStart(); @@ -576,6 +577,32 @@ void tst_qdeclarativeanimations::propertiesTransition() } +void tst_qdeclarativeanimations::disabledTransition() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/disabledTransition.qml")); + QSGRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QSGRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + + QDeclarativeTransition *trans = rect->findChild(); + QVERIFY(trans); + + QCOMPARE(trans->enabled(), false); + + QSGItemPrivate::get(rect)->setState("moved"); + QCOMPARE(myRect->x(),qreal(200)); + + trans->setEnabled(true); + + QSGItemPrivate::get(rect)->setState(""); + QCOMPARE(myRect->x(),qreal(200)); + QTest::qWait(300); + QTIMED_COMPARE(myRect->x(),qreal(100)); +} + void tst_qdeclarativeanimations::invalidDuration() { QDeclarativePropertyAnimation *animation = new QDeclarativePropertyAnimation; diff --git a/tests/auto/declarative/qsgpositioners/data/horizontal-animated-disabled.qml b/tests/auto/declarative/qsgpositioners/data/horizontal-animated-disabled.qml new file mode 100644 index 0000000000..8723ffc78f --- /dev/null +++ b/tests/auto/declarative/qsgpositioners/data/horizontal-animated-disabled.qml @@ -0,0 +1,40 @@ +import QtQuick 2.0 + +Item { + width: 640 + height: 480 + + Row { + objectName: "row" + add: Transition { + enabled: false + NumberAnimation { properties: "x" } + } + move: Transition { + enabled: false + NumberAnimation { properties: "x" } + } + Rectangle { + objectName: "one" + color: "red" + x: -100; + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "blue" + x: -100; + visible: false + width: 50 + height: 50 + } + Rectangle { + objectName: "three" + x: -100; + color: "green" + width: 50 + height: 50 + } + } +} diff --git a/tests/auto/declarative/qsgpositioners/data/horizontal-animated.qml b/tests/auto/declarative/qsgpositioners/data/horizontal-animated.qml index b9b8591e83..a88c26b66c 100644 --- a/tests/auto/declarative/qsgpositioners/data/horizontal-animated.qml +++ b/tests/auto/declarative/qsgpositioners/data/horizontal-animated.qml @@ -4,16 +4,19 @@ Item { width: 640 height: 480 property bool testRightToLeft: false + property bool testEnabled: false Row { objectName: "row" layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight add: Transition { + enabled: testEnabled ? false : true NumberAnimation { properties: "x"; } } move: Transition { + enabled: testEnabled ? false : true NumberAnimation { properties: "x"; } diff --git a/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp b/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp index a9bdf4249b..3b2a504ff4 100644 --- a/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp +++ b/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp @@ -68,6 +68,7 @@ private slots: void test_horizontal_spacing_rightToLeft(); void test_horizontal_animated(); void test_horizontal_animated_rightToLeft(); + void test_horizontal_animated_disabled(); void test_vertical(); void test_vertical_spacing(); void test_vertical_animated(); @@ -328,6 +329,46 @@ void tst_qsgpositioners::test_horizontal_animated_rightToLeft() delete canvas; } +void tst_qsgpositioners::test_horizontal_animated_disabled() +{ + QSGView *canvas = createView(SRCDIR "/data/horizontal-animated-disabled.qml"); + + QSGRectangle *one = canvas->rootObject()->findChild("one"); + QVERIFY(one != 0); + + QSGRectangle *two = canvas->rootObject()->findChild("two"); + QVERIFY(two != 0); + + QSGRectangle *three = canvas->rootObject()->findChild("three"); + QVERIFY(three != 0); + + QSGItem *row = canvas->rootObject()->findChild("row"); + QVERIFY(row); + + qApp->processEvents(); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->isVisible(), false); + QCOMPARE(two->x(), -100.0);//Not 'in' yet + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(three->y(), 0.0); + + //Add 'two' + two->setVisible(true); + QCOMPARE(two->isVisible(), true); + qApp->processEvents(); + QCOMPARE(row->width(), 150.0); + QCOMPARE(row->height(), 50.0); + + qApp->processEvents(); + QCOMPARE(two->x(), 50.0); + QCOMPARE(three->x(), 100.0); + + delete canvas; +} + void tst_qsgpositioners::test_vertical() { QSGView *canvas = createView(SRCDIR "/data/vertical.qml"); -- cgit v1.2.3