Fix various QtQuick.* submodule docs
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitemviewtransition_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKITEMVIEWTRANSITION_P_P_H
43 #define QQUICKITEMVIEWTRANSITION_P_P_H
44
45 #include <private/qquicktransitionmanager_p_p.h>
46
47 QT_BEGIN_HEADER
48
49 QT_BEGIN_NAMESPACE
50
51 QT_MODULE(Quick)
52
53 class QQuickItem;
54 class QQuickItemViewTransitionableItem;
55 class QQuickItemViewTransitionJob;
56
57
58 class QQuickItemViewTransitionChangeListener
59 {
60 public:
61     QQuickItemViewTransitionChangeListener() {}
62     virtual ~QQuickItemViewTransitionChangeListener() {}
63
64     virtual void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) = 0;
65 };
66
67
68 class QQuickItemViewTransitioner
69 {
70 public:
71     enum TransitionType {
72         NoTransition,
73         PopulateTransition,
74         AddTransition,
75         MoveTransition,
76         RemoveTransition
77     };
78
79     QQuickItemViewTransitioner();
80     virtual ~QQuickItemViewTransitioner();
81
82     bool canTransition(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const;
83     void transitionNextReposition(QQuickItemViewTransitionableItem *item, QQuickItemViewTransitioner::TransitionType type, bool isTarget);
84
85     void addToTargetLists(QQuickItemViewTransitioner::TransitionType type, QQuickItemViewTransitionableItem *item, int index);
86     void resetTargetLists();
87
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;
91
92     inline void setPopulateTransitionEnabled(bool b) { usePopulateTransition = b; }
93     inline bool populateTransitionEnabled() const { return usePopulateTransition; }
94
95     inline void setChangeListener(QQuickItemViewTransitionChangeListener *obj) { changeListener = obj; }
96
97     QSet<QQuickItemViewTransitionJob *> runningJobs;
98
99     QList<int> addTransitionIndexes;
100     QList<int> moveTransitionIndexes;
101     QList<int> removeTransitionIndexes;
102     QList<QObject *> addTransitionTargets;
103     QList<QObject *> moveTransitionTargets;
104     QList<QObject *> removeTransitionTargets;
105
106     QQuickTransition *populateTransition;
107     QQuickTransition *addTransition;
108     QQuickTransition *addDisplacedTransition;
109     QQuickTransition *moveTransition;
110     QQuickTransition *moveDisplacedTransition;
111     QQuickTransition *removeTransition;
112     QQuickTransition *removeDisplacedTransition;
113     QQuickTransition *displacedTransition;
114
115 private:
116     friend class QQuickItemViewTransitionJob;
117
118     QQuickItemViewTransitionChangeListener *changeListener;
119     bool usePopulateTransition;
120
121     void finishedTransition(QQuickItemViewTransitionJob *job, QQuickItemViewTransitionableItem *item);
122 };
123
124
125 /*
126   An item that can be transitioned using QQuickViewTransitionJob.
127   */
128 class QQuickItemViewTransitionableItem
129 {
130 public:
131     QQuickItemViewTransitionableItem(QQuickItem *i);
132     virtual ~QQuickItemViewTransitionableItem();
133
134     qreal itemX() const;
135     qreal itemY() const;
136
137     void moveTo(const QPointF &pos, bool immediate = false);
138
139     bool transitionScheduledOrRunning() const;
140     bool transitionRunning() const;
141     bool isPendingRemoval() const;
142
143     bool prepareTransition(QQuickItemViewTransitioner *transitioner, int index, const QRectF &viewBounds);
144     void startTransition(QQuickItemViewTransitioner *transitioner, int index);
145
146     QPointF nextTransitionTo;
147     QPointF lastMovedTo;
148     QPointF nextTransitionFrom;
149     QQuickItem *item;
150     QQuickItemViewTransitionJob *transition;
151     QQuickItemViewTransitioner::TransitionType nextTransitionType;
152     bool isTransitionTarget : 1;
153     bool nextTransitionToSet : 1;
154     bool nextTransitionFromSet : 1;
155     bool lastMovedToSet : 1;
156     bool prepared : 1;
157
158 private:
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();
167 };
168
169
170 class QQuickViewTransitionAttached : public QObject
171 {
172     Q_OBJECT
173
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)
177
178     Q_PROPERTY(QList<int> targetIndexes READ targetIndexes NOTIFY targetIndexesChanged)
179     Q_PROPERTY(QQmlListProperty<QObject> targetItems READ targetItems NOTIFY targetItemsChanged)
180
181 public:
182     QQuickViewTransitionAttached(QObject *parent);
183
184     int index() const { return m_index; }
185     QQuickItem *item() const { return m_item; }
186     QPointF destination() const { return m_destination; }
187
188     QList<int> targetIndexes() const { return m_targetIndexes; }
189     QQmlListProperty<QObject> targetItems();
190
191     static QQuickViewTransitionAttached *qmlAttachedProperties(QObject *);
192
193 signals:
194     void indexChanged();
195     void itemChanged();
196     void destinationChanged();
197
198     void targetIndexesChanged();
199     void targetItemsChanged();
200
201 private:
202     friend class QQuickItemViewTransitionJob;
203     QPointF m_destination;
204     QList<int> m_targetIndexes;
205     QList<QObject *> m_targetItems;
206
207     QQuickItem *m_item;
208     int m_index;
209 };
210
211 QT_END_NAMESPACE
212
213 QML_DECLARE_TYPE(QQuickViewTransitionAttached)
214 QML_DECLARE_TYPEINFO(QQuickViewTransitionAttached, QML_HAS_ATTACHED_PROPERTIES)
215
216 QT_END_HEADER
217
218 #endif // QQUICKITEMVIEWTRANSITION_P_P_H