a7bd36d110ee26aec95e8503a9804fe52f380aea
[profile/ivi/qtdeclarative.git] / src / quick / 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 <qdeclarative.h>
46 #include <qdeclarativeproperty.h>
47 #include <QtCore/qobject.h>
48 #include <QtCore/qsharedpointer.h>
49 #include <private/qtquickglobal_p.h>
50
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
54
55 class QDeclarativeActionEvent;
56 class QDeclarativeAbstractBinding;
57 class QDeclarativeBinding;
58 class QDeclarativeExpression;
59 class Q_QUICK_PRIVATE_EXPORT QDeclarativeAction
60 {
61 public:
62     QDeclarativeAction();
63     QDeclarativeAction(QObject *, const QString &, const QVariant &);
64     QDeclarativeAction(QObject *, const QString &,
65                        QDeclarativeContext *, const QVariant &);
66
67     bool restore:1;
68     bool actionDone:1;
69     bool reverseEvent:1;
70     bool deletableToBinding:1;
71
72     QDeclarativeProperty property;
73     QVariant fromValue;
74     QVariant toValue;
75
76     QDeclarativeAbstractBinding *fromBinding;
77     QWeakPointer<QDeclarativeAbstractBinding> toBinding;
78     QDeclarativeActionEvent *event;
79
80     //strictly for matching
81     QObject *specifiedObject;
82     QString specifiedProperty;
83
84     void deleteFromBinding();
85 };
86
87 class Q_AUTOTEST_EXPORT QDeclarativeActionEvent
88 {
89 public:
90     virtual ~QDeclarativeActionEvent();
91     virtual QString typeName() const;
92
93     enum Reason { ActualChange, FastForward };
94
95     virtual void execute(Reason reason = ActualChange);
96     virtual bool isReversable();
97     virtual void reverse(Reason reason = ActualChange);
98     virtual void saveOriginals() {}
99     virtual bool needsCopy() { return false; }
100     virtual void copyOriginals(QDeclarativeActionEvent *) {}
101
102     virtual bool isRewindable() { return isReversable(); }
103     virtual void rewind() {}
104     virtual void saveCurrentValues() {}
105     virtual void saveTargetValues() {}
106
107     virtual bool changesBindings();
108     virtual void clearBindings();
109     virtual bool override(QDeclarativeActionEvent*other);
110 };
111
112 //### rename to QDeclarativeStateChange?
113 class QDeclarativeStateGroup;
114 class QDeclarativeState;
115 class QDeclarativeStateOperationPrivate;
116 class Q_QUICK_EXPORT QDeclarativeStateOperation : public QObject
117 {
118     Q_OBJECT
119 public:
120     QDeclarativeStateOperation(QObject *parent = 0)
121         : QObject(parent) {}
122     typedef QList<QDeclarativeAction> ActionList;
123
124     virtual ActionList actions();
125
126     QDeclarativeState *state() const;
127     void setState(QDeclarativeState *state);
128
129 protected:
130     QDeclarativeStateOperation(QObjectPrivate &dd, QObject *parent = 0);
131
132 private:
133     Q_DECLARE_PRIVATE(QDeclarativeStateOperation)
134     Q_DISABLE_COPY(QDeclarativeStateOperation)
135 };
136
137 typedef QDeclarativeStateOperation::ActionList QDeclarativeStateActions;
138
139 class QDeclarativeTransition;
140 class QDeclarativeStatePrivate;
141 class Q_QUICK_EXPORT QDeclarativeState : public QObject
142 {
143     Q_OBJECT
144
145     Q_PROPERTY(QString name READ name WRITE setName)
146     Q_PROPERTY(QDeclarativeBinding *when READ when WRITE setWhen)
147     Q_PROPERTY(QString extend READ extends WRITE setExtends)
148     Q_PROPERTY(QDeclarativeListProperty<QDeclarativeStateOperation> changes READ changes)
149     Q_CLASSINFO("DefaultProperty", "changes")
150     Q_CLASSINFO("DeferredPropertyNames", "changes")
151
152 public:
153     QDeclarativeState(QObject *parent=0);
154     virtual ~QDeclarativeState();
155
156     QString name() const;
157     void setName(const QString &);
158     bool isNamed() const;
159
160     /*'when' is a QDeclarativeBinding to limit state changes oscillation
161      due to the unpredictable order of evaluation of bound expressions*/
162     bool isWhenKnown() const;
163     QDeclarativeBinding *when() const;
164     void setWhen(QDeclarativeBinding *);
165
166     QString extends() const;
167     void setExtends(const QString &);
168
169     QDeclarativeListProperty<QDeclarativeStateOperation> changes();
170     int operationCount() const;
171     QDeclarativeStateOperation *operationAt(int) const;
172
173     QDeclarativeState &operator<<(QDeclarativeStateOperation *);
174
175     void apply(QDeclarativeTransition *, QDeclarativeState *revert);
176     void cancel();
177
178     QDeclarativeStateGroup *stateGroup() const;
179     void setStateGroup(QDeclarativeStateGroup *);
180
181     bool containsPropertyInRevertList(QObject *target, const QString &name) const;
182     bool changeValueInRevertList(QObject *target, const QString &name, const QVariant &revertValue);
183     bool changeBindingInRevertList(QObject *target, const QString &name, QDeclarativeAbstractBinding *binding);
184     bool removeEntryFromRevertList(QObject *target, const QString &name);
185     void addEntryToRevertList(const QDeclarativeAction &action);
186     void removeAllEntriesFromRevertList(QObject *target);
187     void addEntriesToRevertList(const QList<QDeclarativeAction> &actions);
188     QVariant valueInRevertList(QObject *target, const QString &name) const;
189     QDeclarativeAbstractBinding *bindingInRevertList(QObject *target, const QString &name) const;
190
191     bool isStateActive() const;
192
193 Q_SIGNALS:
194     void completed();
195
196 private:
197     Q_DECLARE_PRIVATE(QDeclarativeState)
198     Q_DISABLE_COPY(QDeclarativeState)
199 };
200
201 QT_END_NAMESPACE
202
203 QML_DECLARE_TYPE(QDeclarativeStateOperation)
204 QML_DECLARE_TYPE(QDeclarativeState)
205
206 QT_END_HEADER
207
208 #endif // QDECLARATIVESTATE_H