121 { |
121 { |
122 Q_UNUSED(other); |
122 Q_UNUSED(other); |
123 return false; |
123 return false; |
124 } |
124 } |
125 |
125 |
126 /*! |
|
127 \internal |
|
128 */ |
|
129 QDeclarativeStateOperation::QDeclarativeStateOperation(QObjectPrivate &dd, QObject *parent) |
126 QDeclarativeStateOperation::QDeclarativeStateOperation(QObjectPrivate &dd, QObject *parent) |
130 : QObject(dd, parent) |
127 : QObject(dd, parent) |
131 { |
128 { |
132 } |
129 } |
133 |
130 |
134 /*! |
131 /*! |
135 \qmlclass State QDeclarativeState |
132 \qmlclass State QDeclarativeState |
|
133 \ingroup qml-state-elements |
136 \since 4.7 |
134 \since 4.7 |
137 \brief The State element defines configurations of objects and properties. |
135 \brief The State element defines configurations of objects and properties. |
138 |
136 |
139 A \e state is a set of batched changes from the default configuration. |
137 A \e state is a set of batched changes from the default configuration. |
140 |
138 |
152 |
150 |
153 \snippet doc/src/snippets/declarative/state.qml 0 |
151 \snippet doc/src/snippets/declarative/state.qml 0 |
154 |
152 |
155 Notice the default state is referred to using an empty string (""). |
153 Notice the default state is referred to using an empty string (""). |
156 |
154 |
157 States are commonly used together with \l {state-transitions}{Transitions} to provide |
155 States are commonly used together with \l {Transitions} to provide |
158 animations when state changes occur. |
156 animations when state changes occur. |
159 |
157 |
160 \note Setting the state of an object from within another state of the same object is |
158 \note Setting the state of an object from within another state of the same object is |
161 not allowed. |
159 not allowed. |
162 |
160 |
163 \sa {declarative/animation/states}{states example}, {qmlstates}{States}, {state-transitions}{Transitions}, QtDeclarative |
161 \sa {declarative/animation/states}{states example}, {qmlstates}{States}, |
|
162 {qdeclarativeanimation.html#transitions}{QML Transitions}, QtDeclarative |
164 */ |
163 */ |
165 |
|
166 /*! |
|
167 \internal |
|
168 \class QDeclarativeState |
|
169 \brief The QDeclarativeState class allows you to define configurations of objects and properties. |
|
170 |
|
171 |
|
172 QDeclarativeState allows you to specify a state as a set of batched changes from the default |
|
173 configuration. |
|
174 |
|
175 \sa {states-transitions}{States and Transitions} |
|
176 */ |
|
177 |
|
178 |
|
179 QDeclarativeState::QDeclarativeState(QObject *parent) |
164 QDeclarativeState::QDeclarativeState(QObject *parent) |
180 : QObject(*(new QDeclarativeStatePrivate), parent) |
165 : QObject(*(new QDeclarativeStatePrivate), parent) |
181 { |
166 { |
182 Q_D(QDeclarativeState); |
167 Q_D(QDeclarativeState); |
183 d->transitionManager.setState(this); |
168 d->transitionManager.setState(this); |
227 |
212 |
228 This should be set to an expression that evaluates to \c true when you want the state to |
213 This should be set to an expression that evaluates to \c true when you want the state to |
229 be applied. For example, the following \l Rectangle changes in and out of the "hidden" |
214 be applied. For example, the following \l Rectangle changes in and out of the "hidden" |
230 state when the \l MouseArea is pressed: |
215 state when the \l MouseArea is pressed: |
231 |
216 |
232 \qml |
217 \snippet doc/src/snippets/declarative/state-when.qml 0 |
233 Rectangle { |
|
234 id: myRect |
|
235 width: 100; height: 100 |
|
236 color: "red" |
|
237 |
|
238 MouseArea { id: mouseArea; anchors.fill: parent } |
|
239 |
|
240 states: State { |
|
241 name: "hidden"; when: mouseArea.pressed |
|
242 PropertyChanges { target: myRect; opacity: 0 } |
|
243 } |
|
244 } |
|
245 \endqml |
|
246 |
218 |
247 If multiple states in a group have \c when clauses that evaluate to \c true at the same time, |
219 If multiple states in a group have \c when clauses that evaluate to \c true at the same time, |
248 the first matching state will be applied. For example, in the following snippet |
220 the first matching state will be applied. For example, in the following snippet |
249 \c state1 will always be selected rather than \c state2 when sharedCondition becomes |
221 \c state1 will always be selected rather than \c state2 when sharedCondition becomes |
250 \c true. |
222 \c true. |
356 inState = true; |
328 inState = true; |
357 |
329 |
358 if (!extends.isEmpty()) { |
330 if (!extends.isEmpty()) { |
359 QList<QDeclarativeState *> states = group->states(); |
331 QList<QDeclarativeState *> states = group->states(); |
360 for (int ii = 0; ii < states.count(); ++ii) |
332 for (int ii = 0; ii < states.count(); ++ii) |
361 if (states.at(ii)->name() == extends) |
333 if (states.at(ii)->name() == extends) { |
|
334 qmlExecuteDeferred(states.at(ii)); |
362 applyList = static_cast<QDeclarativeStatePrivate*>(states.at(ii)->d_func())->generateActionList(group); |
335 applyList = static_cast<QDeclarativeStatePrivate*>(states.at(ii)->d_func())->generateActionList(group); |
|
336 } |
363 } |
337 } |
364 |
338 |
365 foreach(QDeclarativeStateOperation *op, operations) |
339 foreach(QDeclarativeStateOperation *op, operations) |
366 applyList << op->actions(); |
340 applyList << op->actions(); |
367 |
341 |