src/declarative/util/qdeclarativestate.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
--- a/src/declarative/util/qdeclarativestate.cpp	Tue Jul 06 15:10:48 2010 +0300
+++ b/src/declarative/util/qdeclarativestate.cpp	Wed Aug 18 10:37:55 2010 +0300
@@ -136,12 +136,31 @@
     \since 4.7
     \brief The State element defines configurations of objects and properties.
 
-    A state is specified as a set of batched changes from the default configuration.
+    A \e state is a set of batched changes from the default configuration.
+
+    All items have a default state that defines the default configuration of objects
+    and property values. New states can be defined by adding State items to the \l {Item::states}{states} property to
+    allow items to switch between different configurations. These configurations
+    can, for example, be used to apply different sets of property values or execute
+    different scripts.
 
-    \note setting the state of an object from within another state of the same object is
+    The following example displays a single \l Rectangle. In the default state, the rectangle
+    is colored black. In the "clicked" state, a PropertyChanges element changes the
+    rectangle's color to red. Clicking within the MouseArea toggles the rectangle's state
+    between the default state and the "clicked" state, thus toggling the color of the
+    rectangle between black and red.
+
+    \snippet doc/src/snippets/declarative/state.qml 0
+
+    Notice the default state is referred to using an empty string ("").
+
+    States are commonly used together with \l {state-transitions}{Transitions} to provide
+    animations when state changes occur.
+
+    \note Setting the state of an object from within another state of the same object is
     not allowed.
 
-    \sa {qmlstates}{States}, {state-transitions}{Transitions}, QtDeclarative
+    \sa {declarative/animation/states}{states example}, {qmlstates}{States}, {state-transitions}{Transitions}, QtDeclarative
 */
 
 /*!
@@ -173,9 +192,9 @@
 
 /*!
     \qmlproperty string State::name
-    This property holds the name of the state
+    This property holds the name of the state.
 
-    Each state should have a unique name.
+    Each state should have a unique name within its item.
 */
 QString QDeclarativeState::name() const
 {
@@ -187,6 +206,13 @@
 {
     Q_D(QDeclarativeState);
     d->name = n;
+    d->named = true;
+}
+
+bool QDeclarativeState::isNamed() const
+{
+    Q_D(const QDeclarativeState);
+    return d->named;
 }
 
 bool QDeclarativeState::isWhenKnown() const
@@ -197,12 +223,28 @@
 
 /*!
     \qmlproperty bool State::when
-    This property holds when the state should be applied
+    This property holds when the state should be applied.
+
+    This should be set to an expression that evaluates to \c true when you want the state to
+    be applied. For example, the following \l Rectangle changes in and out of the "hidden"
+    state when the \l MouseArea is pressed:
 
-    This should be set to an expression that evaluates to true when you want the state to
-    be applied.
+    \qml
+    Rectangle {
+        id: myRect
+        width: 100; height: 100
+        color: "red"
+
+        MouseArea { id: mouseArea; anchors.fill: parent }
 
-    If multiple states in a group have \c when clauses that evaluate to true at the same time,
+        states: State {
+            name: "hidden"; when: mouseArea.pressed
+            PropertyChanges { target: myRect; opacity: 0 }
+        }
+    }
+    \endqml
+
+    If multiple states in a group have \c when clauses that evaluate to \c true at the same time,
     the first matching state will be applied. For example, in the following snippet
     \c state1 will always be selected rather than \c state2 when sharedCondition becomes
     \c true.
@@ -229,7 +271,9 @@
 
 /*!
     \qmlproperty string State::extend
-    This property holds the state that this state extends
+    This property holds the state that this state extends.
+
+    When a state extends another state, it inherits all the changes of that state.
 
     The state being extended is treated as the base state in regards to
     the changes specified by the extending state.
@@ -486,6 +530,7 @@
     // All the local reverts now become part of the ongoing revertList
     d->revertList << additionalReverts;
 
+#ifndef QT_NO_DEBUG_STREAM
     // Output for debugging
     if (stateChangeDebug()) {
         foreach(const QDeclarativeAction &action, applyList) {
@@ -497,6 +542,7 @@
                            << "To:" << action.toValue;
         }
     }
+#endif
 
     d->transitionManager.transition(applyList, trans);
 }