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 QQUICKITEMVIEWTRANSITION_P_P_H
41#define QQUICKITEMVIEWTRANSITION_P_P_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 <QtQuick/private/qtquickglobal_p.h>
55
56QT_REQUIRE_CONFIG(quick_viewtransitions);
57
58#include <QtCore/qobject.h>
59#include <QtCore/qpoint.h>
60#include <QtQml/qqml.h>
61#include <private/qqmlguard_p.h>
62#include <private/qquicktransition_p.h>
63#include <private/qanimationjobutil_p.h>
64
65QT_BEGIN_NAMESPACE
66
67class QQuickItem;
68class QQuickTransition;
69class QQuickItemViewTransitionableItem;
70class QQuickItemViewTransitionJob;
71
72
73class Q_QUICK_PRIVATE_EXPORT QQuickItemViewTransitionChangeListener
74{
75public:
76 QQuickItemViewTransitionChangeListener() {}
77 virtual ~QQuickItemViewTransitionChangeListener() {}
78
79 virtual void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) = 0;
80};
81
82
83class Q_QUICK_PRIVATE_EXPORT QQuickItemViewTransitioner
84{
85public:
86 enum TransitionType {
87 NoTransition,
88 PopulateTransition,
89 AddTransition,
90 MoveTransition,
91 RemoveTransition
92 };
93
94 QQuickItemViewTransitioner();
95 virtual ~QQuickItemViewTransitioner();
96
97 bool canTransition(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const;
98 void transitionNextReposition(QQuickItemViewTransitionableItem *item, QQuickItemViewTransitioner::TransitionType type, bool isTarget);
99
100 void addToTargetLists(QQuickItemViewTransitioner::TransitionType type, QQuickItemViewTransitionableItem *item, int index);
101 void resetTargetLists();
102
103 QQuickTransition *transitionObject(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const;
104 const QList<int> &targetIndexes(QQuickItemViewTransitioner::TransitionType type) const;
105 const QList<QObject *> &targetItems(QQuickItemViewTransitioner::TransitionType type) const;
106
107 inline void setPopulateTransitionEnabled(bool b) { usePopulateTransition = b; }
108 inline bool populateTransitionEnabled() const { return usePopulateTransition; }
109
110 inline void setChangeListener(QQuickItemViewTransitionChangeListener *obj) { changeListener = obj; }
111
112 QSet<QQuickItemViewTransitionJob *> runningJobs;
113
114 QList<int> addTransitionIndexes;
115 QList<int> moveTransitionIndexes;
116 QList<int> removeTransitionIndexes;
117 QList<QObject *> addTransitionTargets;
118 QList<QObject *> moveTransitionTargets;
119 QList<QObject *> removeTransitionTargets;
120
121 QQmlGuard<QQuickTransition> populateTransition;
122 QQmlGuard<QQuickTransition> addTransition;
123 QQmlGuard<QQuickTransition> addDisplacedTransition;
124 QQmlGuard<QQuickTransition> moveTransition;
125 QQmlGuard<QQuickTransition> moveDisplacedTransition;
126 QQmlGuard<QQuickTransition> removeTransition;
127 QQmlGuard<QQuickTransition> removeDisplacedTransition;
128 QQmlGuard<QQuickTransition> displacedTransition;
129
130private:
131 friend class QQuickItemViewTransitionJob;
132
133 QQuickItemViewTransitionChangeListener *changeListener;
134 bool usePopulateTransition;
135
136 void finishedTransition(QQuickItemViewTransitionJob *job, QQuickItemViewTransitionableItem *item);
137};
138
139
140/*
141 An item that can be transitioned using QQuickViewTransitionJob.
142 */
143class Q_QUICK_PRIVATE_EXPORT QQuickItemViewTransitionableItem
144{
145public:
146 QQuickItemViewTransitionableItem(QQuickItem *i);
147 virtual ~QQuickItemViewTransitionableItem();
148
149 qreal itemX() const;
150 qreal itemY() const;
151
152 void moveTo(const QPointF &pos, bool immediate = false);
153
154 bool transitionScheduledOrRunning() const;
155 bool transitionRunning() const;
156 bool isPendingRemoval() const;
157
158 bool prepareTransition(QQuickItemViewTransitioner *transitioner, int index, const QRectF &viewBounds);
159 void startTransition(QQuickItemViewTransitioner *transitioner, int index);
160
161 SelfDeletable m_selfDeletable;
162 QPointF nextTransitionTo;
163 QPointF lastMovedTo;
164 QPointF nextTransitionFrom;
165 QQuickItem *item;
166 QQuickItemViewTransitionJob *transition;
167 QQuickItemViewTransitioner::TransitionType nextTransitionType;
168 bool isTransitionTarget : 1;
169 bool nextTransitionToSet : 1;
170 bool nextTransitionFromSet : 1;
171 bool lastMovedToSet : 1;
172 bool prepared : 1;
173
174private:
175 friend class QQuickItemViewTransitioner;
176 friend class QQuickItemViewTransitionJob;
177 void setNextTransition(QQuickItemViewTransitioner::TransitionType, bool isTargetItem);
178 bool transitionWillChangePosition() const;
179 void finishedTransition();
180 void resetNextTransitionPos();
181 void clearCurrentScheduledTransition();
182 void stopTransition();
183};
184
185
186class QQuickViewTransitionAttached : public QObject
187{
188 Q_OBJECT
189
190 Q_PROPERTY(int index READ index NOTIFY indexChanged)
191 Q_PROPERTY(QQuickItem* item READ item NOTIFY itemChanged)
192 Q_PROPERTY(QPointF destination READ destination NOTIFY destinationChanged)
193
194 Q_PROPERTY(QList<int> targetIndexes READ targetIndexes NOTIFY targetIndexesChanged)
195 Q_PROPERTY(QQmlListProperty<QObject> targetItems READ targetItems NOTIFY targetItemsChanged)
196
197 QML_NAMED_ELEMENT(ViewTransition)
198 QML_UNCREATABLE("ViewTransition is only available via attached properties.")
199 QML_ATTACHED(QQuickViewTransitionAttached)
200
201public:
202 QQuickViewTransitionAttached(QObject *parent);
203
204 int index() const { return m_index; }
205 QQuickItem *item() const;
206 QPointF destination() const { return m_destination; }
207
208 QList<int> targetIndexes() const { return m_targetIndexes; }
209 QQmlListProperty<QObject> targetItems();
210
211 static QQuickViewTransitionAttached *qmlAttachedProperties(QObject *);
212
213Q_SIGNALS:
214 void indexChanged();
215 void itemChanged();
216 void destinationChanged();
217
218 void targetIndexesChanged();
219 void targetItemsChanged();
220
221private:
222 friend class QQuickItemViewTransitionJob;
223 QPointF m_destination;
224 QList<int> m_targetIndexes;
225 QList<QObject *> m_targetItems;
226
227 QPointer<QQuickItem> m_item;
228 int m_index;
229};
230
231QT_END_NAMESPACE
232
233QML_DECLARE_TYPE(QQuickViewTransitionAttached)
234
235#endif // QQUICKITEMVIEWTRANSITION_P_P_H
236

source code of qtdeclarative/src/quick/items/qquickitemviewtransition_p.h