1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QDECLARATIVESTATE_H
43 #define QDECLARATIVESTATE_H
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>
55 class QDeclarativeAbstractBinding;
56 class QDeclarativeBinding;
57 class QDeclarativeExpression;
60 class QDeclarative1ActionEvent;
61 class Q_QTQUICK1_EXPORT QDeclarative1Action
64 QDeclarative1Action();
65 QDeclarative1Action(QObject *, const QString &, const QVariant &);
66 QDeclarative1Action(QObject *, const QString &,
67 QDeclarativeContext *, const QVariant &);
72 bool deletableToBinding:1;
74 QDeclarativeProperty property;
78 QDeclarativeAbstractBinding *fromBinding;
79 QWeakPointer<QDeclarativeAbstractBinding> toBinding;
80 QDeclarative1ActionEvent *event;
82 //strictly for matching
83 QObject *specifiedObject;
84 QString specifiedProperty;
86 void deleteFromBinding();
89 class Q_AUTOTEST_EXPORT QDeclarative1ActionEvent
92 virtual ~QDeclarative1ActionEvent();
93 virtual QString typeName() const;
95 enum Reason { ActualChange, FastForward };
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 *) {}
104 virtual bool isRewindable() { return isReversable(); }
105 virtual void rewind() {}
106 virtual void saveCurrentValues() {}
107 virtual void saveTargetValues() {}
109 virtual bool changesBindings();
110 virtual void clearBindings();
111 virtual bool override(QDeclarative1ActionEvent*other);
114 //### rename to QDeclarative1StateChange?
115 class QDeclarative1StateGroup;
116 class QDeclarative1State;
117 class QDeclarative1StateOperationPrivate;
118 class Q_QTQUICK1_EXPORT QDeclarative1StateOperation : public QObject
122 QDeclarative1StateOperation(QObject *parent = 0)
124 typedef QList<QDeclarative1Action> ActionList;
126 virtual ActionList actions();
128 QDeclarative1State *state() const;
129 void setState(QDeclarative1State *state);
132 QDeclarative1StateOperation(QObjectPrivate &dd, QObject *parent = 0);
135 Q_DECLARE_PRIVATE(QDeclarative1StateOperation)
136 Q_DISABLE_COPY(QDeclarative1StateOperation)
139 typedef QDeclarative1StateOperation::ActionList QDeclarative1StateActions;
141 class QDeclarative1Transition;
142 class QDeclarative1StatePrivate;
143 class Q_QTQUICK1_EXPORT QDeclarative1State : public QObject
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")
155 QDeclarative1State(QObject *parent=0);
156 virtual ~QDeclarative1State();
158 QString name() const;
159 void setName(const QString &);
160 bool isNamed() const;
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 *);
168 QString extends() const;
169 void setExtends(const QString &);
171 QDeclarativeListProperty<QDeclarative1StateOperation> changes();
172 int operationCount() const;
173 QDeclarative1StateOperation *operationAt(int) const;
175 QDeclarative1State &operator<<(QDeclarative1StateOperation *);
177 void apply(QDeclarative1StateGroup *, QDeclarative1Transition *, QDeclarative1State *revert);
180 QDeclarative1StateGroup *stateGroup() const;
181 void setStateGroup(QDeclarative1StateGroup *);
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;
193 bool isStateActive() const;
199 Q_DECLARE_PRIVATE(QDeclarative1State)
200 Q_DISABLE_COPY(QDeclarative1State)
205 QML_DECLARE_TYPE(QDeclarative1StateOperation)
206 QML_DECLARE_TYPE(QDeclarative1State)
210 #endif // QDECLARATIVESTATE_H