#include <private/qdeclarativestate_p.h>
#include <private/qdeclarativestategroup_p.h>
#include <private/qdeclarativestateoperations_p.h>
+#include <private/qdeclarativetransition_p.h>
QT_BEGIN_NAMESPACE
}
QSizeF contentSize(0,0);
doPositioning(&contentSize);
- if(d->addTransition || d->moveTransition)
+ if (!d->addActions.isEmpty() || !d->moveActions.isEmpty())
finishApplyTransitions();
d->doingPositioning = false;
//Set implicit size to the size of its children
Q_D(QSGBasePositioner);
if(d->type == Horizontal || d->type == Both){
if (target.isNew) {
- if (!d->addTransition)
+ if (!d->addTransition || !d->addTransition->enabled())
target.item->setX(x);
else
d->addActions << QDeclarativeAction(target.item, QLatin1String("x"), QVariant(x));
} else if (x != target.item->x()) {
- if (!d->moveTransition)
+ if (!d->moveTransition || !d->moveTransition->enabled())
target.item->setX(x);
else
d->moveActions << QDeclarativeAction(target.item, QLatin1String("x"), QVariant(x));
Q_D(QSGBasePositioner);
if(d->type == Vertical || d->type == Both){
if (target.isNew) {
- if (!d->addTransition)
+ if (!d->addTransition || !d->addTransition->enabled())
target.item->setY(y);
else
d->addActions << QDeclarativeAction(target.item, QLatin1String("y"), QVariant(y));
} else if (y != target.item->y()) {
- if (!d->moveTransition)
+ if (!d->moveTransition || !d->moveTransition->enabled())
target.item->setY(y);
else
d->moveActions << QDeclarativeAction(target.item, QLatin1String("y"), QVariant(y));
for (int ii = 0; !done && ii < transitions.count(); ++ii) {
QDeclarativeTransition *t = transitions.at(ii);
+ if (!t->enabled())
+ continue;
for (int ii = 0; ii < 2; ++ii)
{
if (ii && (!t->reversible() ||
public:
QDeclarativeTransitionPrivate()
: fromState(QLatin1String("*")), toState(QLatin1String("*")),
- reversed(false), reversible(false), endState(0)
+ reversed(false), reversible(false), enabled(true), endState(0)
{
group.trans = this;
}
QString toState;
bool reversed;
bool reversible;
+ bool enabled;
ParallelAnimationWrapper group;
QDeclarativeTransitionManager *endState;
}
/*!
+ \qmlproperty bool Transition::enabled
+
+ This property holds whether the Transition will be run when moving
+ from the \c from state to the \c to state.
+
+ By default a Transition is enabled.
+
+ Note that in some circumstances disabling a Transition may cause an
+ alternative Transition to be used in its place. In the following
+ example, the generic Transition will be used to animate the change
+ from \c state1 to \c state2, as the more specific Transition has
+ been disabled.
+
+ \qml
+ Item {
+ states: [
+ State { name: "state1" ... }
+ State { name: "state2" ... }
+ ]
+ transitions: [
+ Transition { from: "state1"; to: "state2"; enabled: false ... }
+ Transition { ... }
+ ]
+ }
+ \endqml
+*/
+
+bool QDeclarativeTransition::enabled() const
+{
+ Q_D(const QDeclarativeTransition);
+ return d->enabled;
+}
+
+void QDeclarativeTransition::setEnabled(bool enabled)
+{
+ Q_D(QDeclarativeTransition);
+ if (d->enabled == enabled)
+ return;
+ d->enabled = enabled;
+ emit enabledChanged();
+}
+
+/*!
\qmlproperty list<Animation> Transition::animations
\default
Q_PROPERTY(QString to READ toState WRITE setToState NOTIFY toChanged)
Q_PROPERTY(bool reversible READ reversible WRITE setReversible NOTIFY reversibleChanged)
Q_PROPERTY(QDeclarativeListProperty<QDeclarativeAbstractAnimation> animations READ animations)
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
Q_CLASSINFO("DefaultProperty", "animations")
Q_CLASSINFO("DeferredPropertyNames", "animations")
bool reversible() const;
void setReversible(bool);
+ bool enabled() const;
+ void setEnabled(bool enabled);
+
QDeclarativeListProperty<QDeclarativeAbstractAnimation> animations();
void prepare(QDeclarativeStateOperation::ActionList &actions,
void fromChanged();
void toChanged();
void reversibleChanged();
+ void enabledChanged();
};
QT_END_NAMESPACE
--- /dev/null
+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"
+ }
+}
void mixedTypes();
void properties();
void propertiesTransition();
+ void disabledTransition();
void invalidDuration();
void attached();
void propertyValueSourceDefaultStart();
}
+void tst_qdeclarativeanimations::disabledTransition()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/disabledTransition.qml"));
+ QSGRectangle *rect = qobject_cast<QSGRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QSGRectangle *myRect = rect->findChild<QSGRectangle*>("TheRect");
+ QVERIFY(myRect);
+
+ QDeclarativeTransition *trans = rect->findChild<QDeclarativeTransition*>();
+ 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;
--- /dev/null
+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
+ }
+ }
+}
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";
}
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();
delete canvas;
}
+void tst_qsgpositioners::test_horizontal_animated_disabled()
+{
+ QSGView *canvas = createView(SRCDIR "/data/horizontal-animated-disabled.qml");
+
+ QSGRectangle *one = canvas->rootObject()->findChild<QSGRectangle*>("one");
+ QVERIFY(one != 0);
+
+ QSGRectangle *two = canvas->rootObject()->findChild<QSGRectangle*>("two");
+ QVERIFY(two != 0);
+
+ QSGRectangle *three = canvas->rootObject()->findChild<QSGRectangle*>("three");
+ QVERIFY(three != 0);
+
+ QSGItem *row = canvas->rootObject()->findChild<QSGItem*>("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");