summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-11-24 07:15:30 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-11-24 07:15:30 (GMT)
commit150d81f5306758cebfc7412944d1a50db1ded903 (patch)
tree615ae160e31c384e753dab3c4fa291c75d5f25cb
parent148b3d9fd6f3fa11ded6a6c6ef44548b8422c0c4 (diff)
parentb45102dfd37112a754dd54f3e53ca6fce08f24cc (diff)
downloadQt-150d81f5306758cebfc7412944d1a50db1ded903.zip
Qt-150d81f5306758cebfc7412944d1a50db1ded903.tar.gz
Qt-150d81f5306758cebfc7412944d1a50db1ded903.tar.bz2
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsflipable.cpp46
-rw-r--r--src/declarative/util/qmlstategroup.cpp19
-rw-r--r--src/declarative/util/qmltransitionmanager.cpp5
-rw-r--r--tests/auto/declarative/states/data/illegalTempState.qml21
-rw-r--r--tests/auto/declarative/states/data/legalTempState.qml23
-rw-r--r--tests/auto/declarative/states/tst_states.cpp29
6 files changed, 117 insertions, 26 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp
index 57d2ee1..9e48bf2 100644
--- a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp
@@ -68,29 +68,39 @@ public:
Flipable allows you to specify a front and a back and then flip between those sides.
+ Here's an example that flips between the front and back sides when clicked:
+
\qml
-Flipable {
- width: 40; height: 40
-
- transform: Rotation {
- id: rotation
- origin.x: 20; origin.y: 120
- axis.x: 0; axis.y: 1; axis.z: 0
- angle: 0
- }
- front: Image { source: "front.png" }
- back: Image { source: "back.png" }
+ Flipable {
+ id: flipable
+ width: 250; height: 250
+ property int angle: 0
- states: State {
- name: "back"
- SetProperties { target: rotation; angle: 180 }
- }
+ transform: Rotation {
+ id: rotation
+ origin.x: flipable.width/2; origin.y: flipable.height/2
+ axis.x: 0; axis.y: 1; axis.z: 0 // rotate around y-axis
+ angle: flipable.angle
+ }
+
+ front: Image { source: "front.png" }
+ back: Image { source: "back.png" }
- transitions: Transition {
- NumberAnimation { easing: "easeInOutQuad"; matchProperties: "rotation" }
+ states: State {
+ name: "back"
+ PropertyChanges { target: flipable; angle: 180 }
+ }
+
+ transitions: Transition {
+ NumberAnimation { matchProperties: "angle"; duration: 2000 }
+ }
+
+ MouseRegion {
+ anchors.fill: parent
+ onClicked: flipable.state = (flipable.state == 'back' ? 'front' : 'back')
+ }
}
-}
\endqml
\image flipable.gif
diff --git a/src/declarative/util/qmlstategroup.cpp b/src/declarative/util/qmlstategroup.cpp
index d6ce191..4dfa34a 100644
--- a/src/declarative/util/qmlstategroup.cpp
+++ b/src/declarative/util/qmlstategroup.cpp
@@ -42,6 +42,7 @@
#include "private/qobject_p.h"
#include "qmlstategroup_p.h"
#include "qmltransition_p.h"
+#include "qmlstate_p_p.h"
#include <qmlbinding.h>
#include <QtCore/qdebug.h>
#include <private/qmlglobal_p.h>
@@ -57,7 +58,8 @@ class QmlStateGroupPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QmlStateGroup)
public:
QmlStateGroupPrivate(QmlStateGroup *p)
- : nullState(0), states(p), componentComplete(true), ignoreTrans(false) {}
+ : nullState(0), states(p), componentComplete(true),
+ ignoreTrans(false), applyingState(false) {}
QString currentState;
QmlState *nullState;
@@ -78,6 +80,7 @@ public:
QmlConcreteList<QmlTransition *> transitions;
bool componentComplete;
bool ignoreTrans;
+ bool applyingState;
QmlTransition *findTransition(const QString &from, const QString &to);
void setCurrentStateInternal(const QString &state, bool = false);
@@ -212,9 +215,6 @@ void QmlStateGroup::setState(const QString &state)
return;
d->setCurrentStateInternal(state);
-
- d->currentState = state;
- emit stateChanged(d->currentState);
}
void QmlStateGroup::classBegin()
@@ -334,6 +334,13 @@ void QmlStateGroupPrivate::setCurrentStateInternal(const QString &state,
if (!componentComplete)
return;
+ if (applyingState) {
+ qWarning() << "Can't apply a state change as part of a state definition.";
+ return;
+ }
+
+ applyingState = true;
+
QmlTransition *transition = (ignoreTrans || ignoreTrans) ? 0 : findTransition(currentState, state);
if (stateChangeDebug()) {
qWarning() << this << "Changing state. From" << currentState << ". To" << state;
@@ -353,6 +360,7 @@ void QmlStateGroupPrivate::setCurrentStateInternal(const QString &state,
}
currentState = state;
+ emit q->stateChanged(currentState);
QmlState *newState = 0;
for (int ii = 0; ii < states.count(); ++ii) {
@@ -369,6 +377,9 @@ void QmlStateGroupPrivate::setCurrentStateInternal(const QString &state,
}
newState->apply(q, transition, oldState);
+ applyingState = false;
+ if (!transition)
+ static_cast<QmlStatePrivate*>(QObjectPrivate::get(newState))->complete();
}
QmlState *QmlStateGroup::findState(const QString &name) const
diff --git a/src/declarative/util/qmltransitionmanager.cpp b/src/declarative/util/qmltransitionmanager.cpp
index ba726db..1a164c7 100644
--- a/src/declarative/util/qmltransitionmanager.cpp
+++ b/src/declarative/util/qmltransitionmanager.cpp
@@ -236,11 +236,8 @@ void QmlTransitionManager::transition(const QList<Action> &list,
action.property.write(action.toValue);
}
}
- if (!transition) {
+ if (!transition)
d->applyBindings();
- if (d->state)
- static_cast<QmlStatePrivate*>(QObjectPrivate::get(d->state))->complete();
- }
}
void QmlTransitionManager::cancel()
diff --git a/tests/auto/declarative/states/data/illegalTempState.qml b/tests/auto/declarative/states/data/illegalTempState.qml
new file mode 100644
index 0000000..2702be4
--- /dev/null
+++ b/tests/auto/declarative/states/data/illegalTempState.qml
@@ -0,0 +1,21 @@
+import Qt 4.6
+
+Rectangle {
+ id: card
+ width: 100; height: 100
+
+ states: [
+ State {
+ name: "placed"
+ PropertyChanges { target: card; state: "idle" }
+ },
+ State {
+ name: "idle"
+ }
+ ]
+
+ MouseRegion {
+ anchors.fill: parent
+ onClicked: card.state = "placed"
+ }
+}
diff --git a/tests/auto/declarative/states/data/legalTempState.qml b/tests/auto/declarative/states/data/legalTempState.qml
new file mode 100644
index 0000000..54c97b9
--- /dev/null
+++ b/tests/auto/declarative/states/data/legalTempState.qml
@@ -0,0 +1,23 @@
+import Qt 4.6
+
+Rectangle {
+ id: card
+ width: 100; height: 100
+
+ states: [
+ State {
+ name: "placed"
+ onCompleted: card.state = "idle"
+ StateChangeScript { script: console.log("entering placed") }
+ },
+ State {
+ name: "idle"
+ StateChangeScript { script: console.log("entering idle") }
+ }
+ ]
+
+ MouseRegion {
+ anchors.fill: parent
+ onClicked: card.state = "placed"
+ }
+}
diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp
index 4847535..17d9263 100644
--- a/tests/auto/declarative/states/tst_states.cpp
+++ b/tests/auto/declarative/states/tst_states.cpp
@@ -72,6 +72,8 @@ private slots:
void incorrectRestoreBug();
void deletingChange();
void deletingState();
+ void tempState();
+ void illegalTempState();
};
void tst_states::basicChanges()
@@ -803,6 +805,33 @@ void tst_states::deletingState()
delete rect;
}
+void tst_states::tempState()
+{
+ QmlEngine engine;
+
+ QmlComponent rectComponent(&engine, SRCDIR "/data/legalTempState.qml");
+ QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QTest::ignoreMessage(QtDebugMsg, "entering placed");
+ QTest::ignoreMessage(QtDebugMsg, "entering idle");
+ rect->setState("placed");
+ QCOMPARE(rect->state(), QLatin1String("idle"));
+}
+
+void tst_states::illegalTempState()
+{
+ QmlEngine engine;
+
+ QmlComponent rectComponent(&engine, SRCDIR "/data/illegalTempState.qml");
+ QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create());
+ QVERIFY(rect != 0);
+
+ QTest::ignoreMessage(QtWarningMsg, "Can't apply a state change as part of a state definition. ");
+ rect->setState("placed");
+ QCOMPARE(rect->state(), QLatin1String("placed"));
+}
+
QTEST_MAIN(tst_states)
#include "tst_states.moc"