1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QDECLARATIVESTATE_P_H
43 #define QDECLARATIVESTATE_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "private/qdeclarativestate_p.h"
58 #include "private/qdeclarativeanimation_p_p.h"
59 #include "private/qdeclarativetransitionmanager_p_p.h"
61 #include <private/qdeclarativeproperty_p.h>
62 #include <private/qdeclarativeguard_p.h>
64 #include <private/qdeclarativebinding_p.h>
66 #include <private/qobject_p.h>
70 class QDeclarativeSimpleAction
73 enum State { StartState, EndState };
74 QDeclarativeSimpleAction(const QDeclarativeAction &a, State state = StartState)
76 m_property = a.property;
77 m_specifiedObject = a.specifiedObject;
78 m_specifiedProperty = a.specifiedProperty;
80 if (state == StartState) {
81 m_value = a.fromValue;
82 if (QDeclarativePropertyPrivate::binding(m_property)) {
83 m_binding = QDeclarativeAbstractBinding::getPointer(QDeclarativePropertyPrivate::binding(m_property));
85 m_reverseEvent = true;
88 m_binding = a.toBinding;
89 m_reverseEvent = false;
93 ~QDeclarativeSimpleAction()
97 QDeclarativeSimpleAction(const QDeclarativeSimpleAction &other)
98 : m_property(other.m_property),
99 m_value(other.m_value),
100 m_binding(QDeclarativeAbstractBinding::getPointer(other.binding())),
101 m_specifiedObject(other.m_specifiedObject),
102 m_specifiedProperty(other.m_specifiedProperty),
103 m_event(other.m_event),
104 m_reverseEvent(other.m_reverseEvent)
108 QDeclarativeSimpleAction &operator =(const QDeclarativeSimpleAction &other)
110 m_property = other.m_property;
111 m_value = other.m_value;
112 m_binding = QDeclarativeAbstractBinding::getPointer(other.binding());
113 m_specifiedObject = other.m_specifiedObject;
114 m_specifiedProperty = other.m_specifiedProperty;
115 m_event = other.m_event;
116 m_reverseEvent = other.m_reverseEvent;
121 void setProperty(const QDeclarativeProperty &property)
123 m_property = property;
126 const QDeclarativeProperty &property() const
131 void setValue(const QVariant &value)
136 const QVariant &value() const
141 void setBinding(QDeclarativeAbstractBinding *binding)
143 m_binding = QDeclarativeAbstractBinding::getPointer(binding);
146 QDeclarativeAbstractBinding *binding() const
148 return m_binding.data();
151 QObject *specifiedObject() const
153 return m_specifiedObject;
156 const QString &specifiedProperty() const
158 return m_specifiedProperty;
161 QDeclarativeActionEvent *event() const
166 bool reverseEvent() const
168 return m_reverseEvent;
172 QDeclarativeProperty m_property;
174 QDeclarativeAbstractBinding::Pointer m_binding;
175 QObject *m_specifiedObject;
176 QString m_specifiedProperty;
177 QDeclarativeActionEvent *m_event;
181 class QDeclarativeStateOperationPrivate : public QObjectPrivate
183 Q_DECLARE_PUBLIC(QDeclarativeStateOperation)
187 QDeclarativeStateOperationPrivate()
190 QDeclarativeState *m_state;
193 class QDeclarativeStatePrivate : public QObjectPrivate
195 Q_DECLARE_PUBLIC(QDeclarativeState)
198 QDeclarativeStatePrivate()
199 : when(0), named(false), inState(false), group(0) {}
201 typedef QList<QDeclarativeSimpleAction> SimpleActionList;
204 QDeclarativeBinding *when;
207 struct OperationGuard : public QDeclarativeGuard<QDeclarativeStateOperation>
209 OperationGuard(QObject *obj, QList<OperationGuard> *l) : list(l) { (QDeclarativeGuard<QObject>&)*this = obj; }
210 QList<OperationGuard> *list;
211 void objectDestroyed(QDeclarativeStateOperation *) {
212 // we assume priv will always be destroyed after objectDestroyed calls
213 list->removeOne(*this);
216 QList<OperationGuard> operations;
218 static void operations_append(QDeclarativeListProperty<QDeclarativeStateOperation> *prop, QDeclarativeStateOperation *op) {
219 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
220 op->setState(qobject_cast<QDeclarativeState*>(prop->object));
221 list->append(OperationGuard(op, list));
223 static void operations_clear(QDeclarativeListProperty<QDeclarativeStateOperation> *prop) {
224 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
225 QMutableListIterator<OperationGuard> listIterator(*list);
226 while(listIterator.hasNext())
227 listIterator.next()->setState(0);
230 static int operations_count(QDeclarativeListProperty<QDeclarativeStateOperation> *prop) {
231 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
232 return list->count();
234 static QDeclarativeStateOperation *operations_at(QDeclarativeListProperty<QDeclarativeStateOperation> *prop, int index) {
235 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
236 return list->at(index);
239 QDeclarativeTransitionManager transitionManager;
241 SimpleActionList revertList;
242 QList<QDeclarativeProperty> reverting;
244 mutable bool inState;
245 QDeclarativeStateGroup *group;
247 QDeclarativeStateOperation::ActionList generateActionList(QDeclarativeStateGroup *) const;
253 #endif // QDECLARATIVESTATE_P_H