| 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 |  | 
| 20 | QT_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 |  | 
| 29 | #include <QtCore/qpointer.h> | 
| 30 |  | 
| 31 | QT_BEGIN_NAMESPACE | 
| 32 |  | 
| 33 | class QQuickItem; | 
| 34 | class QQuickTransition; | 
| 35 | class QQuickItemViewTransitionableItem; | 
| 36 | class QQuickItemViewTransitionJob; | 
| 37 |  | 
| 38 |  | 
| 39 | class Q_QUICK_EXPORT QQuickItemViewTransitionChangeListener | 
| 40 | { | 
| 41 | public: | 
| 42 |     QQuickItemViewTransitionChangeListener() {} | 
| 43 |     virtual ~QQuickItemViewTransitionChangeListener() {} | 
| 44 |  | 
| 45 |     virtual void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) = 0; | 
| 46 | }; | 
| 47 |  | 
| 48 |  | 
| 49 | class Q_QUICK_EXPORT QQuickItemViewTransitioner | 
| 50 | { | 
| 51 | public: | 
| 52 |     enum TransitionType { | 
| 53 |         NoTransition, | 
| 54 |         PopulateTransition, | 
| 55 |         AddTransition, | 
| 56 |         MoveTransition, | 
| 57 |         RemoveTransition | 
| 58 |     }; | 
| 59 |  | 
| 60 |     QQuickItemViewTransitioner(); | 
| 61 |     virtual ~QQuickItemViewTransitioner(); | 
| 62 |  | 
| 63 |     bool canTransition(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const; | 
| 64 |     void transitionNextReposition(QQuickItemViewTransitionableItem *item, QQuickItemViewTransitioner::TransitionType type, bool isTarget); | 
| 65 |  | 
| 66 |     void addToTargetLists(QQuickItemViewTransitioner::TransitionType type, QQuickItemViewTransitionableItem *item, int index); | 
| 67 |     void resetTargetLists(); | 
| 68 |  | 
| 69 |     QQuickTransition *transitionObject(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const; | 
| 70 |     const QList<int> &targetIndexes(QQuickItemViewTransitioner::TransitionType type) const; | 
| 71 |     const QList<QObject *> &targetItems(QQuickItemViewTransitioner::TransitionType type) const; | 
| 72 |  | 
| 73 |     inline void setPopulateTransitionEnabled(bool b) { usePopulateTransition = b; } | 
| 74 |     inline bool populateTransitionEnabled() const { return usePopulateTransition; } | 
| 75 |  | 
| 76 |     inline void setChangeListener(QQuickItemViewTransitionChangeListener *obj) { changeListener = obj; } | 
| 77 |  | 
| 78 |     QSet<QQuickItemViewTransitionJob *> runningJobs; | 
| 79 |  | 
| 80 |     QList<int> addTransitionIndexes; | 
| 81 |     QList<int> moveTransitionIndexes; | 
| 82 |     QList<int> removeTransitionIndexes; | 
| 83 |     QList<QObject *> addTransitionTargets; | 
| 84 |     QList<QObject *> moveTransitionTargets; | 
| 85 |     QList<QObject *> removeTransitionTargets; | 
| 86 |  | 
| 87 |     QQmlGuard<QQuickTransition> populateTransition; | 
| 88 |     QQmlGuard<QQuickTransition> addTransition; | 
| 89 |     QQmlGuard<QQuickTransition> addDisplacedTransition; | 
| 90 |     QQmlGuard<QQuickTransition> moveTransition; | 
| 91 |     QQmlGuard<QQuickTransition> moveDisplacedTransition; | 
| 92 |     QQmlGuard<QQuickTransition> removeTransition; | 
| 93 |     QQmlGuard<QQuickTransition> removeDisplacedTransition; | 
| 94 |     QQmlGuard<QQuickTransition> displacedTransition; | 
| 95 |  | 
| 96 | private: | 
| 97 |     friend class QQuickItemViewTransitionJob; | 
| 98 |  | 
| 99 |     QQuickItemViewTransitionChangeListener *changeListener; | 
| 100 |     bool usePopulateTransition; | 
| 101 |  | 
| 102 |     void finishedTransition(QQuickItemViewTransitionJob *job, QQuickItemViewTransitionableItem *item); | 
| 103 | }; | 
| 104 |  | 
| 105 |  | 
| 106 | /* | 
| 107 |   An item that can be transitioned using QQuickViewTransitionJob. | 
| 108 |   */ | 
| 109 | class Q_QUICK_EXPORT QQuickItemViewTransitionableItem | 
| 110 | { | 
| 111 | public: | 
| 112 |     QQuickItemViewTransitionableItem(QQuickItem *i); | 
| 113 |     virtual ~QQuickItemViewTransitionableItem(); | 
| 114 |  | 
| 115 |     qreal itemX() const; | 
| 116 |     qreal itemY() const; | 
| 117 |  | 
| 118 |     void moveTo(const QPointF &pos, bool immediate = false); | 
| 119 |  | 
| 120 |     bool transitionScheduledOrRunning() const; | 
| 121 |     bool transitionRunning() const; | 
| 122 |     bool isPendingRemoval() const; | 
| 123 |  | 
| 124 |     bool prepareTransition(QQuickItemViewTransitioner *transitioner, int index, const QRectF &viewBounds); | 
| 125 |     void startTransition(QQuickItemViewTransitioner *transitioner, int index); | 
| 126 |     void completeTransition(QQuickTransition *quickTransition); | 
| 127 |  | 
| 128 |     SelfDeletable m_selfDeletable; | 
| 129 |     QPointF nextTransitionTo; | 
| 130 |     QPointF lastMovedTo; | 
| 131 |     QPointF nextTransitionFrom; | 
| 132 |     QQuickItem *item; | 
| 133 |     QQuickItemViewTransitionJob *transition; | 
| 134 |     QQuickItemViewTransitioner::TransitionType nextTransitionType; | 
| 135 |     bool isTransitionTarget : 1; | 
| 136 |     bool nextTransitionToSet : 1; | 
| 137 |     bool nextTransitionFromSet : 1; | 
| 138 |     bool lastMovedToSet : 1; | 
| 139 |     bool prepared : 1; | 
| 140 |  | 
| 141 | private: | 
| 142 |     friend class QQuickItemViewTransitioner; | 
| 143 |     friend class QQuickItemViewTransitionJob; | 
| 144 |     void setNextTransition(QQuickItemViewTransitioner::TransitionType, bool isTargetItem); | 
| 145 |     bool transitionWillChangePosition() const; | 
| 146 |     void finishedTransition(); | 
| 147 |     void resetNextTransitionPos(); | 
| 148 |     void clearCurrentScheduledTransition(); | 
| 149 |     void stopTransition(); | 
| 150 | }; | 
| 151 |  | 
| 152 |  | 
| 153 | class QQuickViewTransitionAttached : public QObject | 
| 154 | { | 
| 155 |     Q_OBJECT | 
| 156 |  | 
| 157 |     Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL) | 
| 158 |     Q_PROPERTY(QQuickItem* item READ item NOTIFY itemChanged FINAL) | 
| 159 |     Q_PROPERTY(QPointF destination READ destination NOTIFY destinationChanged FINAL) | 
| 160 |  | 
| 161 |     Q_PROPERTY(QList<int> targetIndexes READ targetIndexes NOTIFY targetIndexesChanged FINAL) | 
| 162 |     Q_PROPERTY(QQmlListProperty<QObject> targetItems READ targetItems NOTIFY targetItemsChanged FINAL) | 
| 163 |  | 
| 164 |     QML_NAMED_ELEMENT(ViewTransition) | 
| 165 |     QML_ADDED_IN_VERSION(2, 0) | 
| 166 |     QML_UNCREATABLE("ViewTransition is only available via attached properties." ) | 
| 167 |     QML_ATTACHED(QQuickViewTransitionAttached) | 
| 168 |  | 
| 169 | public: | 
| 170 |     QQuickViewTransitionAttached(QObject *parent); | 
| 171 |  | 
| 172 |     int index() const { return m_index; } | 
| 173 |     QQuickItem *item() const { return m_item; } | 
| 174 |     QPointF destination() const { return m_destination; } | 
| 175 |  | 
| 176 |     QList<int> targetIndexes() const { return m_targetIndexes; } | 
| 177 |     QQmlListProperty<QObject> targetItems(); | 
| 178 |  | 
| 179 |     static QQuickViewTransitionAttached *qmlAttachedProperties(QObject *); | 
| 180 |  | 
| 181 | Q_SIGNALS: | 
| 182 |     void indexChanged(); | 
| 183 |     void itemChanged(); | 
| 184 |     void destinationChanged(); | 
| 185 |  | 
| 186 |     void targetIndexesChanged(); | 
| 187 |     void targetItemsChanged(); | 
| 188 |  | 
| 189 | private: | 
| 190 |     friend class QQuickItemViewTransitionJob; | 
| 191 |     QPointF m_destination; | 
| 192 |     QList<int> m_targetIndexes; | 
| 193 |     QList<QObject *> m_targetItems; | 
| 194 |  | 
| 195 |     QPointer<QQuickItem> m_item; | 
| 196 |     int m_index; | 
| 197 | }; | 
| 198 |  | 
| 199 | QT_END_NAMESPACE | 
| 200 |  | 
| 201 | #endif // QQUICKITEMVIEWTRANSITION_P_P_H | 
| 202 |  |