Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / qtquick1 / 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 "QtQuick1/private/qdeclarativestate_p.h"
57
58 #include "QtQuick1/private/qdeclarativeanimation_p_p.h"
59 #include "QtQuick1/private/qdeclarativetransitionmanager_p_p.h"
60
61 #include <QtDeclarative/private/qdeclarativeproperty_p.h>
62 #include <QtDeclarative/private/qdeclarativeguard_p.h>
63
64 #include <QtDeclarative/private/qdeclarativebinding_p.h>
65
66 #include <QtCore/private/qobject_p.h>
67
68 QT_BEGIN_NAMESPACE
69
70 class QDeclarative1SimpleAction
71 {
72 public:
73     enum State { StartState, EndState };
74     QDeclarative1SimpleAction(const QDeclarative1Action &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     ~QDeclarative1SimpleAction()
94     {
95     }
96
97     QDeclarative1SimpleAction(const QDeclarative1SimpleAction &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     QDeclarative1SimpleAction &operator =(const QDeclarative1SimpleAction &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     QDeclarative1ActionEvent *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     QDeclarative1ActionEvent *m_event;
178     bool m_reverseEvent;
179 };
180
181 class QDeclarative1StateOperationPrivate : public QObjectPrivate
182 {
183     Q_DECLARE_PUBLIC(QDeclarative1StateOperation)
184
185 public:
186
187     QDeclarative1StateOperationPrivate()
188     : m_state(0) {}
189
190     QDeclarative1State *m_state;
191 };
192
193 class QDeclarative1StatePrivate : public QObjectPrivate
194 {
195     Q_DECLARE_PUBLIC(QDeclarative1State)
196
197 public:
198     QDeclarative1StatePrivate()
199     : when(0), named(false), inState(false), group(0) {}
200
201     typedef QList<QDeclarative1SimpleAction> SimpleActionList;
202
203     QString name;
204     QDeclarativeBinding *when;
205     bool named;
206
207     struct OperationGuard : public QDeclarativeGuard<QDeclarative1StateOperation>
208     {
209         OperationGuard(QObject *obj, QList<OperationGuard> *l) : list(l) { (QDeclarativeGuard<QObject>&)*this = obj; }
210         QList<OperationGuard> *list;
211         void objectDestroyed(QDeclarative1StateOperation *) {
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<QDeclarative1StateOperation> *prop, QDeclarative1StateOperation *op) {
219         QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
220         op->setState(qobject_cast<QDeclarative1State*>(prop->object));
221         list->append(OperationGuard(op, list));
222     }
223     static void operations_clear(QDeclarativeListProperty<QDeclarative1StateOperation> *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<QDeclarative1StateOperation> *prop) {
231         QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
232         return list->count();
233     }
234     static QDeclarative1StateOperation *operations_at(QDeclarativeListProperty<QDeclarative1StateOperation> *prop, int index) {
235         QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
236         return list->at(index);
237     }
238
239     QDeclarative1TransitionManager transitionManager;
240
241     SimpleActionList revertList;
242     QList<QDeclarativeProperty> reverting;
243     QString extends;
244     mutable bool inState;
245     QDeclarative1StateGroup *group;
246
247     QDeclarative1StateOperation::ActionList generateActionList(QDeclarative1StateGroup *) const;
248     void complete();
249 };
250
251 QT_END_NAMESPACE
252
253 #endif // QDECLARATIVESTATE_P_H