Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / src / declarative / util / qdeclarativestate_p_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
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
14 ** this package.
15 **
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.
23 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVESTATE_P_H
43 #define QDECLARATIVESTATE_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
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.
52 //
53 // We mean it.
54 //
55
56 #include "private/qdeclarativestate_p.h"
57
58 #include "private/qdeclarativeanimation_p_p.h"
59 #include "private/qdeclarativetransitionmanager_p_p.h"
60
61 #include <private/qdeclarativeproperty_p.h>
62 #include <private/qdeclarativeguard_p.h>
63
64 #include <private/qdeclarativebinding_p.h>
65
66 #include <private/qobject_p.h>
67
68 QT_BEGIN_NAMESPACE
69
70 class QDeclarativeSimpleAction
71 {
72 public:
73     enum State { StartState, EndState };
74     QDeclarativeSimpleAction(const QDeclarativeAction &a, State state = StartState)
75     {
76         m_property = a.property;
77         m_specifiedObject = a.specifiedObject;
78         m_specifiedProperty = a.specifiedProperty;
79         m_event = a.event;
80         if (state == StartState) {
81             m_value = a.fromValue;
82             if (QDeclarativePropertyPrivate::binding(m_property)) {
83                 m_binding = QDeclarativeAbstractBinding::getPointer(QDeclarativePropertyPrivate::binding(m_property));
84             }
85             m_reverseEvent = true;
86         } else {
87             m_value = a.toValue;
88             m_binding = a.toBinding;
89             m_reverseEvent = false;
90         }
91     }
92
93     ~QDeclarativeSimpleAction()
94     {
95     }
96
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)
105     {
106     }
107
108     QDeclarativeSimpleAction &operator =(const QDeclarativeSimpleAction &other)
109     {
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;
117
118         return *this;
119     }
120
121     void setProperty(const QDeclarativeProperty &property)
122     {
123         m_property = property;
124     }
125
126     const QDeclarativeProperty &property() const
127     {
128         return m_property;
129     }
130
131     void setValue(const QVariant &value)
132     {
133         m_value = value;
134     }
135
136     const QVariant &value() const
137     {
138         return m_value;
139     }
140
141     void setBinding(QDeclarativeAbstractBinding *binding)
142     {
143         m_binding = QDeclarativeAbstractBinding::getPointer(binding);
144     }
145
146     QDeclarativeAbstractBinding *binding() const
147     {
148         return m_binding.data();
149     }
150
151     QObject *specifiedObject() const
152     {
153         return m_specifiedObject;
154     }
155
156     const QString &specifiedProperty() const
157     {
158         return m_specifiedProperty;
159     }
160
161     QDeclarativeActionEvent *event() const
162     {
163         return m_event;
164     }
165
166     bool reverseEvent() const
167     {
168         return m_reverseEvent;
169     }
170
171 private:
172     QDeclarativeProperty m_property;
173     QVariant m_value;
174     QDeclarativeAbstractBinding::Pointer m_binding;
175     QObject *m_specifiedObject;
176     QString m_specifiedProperty;
177     QDeclarativeActionEvent *m_event;
178     bool m_reverseEvent;
179 };
180
181 class QDeclarativeStateOperationPrivate : public QObjectPrivate
182 {
183     Q_DECLARE_PUBLIC(QDeclarativeStateOperation)
184
185 public:
186
187     QDeclarativeStateOperationPrivate()
188     : m_state(0) {}
189
190     QDeclarativeState *m_state;
191 };
192
193 class QDeclarativeStatePrivate : public QObjectPrivate
194 {
195     Q_DECLARE_PUBLIC(QDeclarativeState)
196
197 public:
198     QDeclarativeStatePrivate()
199     : when(0), named(false), inState(false), group(0) {}
200
201     typedef QList<QDeclarativeSimpleAction> SimpleActionList;
202
203     QString name;
204     QDeclarativeBinding *when;
205     bool named;
206
207     struct OperationGuard : public QDeclarativeGuard<QDeclarativeStateOperation>
208     {
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);
214         }
215     };
216     QList<OperationGuard> operations;
217
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));
222     }
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);
228         list->clear();
229     }
230     static int operations_count(QDeclarativeListProperty<QDeclarativeStateOperation> *prop) {
231         QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
232         return list->count();
233     }
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);
237     }
238
239     QDeclarativeTransitionManager transitionManager;
240
241     SimpleActionList revertList;
242     QList<QDeclarativeProperty> reverting;
243     QString extends;
244     mutable bool inState;
245     QDeclarativeStateGroup *group;
246
247     QDeclarativeStateOperation::ActionList generateActionList(QDeclarativeStateGroup *) const;
248     void complete();
249 };
250
251 QT_END_NAMESPACE
252
253 #endif // QDECLARATIVESTATE_P_H