summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-11-24 06:43:27 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-11-24 06:43:27 (GMT)
commitfe996d89f4441d9c3ee341083a2bf133a6a57114 (patch)
tree215f9251501517fd37aa8f9d1e94c5ead92a1f91 /src/declarative
parent31540e4b5177073d71b98e296ad7d59faf63b383 (diff)
parentb45102dfd37112a754dd54f3e53ca6fce08f24cc (diff)
downloadQt-fe996d89f4441d9c3ee341083a2bf133a6a57114.zip
Qt-fe996d89f4441d9c3ee341083a2bf133a6a57114.tar.gz
Qt-fe996d89f4441d9c3ee341083a2bf133a6a57114.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsflipable.cpp46
-rw-r--r--src/declarative/util/qmlpropertychanges.cpp17
-rw-r--r--src/declarative/util/qmlstategroup.cpp19
-rw-r--r--src/declarative/util/qmlstateoperations.cpp21
-rw-r--r--src/declarative/util/qmltransitionmanager.cpp5
5 files changed, 78 insertions, 30 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/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp
index 28c8e4f..6a393ee 100644
--- a/src/declarative/util/qmlpropertychanges.cpp
+++ b/src/declarative/util/qmlpropertychanges.cpp
@@ -57,7 +57,8 @@ QT_BEGIN_NAMESPACE
\brief The PropertyChanges element describes new property values for a state.
PropertyChanges changes the properties of an item. It allows you to specify the property
- names and values similar to how you normally would specify them for the actual item:
+ names and values for a state similar to how you normally would specify them for the
+ actual item:
\code
PropertyChanges {
@@ -67,6 +68,20 @@ QT_BEGIN_NAMESPACE
width: 48
}
\endcode
+
+ State-specific script for signal handlers can also be specified:
+
+ \qml
+ PropertyChanges {
+ target: myMouseRegion
+ onClicked: doSomethingDifferent()
+ }
+ \endqml
+
+ Changes to an Item's parent or anchors should be done using the associated change elements
+ (ParentChange and AnchorChanges, respectively) rather than PropertyChanges.
+
+ \sa {qmlstate}{States}
*/
/*!
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/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp
index e2933b2..9727ca7 100644
--- a/src/declarative/util/qmlstateoperations.cpp
+++ b/src/declarative/util/qmlstateoperations.cpp
@@ -153,6 +153,9 @@ void QmlParentChangePrivate::doChange(QmlGraphicsItem *targetParent, QmlGraphics
More specifically, it will not work if the transform property has been set for any
Items involved in the reparenting (defined as any Items in the common ancestor tree
for the original and new parent).
+
+ You can specify at which point in a transition you want a ParentChange to occur by
+ using a ParentAction.
*/
QML_DEFINE_TYPE(Qt,4,6,ParentChange,QmlParentChange)
@@ -166,7 +169,7 @@ QmlParentChange::~QmlParentChange()
}
/*!
- \qmlproperty Object ParentChange::target
+ \qmlproperty Item ParentChange::target
This property holds the item to be reparented
*/
@@ -310,6 +313,10 @@ public:
/*!
\qmlclass StateChangeScript QmlStateChangeScript
\brief The StateChangeScript element allows you to run a script in a state.
+
+ The script specified will be run immediately when the state is made current.
+ Alternatively you can use a ScriptAction to specify at which point in the transition
+ you want the StateChangeScript to be run.
*/
QML_DEFINE_TYPE(Qt,4,6,StateChangeScript,QmlStateChangeScript)
QmlStateChangeScript::QmlStateChangeScript(QObject *parent)
@@ -385,8 +392,16 @@ QString QmlStateChangeScript::typeName() const
\qmlclass AnchorChanges QmlAnchorChanges
\brief The AnchorChanges element allows you to change the anchors of an item in a state.
+ In the following example we change the top and bottom anchors of an item:
\snippet examples/declarative/anchors/anchor-changes.qml 0
+ AnchorChanges will 'inject' \c x, \c y, \c width, and \c height changes into the transition,
+ so you can animate them as you would normally changes to these properties:
+ \qml
+ //animate our anchor changes
+ NumberAnimation { matchTargets: content; matchProperties: "x,y,width,height" }
+ \endqml
+
For more information on anchors see \l {anchor-layout}{Anchor Layouts}.
*/
@@ -432,8 +447,8 @@ public:
};
/*!
- \qmlproperty Object AnchorChanges::target
- This property holds the object that the anchors to change belong to
+ \qmlproperty Item AnchorChanges::target
+ This property holds the Item whose anchors will change
*/
QmlAnchorChanges::QmlAnchorChanges(QObject *parent)
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()