Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / util / qdeclarativestate_p_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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 "qdeclarativestate_p.h"
57
58 #include "qdeclarativetransitionmanager_p_p.h"
59
60 #include <private/qdeclarativeproperty_p.h>
61 #include <private/qdeclarativeguard_p.h>
62
63 #include <private/qdeclarativebinding_p.h>
64
65 #include <private/qobject_p.h>
66
67 QT_BEGIN_NAMESPACE
68
69 class QDeclarativeSimpleAction
70 {
71 public:
72     enum State { StartState, EndState };
73     QDeclarativeSimpleAction(const QDeclarativeAction &a, State state = StartState)
74     {
75         m_property = a.property;
76         m_specifiedObject = a.specifiedObject;
77         m_specifiedProperty = a.specifiedProperty;
78         m_event = a.event;
79         if (state == StartState) {
80             m_value = a.fromValue;
81             if (QDeclarativePropertyPrivate::binding(m_property)) {
82                 m_binding = QDeclarativeAbstractBinding::getPointer(QDeclarativePropertyPrivate::binding(m_property));
83             }
84             m_reverseEvent = true;
85         } else {
86             m_value = a.toValue;
87             m_binding = a.toBinding;
88             m_reverseEvent = false;
89         }
90     }
91
92     ~QDeclarativeSimpleAction()
93     {
94     }
95
96     QDeclarativeSimpleAction(const QDeclarativeSimpleAction &other)
97         :  m_property(other.m_property),
98         m_value(other.m_value),
99         m_binding(QDeclarativeAbstractBinding::getPointer(other.binding())),
100         m_specifiedObject(other.m_specifiedObject),
101         m_specifiedProperty(other.m_specifiedProperty),
102         m_event(other.m_event),
103         m_reverseEvent(other.m_reverseEvent)
104     {
105     }
106
107     QDeclarativeSimpleAction &operator =(const QDeclarativeSimpleAction &other)
108     {
109         m_property = other.m_property;
110         m_value = other.m_value;
111         m_binding = QDeclarativeAbstractBinding::getPointer(other.binding());
112         m_specifiedObject = other.m_specifiedObject;
113         m_specifiedProperty = other.m_specifiedProperty;
114         m_event = other.m_event;
115         m_reverseEvent = other.m_reverseEvent;
116
117         return *this;
118     }
119
120     void setProperty(const QDeclarativeProperty &property)
121     {
122         m_property = property;
123     }
124
125     const QDeclarativeProperty &property() const
126     {
127         return m_property;
128     }
129
130     void setValue(const QVariant &value)
131     {
132         m_value = value;
133     }
134
135     const QVariant &value() const
136     {
137         return m_value;
138     }
139
140     void setBinding(QDeclarativeAbstractBinding *binding)
141     {
142         m_binding = QDeclarativeAbstractBinding::getPointer(binding);
143     }
144
145     QDeclarativeAbstractBinding *binding() const
146     {
147         return m_binding.data();
148     }
149
150     QObject *specifiedObject() const
151     {
152         return m_specifiedObject;
153     }
154
155     const QString &specifiedProperty() const
156     {
157         return m_specifiedProperty;
158     }
159
160     QDeclarativeActionEvent *event() const
161     {
162         return m_event;
163     }
164
165     bool reverseEvent() const
166     {
167         return m_reverseEvent;
168     }
169
170 private:
171     QDeclarativeProperty m_property;
172     QVariant m_value;
173     QDeclarativeAbstractBinding::Pointer m_binding;
174     QObject *m_specifiedObject;
175     QString m_specifiedProperty;
176     QDeclarativeActionEvent *m_event;
177     bool m_reverseEvent;
178 };
179
180 class QDeclarativeRevertAction
181 {
182 public:
183     QDeclarativeRevertAction() : event(0) {}
184     QDeclarativeRevertAction(const QDeclarativeProperty &prop) : property(prop), event(0) {}
185     QDeclarativeRevertAction(QDeclarativeActionEvent *e) : event(e) {}
186     QDeclarativeProperty property;
187     QDeclarativeActionEvent *event;
188 };
189
190 class QDeclarativeStateOperationPrivate : public QObjectPrivate
191 {
192     Q_DECLARE_PUBLIC(QDeclarativeStateOperation)
193
194 public:
195
196     QDeclarativeStateOperationPrivate()
197     : m_state(0) {}
198
199     QDeclarativeState *m_state;
200 };
201
202 class QDeclarativeStatePrivate : public QObjectPrivate
203 {
204     Q_DECLARE_PUBLIC(QDeclarativeState)
205
206 public:
207     QDeclarativeStatePrivate()
208     : when(0), named(false), inState(false), group(0) {}
209
210     typedef QList<QDeclarativeSimpleAction> SimpleActionList;
211
212     QString name;
213     QDeclarativeBinding *when;
214     bool named;
215
216     struct OperationGuard : public QDeclarativeGuard<QDeclarativeStateOperation>
217     {
218         OperationGuard(QObject *obj, QList<OperationGuard> *l) : list(l) { 
219             setObject(static_cast<QDeclarativeStateOperation *>(obj));
220         }
221         QList<OperationGuard> *list;
222         void objectDestroyed(QDeclarativeStateOperation *) {
223             // we assume priv will always be destroyed after objectDestroyed calls
224             list->removeOne(*this);
225         }
226     };
227     QList<OperationGuard> operations;
228
229     static void operations_append(QDeclarativeListProperty<QDeclarativeStateOperation> *prop, QDeclarativeStateOperation *op) {
230         QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
231         op->setState(qobject_cast<QDeclarativeState*>(prop->object));
232         list->append(OperationGuard(op, list));
233     }
234     static void operations_clear(QDeclarativeListProperty<QDeclarativeStateOperation> *prop) {
235         QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
236         QMutableListIterator<OperationGuard> listIterator(*list);
237         while(listIterator.hasNext())
238             listIterator.next()->setState(0);
239         list->clear();
240     }
241     static int operations_count(QDeclarativeListProperty<QDeclarativeStateOperation> *prop) {
242         QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
243         return list->count();
244     }
245     static QDeclarativeStateOperation *operations_at(QDeclarativeListProperty<QDeclarativeStateOperation> *prop, int index) {
246         QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
247         return list->at(index);
248     }
249
250     QDeclarativeTransitionManager transitionManager;
251
252     SimpleActionList revertList;
253     QList<QDeclarativeRevertAction> reverting;
254     QString extends;
255     mutable bool inState;
256     QDeclarativeStateGroup *group;
257
258     QDeclarativeStateOperation::ActionList generateActionList() const;
259     void complete();
260 };
261
262 QT_END_NAMESPACE
263
264 #endif // QDECLARATIVESTATE_P_H