Initial bundle support
[profile/ivi/qtdeclarative.git] / src / quick / util / qquickstate_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 QtQml 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 QQUICKSTATE_H
43 #define QQUICKSTATE_H
44
45 #include <qqml.h>
46 #include <qqmlproperty.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 QQuickActionEvent;
56 class QQmlAbstractBinding;
57 class QQmlBinding;
58 class QQmlExpression;
59 class Q_QUICK_PRIVATE_EXPORT QQuickAction
60 {
61 public:
62     QQuickAction();
63     QQuickAction(QObject *, const QString &, const QVariant &);
64     QQuickAction(QObject *, const QString &,
65                        QQmlContext *, const QVariant &);
66
67     bool restore:1;
68     bool actionDone:1;
69     bool reverseEvent:1;
70     bool deletableToBinding:1;
71
72     QQmlProperty property;
73     QVariant fromValue;
74     QVariant toValue;
75
76     QQmlAbstractBinding *fromBinding;
77     QWeakPointer<QQmlAbstractBinding> toBinding;
78     QQuickActionEvent *event;
79
80     //strictly for matching
81     QObject *specifiedObject;
82     QString specifiedProperty;
83
84     void deleteFromBinding();
85 };
86
87 class Q_AUTOTEST_EXPORT QQuickActionEvent
88 {
89 public:
90     virtual ~QQuickActionEvent();
91
92     enum EventType { Script, SignalHandler, ParentChange, AnchorChanges };
93     enum Reason { ActualChange, FastForward };
94
95     virtual EventType type() const = 0;
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(QQuickActionEvent *) {}
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(QQuickActionEvent*other);
112 };
113
114 //### rename to QQuickStateChange?
115 class QQuickStateGroup;
116 class QQuickState;
117 class QQuickStateOperationPrivate;
118 class Q_QUICK_EXPORT QQuickStateOperation : public QObject
119 {
120     Q_OBJECT
121 public:
122     QQuickStateOperation(QObject *parent = 0)
123         : QObject(parent) {}
124     typedef QList<QQuickAction> ActionList;
125
126     virtual ActionList actions();
127
128     QQuickState *state() const;
129     void setState(QQuickState *state);
130
131 protected:
132     QQuickStateOperation(QObjectPrivate &dd, QObject *parent = 0);
133
134 private:
135     Q_DECLARE_PRIVATE(QQuickStateOperation)
136     Q_DISABLE_COPY(QQuickStateOperation)
137 };
138
139 typedef QQuickStateOperation::ActionList QQuickStateActions;
140
141 class QQuickTransition;
142 class QQuickStatePrivate;
143 class Q_QUICK_EXPORT QQuickState : public QObject
144 {
145     Q_OBJECT
146
147     Q_PROPERTY(QString name READ name WRITE setName)
148     Q_PROPERTY(QQmlBinding *when READ when WRITE setWhen)
149     Q_PROPERTY(QString extend READ extends WRITE setExtends)
150     Q_PROPERTY(QQmlListProperty<QQuickStateOperation> changes READ changes)
151     Q_CLASSINFO("DefaultProperty", "changes")
152     Q_CLASSINFO("DeferredPropertyNames", "changes")
153
154 public:
155     QQuickState(QObject *parent=0);
156     virtual ~QQuickState();
157
158     QString name() const;
159     void setName(const QString &);
160     bool isNamed() const;
161
162     /*'when' is a QQmlBinding to limit state changes oscillation
163      due to the unpredictable order of evaluation of bound expressions*/
164     bool isWhenKnown() const;
165     QQmlBinding *when() const;
166     void setWhen(QQmlBinding *);
167
168     QString extends() const;
169     void setExtends(const QString &);
170
171     QQmlListProperty<QQuickStateOperation> changes();
172     int operationCount() const;
173     QQuickStateOperation *operationAt(int) const;
174
175     QQuickState &operator<<(QQuickStateOperation *);
176
177     void apply(QQuickTransition *, QQuickState *revert);
178     void cancel();
179
180     QQuickStateGroup *stateGroup() const;
181     void setStateGroup(QQuickStateGroup *);
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, QQmlAbstractBinding *binding);
186     bool removeEntryFromRevertList(QObject *target, const QString &name);
187     void addEntryToRevertList(const QQuickAction &action);
188     void removeAllEntriesFromRevertList(QObject *target);
189     void addEntriesToRevertList(const QList<QQuickAction> &actions);
190     QVariant valueInRevertList(QObject *target, const QString &name) const;
191     QQmlAbstractBinding *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(QQuickState)
200     Q_DISABLE_COPY(QQuickState)
201 };
202
203 QT_END_NAMESPACE
204
205 QML_DECLARE_TYPE(QQuickStateOperation)
206 QML_DECLARE_TYPE(QQuickState)
207
208 QT_END_HEADER
209
210 #endif // QQUICKSTATE_H