c6f3e22120394111f3a5d00d0d2a2b238274ae1e
[profile/ivi/qtdeclarative.git] / src / qtquick1 / util / qdeclarativestate_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVESTATE_H
43 #define QDECLARATIVESTATE_H
44
45 #include <QtDeclarative/qdeclarative.h>
46 #include <QtDeclarative/qdeclarativeproperty.h>
47 #include <QtCore/qobject.h>
48 #include <QtCore/qsharedpointer.h>
49 #include <QtDeclarative/private/qdeclarativeglobal_p.h>
50
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
54
55 class QDeclarativeAbstractBinding;
56 class QDeclarativeBinding;
57 class QDeclarativeExpression;
58
59
60 class QDeclarative1ActionEvent;
61 class Q_QTQUICK1_EXPORT QDeclarative1Action
62 {
63 public:
64     QDeclarative1Action();
65     QDeclarative1Action(QObject *, const QString &, const QVariant &);
66     QDeclarative1Action(QObject *, const QString &,
67                        QDeclarativeContext *, const QVariant &);
68
69     bool restore:1;
70     bool actionDone:1;
71     bool reverseEvent:1;
72     bool deletableToBinding:1;
73
74     QDeclarativeProperty property;
75     QVariant fromValue;
76     QVariant toValue;
77
78     QDeclarativeAbstractBinding *fromBinding;
79     QWeakPointer<QDeclarativeAbstractBinding> toBinding;
80     QDeclarative1ActionEvent *event;
81
82     //strictly for matching
83     QObject *specifiedObject;
84     QString specifiedProperty;
85
86     void deleteFromBinding();
87 };
88
89 class Q_AUTOTEST_EXPORT QDeclarative1ActionEvent
90 {
91 public:
92     virtual ~QDeclarative1ActionEvent();
93     virtual QString typeName() const;
94
95     enum Reason { ActualChange, FastForward };
96
97     virtual void execute(Reason reason = ActualChange);
98     virtual bool isReversable();
99     virtual void reverse(Reason reason = ActualChange);
100     virtual void saveOriginals() {}
101     virtual bool needsCopy() { return false; }
102     virtual void copyOriginals(QDeclarative1ActionEvent *) {}
103
104     virtual bool isRewindable() { return isReversable(); }
105     virtual void rewind() {}
106     virtual void saveCurrentValues() {}
107     virtual void saveTargetValues() {}
108
109     virtual bool changesBindings();
110     virtual void clearBindings();
111     virtual bool override(QDeclarative1ActionEvent*other);
112 };
113
114 //### rename to QDeclarative1StateChange?
115 class QDeclarative1StateGroup;
116 class QDeclarative1State;
117 class QDeclarative1StateOperationPrivate;
118 class Q_QTQUICK1_EXPORT QDeclarative1StateOperation : public QObject
119 {
120     Q_OBJECT
121 public:
122     QDeclarative1StateOperation(QObject *parent = 0)
123         : QObject(parent) {}
124     typedef QList<QDeclarative1Action> ActionList;
125
126     virtual ActionList actions();
127
128     QDeclarative1State *state() const;
129     void setState(QDeclarative1State *state);
130
131 protected:
132     QDeclarative1StateOperation(QObjectPrivate &dd, QObject *parent = 0);
133
134 private:
135     Q_DECLARE_PRIVATE(QDeclarative1StateOperation)
136     Q_DISABLE_COPY(QDeclarative1StateOperation)
137 };
138
139 typedef QDeclarative1StateOperation::ActionList QDeclarative1StateActions;
140
141 class QDeclarative1Transition;
142 class QDeclarative1StatePrivate;
143 class Q_QTQUICK1_EXPORT QDeclarative1State : public QObject
144 {
145     Q_OBJECT
146
147     Q_PROPERTY(QString name READ name WRITE setName)
148     Q_PROPERTY(QDeclarativeBinding *when READ when WRITE setWhen)
149     Q_PROPERTY(QString extend READ extends WRITE setExtends)
150     Q_PROPERTY(QDeclarativeListProperty<QDeclarative1StateOperation> changes READ changes)
151     Q_CLASSINFO("DefaultProperty", "changes")
152     Q_CLASSINFO("DeferredPropertyNames", "changes")
153
154 public:
155     QDeclarative1State(QObject *parent=0);
156     virtual ~QDeclarative1State();
157
158     QString name() const;
159     void setName(const QString &);
160     bool isNamed() const;
161
162     /*'when' is a QDeclarativeBinding to limit state changes oscillation
163      due to the unpredictable order of evaluation of bound expressions*/
164     bool isWhenKnown() const;
165     QDeclarativeBinding *when() const;
166     void setWhen(QDeclarativeBinding *);
167
168     QString extends() const;
169     void setExtends(const QString &);
170
171     QDeclarativeListProperty<QDeclarative1StateOperation> changes();
172     int operationCount() const;
173     QDeclarative1StateOperation *operationAt(int) const;
174
175     QDeclarative1State &operator<<(QDeclarative1StateOperation *);
176
177     void apply(QDeclarative1StateGroup *, QDeclarative1Transition *, QDeclarative1State *revert);
178     void cancel();
179
180     QDeclarative1StateGroup *stateGroup() const;
181     void setStateGroup(QDeclarative1StateGroup *);
182
183     bool containsPropertyInRevertList(QObject *target, const QString &name) const;
184     bool changeValueInRevertList(QObject *target, const QString &name, const QVariant &revertValue);
185     bool changeBindingInRevertList(QObject *target, const QString &name, QDeclarativeAbstractBinding *binding);
186     bool removeEntryFromRevertList(QObject *target, const QString &name);
187     void addEntryToRevertList(const QDeclarative1Action &action);
188     void removeAllEntriesFromRevertList(QObject *target);
189     void addEntriesToRevertList(const QList<QDeclarative1Action> &actions);
190     QVariant valueInRevertList(QObject *target, const QString &name) const;
191     QDeclarativeAbstractBinding *bindingInRevertList(QObject *target, const QString &name) const;
192
193     bool isStateActive() const;
194
195 Q_SIGNALS:
196     void completed();
197
198 private:
199     Q_DECLARE_PRIVATE(QDeclarative1State)
200     Q_DISABLE_COPY(QDeclarative1State)
201 };
202
203 QT_END_NAMESPACE
204
205 QML_DECLARE_TYPE(QDeclarative1StateOperation)
206 QML_DECLARE_TYPE(QDeclarative1State)
207
208 QT_END_HEADER
209
210 #endif // QDECLARATIVESTATE_H