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 | |
61 | QT_BEGIN_NAMESPACE |
62 | |
63 | class QQuickStateActionEvent; |
64 | class QQmlBinding; |
65 | class QQmlExpression; |
66 | |
67 | class Q_QUICK_PRIVATE_EXPORT QQuickStateAction |
68 | { |
69 | public: |
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 | |
95 | class Q_AUTOTEST_EXPORT QQuickStateActionEvent |
96 | { |
97 | public: |
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? |
122 | class QQuickStateGroup; |
123 | class QQuickState; |
124 | class QQuickStateOperationPrivate; |
125 | class Q_QUICK_PRIVATE_EXPORT QQuickStateOperation : public QObject |
126 | { |
127 | Q_OBJECT |
128 | QML_ANONYMOUS |
129 | public: |
130 | QQuickStateOperation(QObject *parent = nullptr) |
131 | : QObject(parent) {} |
132 | typedef QList<QQuickStateAction> ActionList; |
133 | |
134 | virtual ActionList actions(); |
135 | |
136 | QQuickState *state() const; |
137 | void setState(QQuickState *state); |
138 | |
139 | protected: |
140 | QQuickStateOperation(QObjectPrivate &dd, QObject *parent = nullptr); |
141 | |
142 | private: |
143 | Q_DECLARE_PRIVATE(QQuickStateOperation) |
144 | Q_DISABLE_COPY(QQuickStateOperation) |
145 | }; |
146 | |
147 | typedef QQuickStateOperation::ActionList QQuickStateActions; |
148 | |
149 | class QQuickTransition; |
150 | class QQuickStatePrivate; |
151 | class Q_QUICK_PRIVATE_EXPORT QQuickState : public QObject |
152 | { |
153 | Q_OBJECT |
154 | |
155 | Q_PROPERTY(QString name READ name WRITE setName) |
156 | Q_PROPERTY(bool when READ when WRITE setWhen) |
157 | Q_PROPERTY(QString extend READ extends WRITE setExtends) |
158 | Q_PROPERTY(QQmlListProperty<QQuickStateOperation> changes READ changes) |
159 | Q_CLASSINFO("DefaultProperty" , "changes" ) |
160 | Q_CLASSINFO("DeferredPropertyNames" , "changes" ) |
161 | QML_NAMED_ELEMENT(State) |
162 | |
163 | public: |
164 | QQuickState(QObject *parent=nullptr); |
165 | ~QQuickState() override; |
166 | |
167 | QString name() const; |
168 | void setName(const QString &); |
169 | bool isNamed() const; |
170 | |
171 | bool isWhenKnown() const; |
172 | bool when() const; |
173 | void setWhen(bool); |
174 | |
175 | QString extends() const; |
176 | void setExtends(const QString &); |
177 | |
178 | QQmlListProperty<QQuickStateOperation> changes(); |
179 | int operationCount() const; |
180 | QQuickStateOperation *operationAt(int) const; |
181 | |
182 | QQuickState &operator<<(QQuickStateOperation *); |
183 | |
184 | void apply(QQuickTransition *, QQuickState *revert); |
185 | void cancel(); |
186 | |
187 | QQuickStateGroup *stateGroup() const; |
188 | void setStateGroup(QQuickStateGroup *); |
189 | |
190 | bool containsPropertyInRevertList(QObject *target, const QString &name) const; |
191 | bool changeValueInRevertList(QObject *target, const QString &name, const QVariant &revertValue); |
192 | bool changeBindingInRevertList(QObject *target, const QString &name, QQmlAbstractBinding *binding); |
193 | bool removeEntryFromRevertList(QObject *target, const QString &name); |
194 | void addEntryToRevertList(const QQuickStateAction &action); |
195 | void removeAllEntriesFromRevertList(QObject *target); |
196 | void addEntriesToRevertList(const QList<QQuickStateAction> &actions); |
197 | QVariant valueInRevertList(QObject *target, const QString &name) const; |
198 | QQmlAbstractBinding *bindingInRevertList(QObject *target, const QString &name) const; |
199 | |
200 | bool isStateActive() const; |
201 | |
202 | Q_SIGNALS: |
203 | void completed(); |
204 | |
205 | private: |
206 | Q_DECLARE_PRIVATE(QQuickState) |
207 | Q_DISABLE_COPY(QQuickState) |
208 | }; |
209 | |
210 | QT_END_NAMESPACE |
211 | |
212 | QML_DECLARE_TYPE(QQuickStateOperation) |
213 | QML_DECLARE_TYPE(QQuickState) |
214 | |
215 | #endif // QQUICKSTATE_H |
216 | |