1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKSTATE_H
41#define QQUICKSTATE_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <qqml.h>
55#include <qqmlproperty.h>
56#include <QtCore/qobject.h>
57#include <QtCore/qsharedpointer.h>
58#include <private/qtquickglobal_p.h>
59#include <private/qqmlabstractbinding_p.h>
60
61QT_BEGIN_NAMESPACE
62
63class QQuickStateActionEvent;
64class QQmlBinding;
65class QQmlExpression;
66
67class Q_QUICK_PRIVATE_EXPORT QQuickStateAction
68{
69public:
70 QQuickStateAction();
71 QQuickStateAction(QObject *, const QString &, const QVariant &);
72 QQuickStateAction(QObject *, const QQmlProperty &property, const QString &,
73 const QVariant &);
74
75 bool restore:1;
76 bool actionDone:1;
77 bool reverseEvent:1;
78 bool deletableToBinding:1;
79
80 QQmlProperty property;
81 QVariant fromValue;
82 QVariant toValue;
83
84 QQmlAbstractBinding::Ptr fromBinding;
85 QQmlAbstractBinding::Ptr toBinding;
86 QQuickStateActionEvent *event;
87
88 //strictly for matching
89 QObject *specifiedObject;
90 QString specifiedProperty;
91
92 void deleteFromBinding();
93};
94
95class Q_AUTOTEST_EXPORT QQuickStateActionEvent
96{
97public:
98 virtual ~QQuickStateActionEvent();
99
100 enum EventType { Script, SignalHandler, ParentChange, AnchorChanges };
101
102 virtual EventType type() const = 0;
103
104 virtual void execute();
105 virtual bool isReversable();
106 virtual void reverse();
107 virtual void saveOriginals() {}
108 virtual bool needsCopy() { return false; }
109 virtual void copyOriginals(QQuickStateActionEvent *) {}
110
111 virtual bool isRewindable() { return isReversable(); }
112 virtual void rewind() {}
113 virtual void saveCurrentValues() {}
114 virtual void saveTargetValues() {}
115
116 virtual bool changesBindings();
117 virtual void clearBindings();
118 virtual bool mayOverride(QQuickStateActionEvent*other);
119};
120
121//### rename to QQuickStateChange?
122class QQuickStateGroup;
123class QQuickState;
124class QQuickStateOperationPrivate;
125class Q_QUICK_PRIVATE_EXPORT QQuickStateOperation : public QObject
126{
127 Q_OBJECT
128public:
129 QQuickStateOperation(QObject *parent = nullptr)
130 : QObject(parent) {}
131 typedef QList<QQuickStateAction> ActionList;
132
133 virtual ActionList actions();
134
135 QQuickState *state() const;
136 void setState(QQuickState *state);
137
138protected:
139 QQuickStateOperation(QObjectPrivate &dd, QObject *parent = nullptr);
140
141private:
142 Q_DECLARE_PRIVATE(QQuickStateOperation)
143 Q_DISABLE_COPY(QQuickStateOperation)
144};
145
146typedef QQuickStateOperation::ActionList QQuickStateActions;
147
148class QQuickTransition;
149class QQuickStatePrivate;
150class Q_QUICK_PRIVATE_EXPORT QQuickState : public QObject
151{
152 Q_OBJECT
153
154 Q_PROPERTY(QString name READ name WRITE setName)
155 Q_PROPERTY(bool when READ when WRITE setWhen)
156 Q_PROPERTY(QString extend READ extends WRITE setExtends)
157 Q_PROPERTY(QQmlListProperty<QQuickStateOperation> changes READ changes)
158 Q_CLASSINFO("DefaultProperty", "changes")
159 Q_CLASSINFO("DeferredPropertyNames", "changes")
160
161public:
162 QQuickState(QObject *parent=nullptr);
163 ~QQuickState() override;
164
165 QString name() const;
166 void setName(const QString &);
167 bool isNamed() const;
168
169 bool isWhenKnown() const;
170 bool when() const;
171 void setWhen(bool);
172
173 QString extends() const;
174 void setExtends(const QString &);
175
176 QQmlListProperty<QQuickStateOperation> changes();
177 int operationCount() const;
178 QQuickStateOperation *operationAt(int) const;
179
180 QQuickState &operator<<(QQuickStateOperation *);
181
182 void apply(QQuickTransition *, QQuickState *revert);
183 void cancel();
184
185 QQuickStateGroup *stateGroup() const;
186 void setStateGroup(QQuickStateGroup *);
187
188 bool containsPropertyInRevertList(QObject *target, const QString &name) const;
189 bool changeValueInRevertList(QObject *target, const QString &name, const QVariant &revertValue);
190 bool changeBindingInRevertList(QObject *target, const QString &name, QQmlAbstractBinding *binding);
191 bool removeEntryFromRevertList(QObject *target, const QString &name);
192 void addEntryToRevertList(const QQuickStateAction &action);
193 void removeAllEntriesFromRevertList(QObject *target);
194 void addEntriesToRevertList(const QList<QQuickStateAction> &actions);
195 QVariant valueInRevertList(QObject *target, const QString &name) const;
196 QQmlAbstractBinding *bindingInRevertList(QObject *target, const QString &name) const;
197
198 bool isStateActive() const;
199
200Q_SIGNALS:
201 void completed();
202
203private:
204 Q_DECLARE_PRIVATE(QQuickState)
205 Q_DISABLE_COPY(QQuickState)
206};
207
208QT_END_NAMESPACE
209
210QML_DECLARE_TYPE(QQuickStateOperation)
211QML_DECLARE_TYPE(QQuickState)
212
213#endif // QQUICKSTATE_H
214