1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKITEMVIEWTRANSITION_P_P_H
5#define QQUICKITEMVIEWTRANSITION_P_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick/private/qtquickglobal_p.h>
19
20QT_REQUIRE_CONFIG(quick_viewtransitions);
21
22#include <QtCore/qobject.h>
23#include <QtCore/qpoint.h>
24#include <QtQml/qqml.h>
25#include <private/qqmlguard_p.h>
26#include <private/qquicktransition_p.h>
27#include <private/qanimationjobutil_p.h>
28
29QT_BEGIN_NAMESPACE
30
31class QQuickItem;
32class QQuickTransition;
33class QQuickItemViewTransitionableItem;
34class QQuickItemViewTransitionJob;
35
36
37class Q_QUICK_PRIVATE_EXPORT QQuickItemViewTransitionChangeListener
38{
39public:
40 QQuickItemViewTransitionChangeListener() {}
41 virtual ~QQuickItemViewTransitionChangeListener() {}
42
43 virtual void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) = 0;
44};
45
46
47class Q_QUICK_PRIVATE_EXPORT QQuickItemViewTransitioner
48{
49public:
50 enum TransitionType {
51 NoTransition,
52 PopulateTransition,
53 AddTransition,
54 MoveTransition,
55 RemoveTransition
56 };
57
58 QQuickItemViewTransitioner();
59 virtual ~QQuickItemViewTransitioner();
60
61 bool canTransition(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const;
62 void transitionNextReposition(QQuickItemViewTransitionableItem *item, QQuickItemViewTransitioner::TransitionType type, bool isTarget);
63
64 void addToTargetLists(QQuickItemViewTransitioner::TransitionType type, QQuickItemViewTransitionableItem *item, int index);
65 void resetTargetLists();
66
67 QQuickTransition *transitionObject(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const;
68 const QList<int> &targetIndexes(QQuickItemViewTransitioner::TransitionType type) const;
69 const QList<QObject *> &targetItems(QQuickItemViewTransitioner::TransitionType type) const;
70
71 inline void setPopulateTransitionEnabled(bool b) { usePopulateTransition = b; }
72 inline bool populateTransitionEnabled() const { return usePopulateTransition; }
73
74 inline void setChangeListener(QQuickItemViewTransitionChangeListener *obj) { changeListener = obj; }
75
76 QSet<QQuickItemViewTransitionJob *> runningJobs;
77
78 QList<int> addTransitionIndexes;
79 QList<int> moveTransitionIndexes;
80 QList<int> removeTransitionIndexes;
81 QList<QObject *> addTransitionTargets;
82 QList<QObject *> moveTransitionTargets;
83 QList<QObject *> removeTransitionTargets;
84
85 QQmlGuard<QQuickTransition> populateTransition;
86 QQmlGuard<QQuickTransition> addTransition;
87 QQmlGuard<QQuickTransition> addDisplacedTransition;
88 QQmlGuard<QQuickTransition> moveTransition;
89 QQmlGuard<QQuickTransition> moveDisplacedTransition;
90 QQmlGuard<QQuickTransition> removeTransition;
91 QQmlGuard<QQuickTransition> removeDisplacedTransition;
92 QQmlGuard<QQuickTransition> displacedTransition;
93
94private:
95 friend class QQuickItemViewTransitionJob;
96
97 QQuickItemViewTransitionChangeListener *changeListener;
98 bool usePopulateTransition;
99
100 void finishedTransition(QQuickItemViewTransitionJob *job, QQuickItemViewTransitionableItem *item);
101};
102
103
104/*
105 An item that can be transitioned using QQuickViewTransitionJob.
106 */
107class Q_QUICK_PRIVATE_EXPORT QQuickItemViewTransitionableItem
108{
109public:
110 QQuickItemViewTransitionableItem(QQuickItem *i);
111 virtual ~QQuickItemViewTransitionableItem();
112
113 qreal itemX() const;
114 qreal itemY() const;
115
116 void moveTo(const QPointF &pos, bool immediate = false);
117
118 bool transitionScheduledOrRunning() const;
119 bool transitionRunning() const;
120 bool isPendingRemoval() const;
121
122 bool prepareTransition(QQuickItemViewTransitioner *transitioner, int index, const QRectF &viewBounds);
123 void startTransition(QQuickItemViewTransitioner *transitioner, int index);
124 void completeTransition(QQuickTransition *quickTransition);
125
126 SelfDeletable m_selfDeletable;
127 QPointF nextTransitionTo;
128 QPointF lastMovedTo;
129 QPointF nextTransitionFrom;
130 QQuickItem *item;
131 QQuickItemViewTransitionJob *transition;
132 QQuickItemViewTransitioner::TransitionType nextTransitionType;
133 bool isTransitionTarget : 1;
134 bool nextTransitionToSet : 1;
135 bool nextTransitionFromSet : 1;
136 bool lastMovedToSet : 1;
137 bool prepared : 1;
138
139private:
140 friend class QQuickItemViewTransitioner;
141 friend class QQuickItemViewTransitionJob;
142 void setNextTransition(QQuickItemViewTransitioner::TransitionType, bool isTargetItem);
143 bool transitionWillChangePosition() const;
144 void finishedTransition();
145 void resetNextTransitionPos();
146 void clearCurrentScheduledTransition();
147 void stopTransition();
148};
149
150
151class QQuickViewTransitionAttached : public QObject
152{
153 Q_OBJECT
154
155 Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL)
156 Q_PROPERTY(QQuickItem* item READ item NOTIFY itemChanged FINAL)
157 Q_PROPERTY(QPointF destination READ destination NOTIFY destinationChanged FINAL)
158
159 Q_PROPERTY(QList<int> targetIndexes READ targetIndexes NOTIFY targetIndexesChanged FINAL)
160 Q_PROPERTY(QQmlListProperty<QObject> targetItems READ targetItems NOTIFY targetItemsChanged FINAL)
161
162 QML_NAMED_ELEMENT(ViewTransition)
163 QML_ADDED_IN_VERSION(2, 0)
164 QML_UNCREATABLE("ViewTransition is only available via attached properties.")
165 QML_ATTACHED(QQuickViewTransitionAttached)
166
167public:
168 QQuickViewTransitionAttached(QObject *parent);
169
170 int index() const { return m_index; }
171 QQuickItem *item() const { return m_item; }
172 QPointF destination() const { return m_destination; }
173
174 QList<int> targetIndexes() const { return m_targetIndexes; }
175 QQmlListProperty<QObject> targetItems();
176
177 static QQuickViewTransitionAttached *qmlAttachedProperties(QObject *);
178
179Q_SIGNALS:
180 void indexChanged();
181 void itemChanged();
182 void destinationChanged();
183
184 void targetIndexesChanged();
185 void targetItemsChanged();
186
187private:
188 friend class QQuickItemViewTransitionJob;
189 QPointF m_destination;
190 QList<int> m_targetIndexes;
191 QList<QObject *> m_targetItems;
192
193 QPointer<QQuickItem> m_item;
194 int m_index;
195};
196
197QT_END_NAMESPACE
198
199QML_DECLARE_TYPE(QQuickViewTransitionAttached)
200
201#endif // QQUICKITEMVIEWTRANSITION_P_P_H
202

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