Rename QDeclarative symbols to QQuick and QQml
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitemview_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 QQUICKITEMVIEW_P_H
43 #define QQUICKITEMVIEW_P_H
44
45 #include "qquickflickable_p.h"
46
47 QT_BEGIN_HEADER
48
49 QT_BEGIN_NAMESPACE
50
51 QT_MODULE(Qml)
52
53 class QQuickChangeSet;
54
55 class QQuickItemViewPrivate;
56
57 class Q_AUTOTEST_EXPORT QQuickItemView : public QQuickFlickable
58 {
59     Q_OBJECT
60
61     Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
62     Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
63     Q_PROPERTY(int count READ count NOTIFY countChanged)
64
65     Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
66     Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged)
67
68     Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
69     Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
70
71     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
72     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
73
74     Q_PROPERTY(QQmlComponent *header READ header WRITE setHeader NOTIFY headerChanged)
75     Q_PROPERTY(QQuickItem *headerItem READ headerItem NOTIFY headerItemChanged)
76     Q_PROPERTY(QQmlComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
77     Q_PROPERTY(QQuickItem *footerItem READ footerItem NOTIFY footerItemChanged)
78
79     Q_PROPERTY(QQuickTransition *populate READ populateTransition WRITE setPopulateTransition NOTIFY populateTransitionChanged)
80     Q_PROPERTY(QQuickTransition *add READ addTransition WRITE setAddTransition NOTIFY addTransitionChanged)
81     Q_PROPERTY(QQuickTransition *addDisplaced READ addDisplacedTransition WRITE setAddDisplacedTransition NOTIFY addDisplacedTransitionChanged)
82     Q_PROPERTY(QQuickTransition *move READ moveTransition WRITE setMoveTransition NOTIFY moveTransitionChanged)
83     Q_PROPERTY(QQuickTransition *moveDisplaced READ moveDisplacedTransition WRITE setMoveDisplacedTransition NOTIFY moveDisplacedTransitionChanged)
84     Q_PROPERTY(QQuickTransition *remove READ removeTransition WRITE setRemoveTransition NOTIFY removeTransitionChanged)
85     Q_PROPERTY(QQuickTransition *removeDisplaced READ removeDisplacedTransition WRITE setRemoveDisplacedTransition NOTIFY removeDisplacedTransitionChanged)
86
87     Q_PROPERTY(QQmlComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
88     Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
89     Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
90     Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
91     Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
92     Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
93     Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
94
95     Q_ENUMS(HighlightRangeMode)
96     Q_ENUMS(PositionMode)
97
98 public:
99     QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent = 0);
100     ~QQuickItemView();
101
102     QVariant model() const;
103     void setModel(const QVariant &);
104
105     QQmlComponent *delegate() const;
106     void setDelegate(QQmlComponent *);
107
108     int count() const;
109
110     int currentIndex() const;
111     void setCurrentIndex(int idx);
112
113     QQuickItem *currentItem() const;
114
115     bool isWrapEnabled() const;
116     void setWrapEnabled(bool);
117
118     int cacheBuffer() const;
119     void setCacheBuffer(int);
120
121     Qt::LayoutDirection layoutDirection() const;
122     void setLayoutDirection(Qt::LayoutDirection);
123     Qt::LayoutDirection effectiveLayoutDirection() const;
124
125     QQmlComponent *footer() const;
126     void setFooter(QQmlComponent *);
127     QQuickItem *footerItem() const;
128
129     QQmlComponent *header() const;
130     void setHeader(QQmlComponent *);
131     QQuickItem *headerItem() const;
132
133     QQuickTransition *populateTransition() const;
134     void setPopulateTransition(QQuickTransition *transition);
135
136     QQuickTransition *addTransition() const;
137     void setAddTransition(QQuickTransition *transition);
138
139     QQuickTransition *addDisplacedTransition() const;
140     void setAddDisplacedTransition(QQuickTransition *transition);
141
142     QQuickTransition *moveTransition() const;
143     void setMoveTransition(QQuickTransition *transition);
144
145     QQuickTransition *moveDisplacedTransition() const;
146     void setMoveDisplacedTransition(QQuickTransition *transition);
147
148     QQuickTransition *removeTransition() const;
149     void setRemoveTransition(QQuickTransition *transition);
150
151     QQuickTransition *removeDisplacedTransition() const;
152     void setRemoveDisplacedTransition(QQuickTransition *transition);
153
154     QQmlComponent *highlight() const;
155     void setHighlight(QQmlComponent *);
156
157     QQuickItem *highlightItem() const;
158
159     bool highlightFollowsCurrentItem() const;
160     virtual void setHighlightFollowsCurrentItem(bool);
161
162     enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
163     HighlightRangeMode highlightRangeMode() const;
164     void setHighlightRangeMode(HighlightRangeMode mode);
165
166     qreal preferredHighlightBegin() const;
167     void setPreferredHighlightBegin(qreal);
168     void resetPreferredHighlightBegin();
169
170     qreal preferredHighlightEnd() const;
171     void setPreferredHighlightEnd(qreal);
172     void resetPreferredHighlightEnd();
173
174     int highlightMoveDuration() const;
175     virtual void setHighlightMoveDuration(int);
176
177     enum PositionMode { Beginning, Center, End, Visible, Contain };
178
179     Q_INVOKABLE void positionViewAtIndex(int index, int mode);
180     Q_INVOKABLE int indexAt(qreal x, qreal y) const;
181     Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const;
182     Q_INVOKABLE void positionViewAtBeginning();
183     Q_INVOKABLE void positionViewAtEnd();
184
185     virtual void setContentX(qreal pos);
186     virtual void setContentY(qreal pos);
187     virtual qreal xOrigin() const;
188
189 signals:
190     void modelChanged();
191     void delegateChanged();
192     void countChanged();
193     void currentIndexChanged();
194     void currentItemChanged();
195
196     void keyNavigationWrapsChanged();
197     void cacheBufferChanged();
198
199     void layoutDirectionChanged();
200     void effectiveLayoutDirectionChanged();
201
202     void headerChanged();
203     void footerChanged();
204     void headerItemChanged();
205     void footerItemChanged();
206
207     void populateTransitionChanged();
208     void addTransitionChanged();
209     void addDisplacedTransitionChanged();
210     void moveTransitionChanged();
211     void moveDisplacedTransitionChanged();
212     void removeTransitionChanged();
213     void removeDisplacedTransitionChanged();
214
215     void highlightChanged();
216     void highlightItemChanged();
217     void highlightFollowsCurrentItemChanged();
218     void highlightRangeModeChanged();
219     void preferredHighlightBeginChanged();
220     void preferredHighlightEndChanged();
221     void highlightMoveDurationChanged();
222
223 protected:
224     virtual void updatePolish();
225     virtual void componentComplete();
226     virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
227     virtual qreal minYExtent() const;
228     virtual qreal maxYExtent() const;
229     virtual qreal minXExtent() const;
230     virtual qreal maxXExtent() const;
231
232 protected slots:
233     virtual void updateSections() {}
234     void destroyRemoved();
235     void createdItem(int index, QQuickItem *item);
236     void initItem(int index, QQuickItem *item);
237     void modelUpdated(const QQuickChangeSet &changeSet, bool reset);
238     void destroyingItem(QQuickItem *item);
239     void animStopped();
240     void trackedPositionChanged();
241
242 private:
243     Q_DECLARE_PRIVATE(QQuickItemView)
244 };
245
246
247 class Q_AUTOTEST_EXPORT QQuickItemViewAttached : public QObject
248 {
249     Q_OBJECT
250
251     Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
252     Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
253
254     Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
255     Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
256     Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
257
258 public:
259     QQuickItemViewAttached(QObject *parent)
260         : QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
261     ~QQuickItemViewAttached() {}
262
263     bool isCurrentItem() const { return m_isCurrent; }
264     void setIsCurrentItem(bool c) {
265         if (m_isCurrent != c) {
266             m_isCurrent = c;
267             emit currentItemChanged();
268         }
269     }
270
271     bool delayRemove() const { return m_delayRemove; }
272     void setDelayRemove(bool delay) {
273         if (m_delayRemove != delay) {
274             m_delayRemove = delay;
275             emit delayRemoveChanged();
276         }
277     }
278
279     QString section() const { return m_section; }
280     void setSection(const QString &sect) {
281         if (m_section != sect) {
282             m_section = sect;
283             emit sectionChanged();
284         }
285     }
286
287     QString prevSection() const { return m_prevSection; }
288     void setPrevSection(const QString &sect) {
289         if (m_prevSection != sect) {
290             m_prevSection = sect;
291             emit prevSectionChanged();
292         }
293     }
294
295     QString nextSection() const { return m_nextSection; }
296     void setNextSection(const QString &sect) {
297         if (m_nextSection != sect) {
298             m_nextSection = sect;
299             emit nextSectionChanged();
300         }
301     }
302
303     void emitAdd() { emit add(); }
304     void emitRemove() { emit remove(); }
305
306 signals:
307     void currentItemChanged();
308     void delayRemoveChanged();
309
310     void add();
311     void remove();
312
313     void sectionChanged();
314     void prevSectionChanged();
315     void nextSectionChanged();
316
317 public:
318     bool m_isCurrent : 1;
319     bool m_delayRemove : 1;
320
321     // current only used by list view
322     mutable QString m_section;
323     QString m_prevSection;
324     QString m_nextSection;
325 };
326
327 class QQuickViewTransitionAttached : public QObject
328 {
329     Q_OBJECT
330
331     Q_PROPERTY(int index READ index NOTIFY indexChanged)
332     Q_PROPERTY(QQuickItem* item READ item NOTIFY itemChanged)
333     Q_PROPERTY(QPointF destination READ destination NOTIFY destinationChanged)
334
335     Q_PROPERTY(QList<int> targetIndexes READ targetIndexes NOTIFY targetIndexesChanged)
336     Q_PROPERTY(QQmlListProperty<QObject> targetItems READ targetItems NOTIFY targetItemsChanged)
337
338 public:
339     QQuickViewTransitionAttached(QObject *parent);
340
341     int index() const { return m_index; }
342     QQuickItem *item() const { return m_item; }
343     QPointF destination() const { return m_destination; }
344
345     QList<int> targetIndexes() const { return m_targetIndexes; }
346     QQmlListProperty<QObject> targetItems();
347
348     static QQuickViewTransitionAttached *qmlAttachedProperties(QObject *);
349
350 signals:
351     void indexChanged();
352     void itemChanged();
353     void destinationChanged();
354
355     void targetIndexesChanged();
356     void targetItemsChanged();
357
358 private:
359     friend class FxViewItemTransitionManager;
360     int m_index;
361     QQuickItem *m_item;
362     QPointF m_destination;
363
364     QList<int> m_targetIndexes;
365     QList<QObject *> m_targetItems;
366 };
367
368
369 QT_END_NAMESPACE
370
371 QML_DECLARE_TYPE(QQuickViewTransitionAttached)
372 QML_DECLARE_TYPEINFO(QQuickViewTransitionAttached, QML_HAS_ATTACHED_PROPERTIES)
373
374 QT_END_HEADER
375
376 #endif // QQUICKITEMVIEW_P_H
377