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 QtQml 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 QQUICKITEMVIEWTRANSITION_P_P_H
43 #define QQUICKITEMVIEWTRANSITION_P_P_H
45 #include <private/qquicktransitionmanager_p_p.h>
54 class QQuickItemViewTransitionableItem;
55 class QQuickItemViewTransitionJob;
58 class QQuickItemViewTransitionChangeListener
61 QQuickItemViewTransitionChangeListener() {}
62 virtual ~QQuickItemViewTransitionChangeListener() {}
64 virtual void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) = 0;
68 class QQuickItemViewTransitioner
79 QQuickItemViewTransitioner();
80 virtual ~QQuickItemViewTransitioner();
82 bool canTransition(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const;
83 void transitionNextReposition(QQuickItemViewTransitionableItem *item, QQuickItemViewTransitioner::TransitionType type, bool isTarget);
85 void addToTargetLists(QQuickItemViewTransitioner::TransitionType type, QQuickItemViewTransitionableItem *item, int index);
86 void resetTargetLists();
88 QQuickTransition *transitionObject(QQuickItemViewTransitioner::TransitionType type, bool asTarget);
89 const QList<int> &targetIndexes(QQuickItemViewTransitioner::TransitionType type) const;
90 const QList<QObject *> &targetItems(QQuickItemViewTransitioner::TransitionType type) const;
92 inline void setPopulateTransitionEnabled(bool b) { usePopulateTransition = b; }
93 inline bool populateTransitionEnabled() const { return usePopulateTransition; }
95 inline void setChangeListener(QQuickItemViewTransitionChangeListener *obj) { changeListener = obj; }
97 QSet<QQuickItemViewTransitionJob *> runningJobs;
99 QList<int> addTransitionIndexes;
100 QList<int> moveTransitionIndexes;
101 QList<int> removeTransitionIndexes;
102 QList<QObject *> addTransitionTargets;
103 QList<QObject *> moveTransitionTargets;
104 QList<QObject *> removeTransitionTargets;
106 QQuickTransition *populateTransition;
107 QQuickTransition *addTransition;
108 QQuickTransition *addDisplacedTransition;
109 QQuickTransition *moveTransition;
110 QQuickTransition *moveDisplacedTransition;
111 QQuickTransition *removeTransition;
112 QQuickTransition *removeDisplacedTransition;
113 QQuickTransition *displacedTransition;
116 friend class QQuickItemViewTransitionJob;
118 QQuickItemViewTransitionChangeListener *changeListener;
119 bool usePopulateTransition;
121 void finishedTransition(QQuickItemViewTransitionJob *job, QQuickItemViewTransitionableItem *item);
126 An item that can be transitioned using QQuickViewTransitionJob.
128 class QQuickItemViewTransitionableItem
131 QQuickItemViewTransitionableItem(QQuickItem *i);
132 virtual ~QQuickItemViewTransitionableItem();
137 void moveTo(const QPointF &pos, bool immediate = false);
139 bool transitionScheduledOrRunning() const;
140 bool transitionRunning() const;
141 bool isPendingRemoval() const;
143 bool prepareTransition(QQuickItemViewTransitioner *transitioner, int index, const QRectF &viewBounds);
144 void startTransition(QQuickItemViewTransitioner *transitioner, int index);
146 QPointF nextTransitionTo;
148 QPointF nextTransitionFrom;
150 QQuickItemViewTransitionJob *transition;
151 QQuickItemViewTransitioner::TransitionType nextTransitionType;
152 bool isTransitionTarget : 1;
153 bool nextTransitionToSet : 1;
154 bool nextTransitionFromSet : 1;
155 bool lastMovedToSet : 1;
159 friend class QQuickItemViewTransitioner;
160 friend class QQuickItemViewTransitionJob;
161 void setNextTransition(QQuickItemViewTransitioner::TransitionType, bool isTargetItem);
162 bool transitionWillChangePosition() const;
163 void finishedTransition();
164 void resetNextTransitionPos();
165 void clearCurrentScheduledTransition();
166 void stopTransition();
170 class QQuickViewTransitionAttached : public QObject
174 Q_PROPERTY(int index READ index NOTIFY indexChanged)
175 Q_PROPERTY(QQuickItem* item READ item NOTIFY itemChanged)
176 Q_PROPERTY(QPointF destination READ destination NOTIFY destinationChanged)
178 Q_PROPERTY(QList<int> targetIndexes READ targetIndexes NOTIFY targetIndexesChanged)
179 Q_PROPERTY(QQmlListProperty<QObject> targetItems READ targetItems NOTIFY targetItemsChanged)
182 QQuickViewTransitionAttached(QObject *parent);
184 int index() const { return m_index; }
185 QQuickItem *item() const { return m_item; }
186 QPointF destination() const { return m_destination; }
188 QList<int> targetIndexes() const { return m_targetIndexes; }
189 QQmlListProperty<QObject> targetItems();
191 static QQuickViewTransitionAttached *qmlAttachedProperties(QObject *);
196 void destinationChanged();
198 void targetIndexesChanged();
199 void targetItemsChanged();
202 friend class QQuickItemViewTransitionJob;
203 QPointF m_destination;
204 QList<int> m_targetIndexes;
205 QList<QObject *> m_targetItems;
213 QML_DECLARE_TYPE(QQuickViewTransitionAttached)
214 QML_DECLARE_TYPEINFO(QQuickViewTransitionAttached, QML_HAS_ATTACHED_PROPERTIES)
218 #endif // QQUICKITEMVIEWTRANSITION_P_P_H