Section headers ignore list delegate size changes when "colliding"
[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(Quick)
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     Q_PROPERTY(VerticalLayoutDirection verticalLayoutDirection READ verticalLayoutDirection WRITE setVerticalLayoutDirection NOTIFY verticalLayoutDirectionChanged)
74
75     Q_PROPERTY(QQmlComponent *header READ header WRITE setHeader NOTIFY headerChanged)
76     Q_PROPERTY(QQuickItem *headerItem READ headerItem NOTIFY headerItemChanged)
77     Q_PROPERTY(QQmlComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
78     Q_PROPERTY(QQuickItem *footerItem READ footerItem NOTIFY footerItemChanged)
79
80     Q_PROPERTY(QQuickTransition *populate READ populateTransition WRITE setPopulateTransition NOTIFY populateTransitionChanged)
81     Q_PROPERTY(QQuickTransition *add READ addTransition WRITE setAddTransition NOTIFY addTransitionChanged)
82     Q_PROPERTY(QQuickTransition *addDisplaced READ addDisplacedTransition WRITE setAddDisplacedTransition NOTIFY addDisplacedTransitionChanged)
83     Q_PROPERTY(QQuickTransition *move READ moveTransition WRITE setMoveTransition NOTIFY moveTransitionChanged)
84     Q_PROPERTY(QQuickTransition *moveDisplaced READ moveDisplacedTransition WRITE setMoveDisplacedTransition NOTIFY moveDisplacedTransitionChanged)
85     Q_PROPERTY(QQuickTransition *remove READ removeTransition WRITE setRemoveTransition NOTIFY removeTransitionChanged)
86     Q_PROPERTY(QQuickTransition *removeDisplaced READ removeDisplacedTransition WRITE setRemoveDisplacedTransition NOTIFY removeDisplacedTransitionChanged)
87     Q_PROPERTY(QQuickTransition *displaced READ displacedTransition WRITE setDisplacedTransition NOTIFY displacedTransitionChanged)
88
89     Q_PROPERTY(QQmlComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
90     Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
91     Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
92     Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
93     Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
94     Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
95     Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
96
97     Q_ENUMS(HighlightRangeMode)
98     Q_ENUMS(PositionMode)
99     Q_ENUMS(VerticalLayoutDirection)
100     Q_ENUMS(LayoutDirection)
101
102 public:
103     // this holds all layout enum values so they can be referred to by other enums
104     // to ensure consistent values - e.g. QML references to GridView.TopToBottom flow
105     // and GridView.TopToBottom vertical layout direction should have same value
106     enum LayoutDirection {
107         LeftToRight = Qt::LeftToRight,
108         RightToLeft = Qt::RightToLeft,
109         VerticalTopToBottom,
110         VerticalBottomToTop
111     };
112
113     enum VerticalLayoutDirection {
114         TopToBottom = VerticalTopToBottom,
115         BottomToTop = VerticalBottomToTop
116     };
117
118     QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent = 0);
119     ~QQuickItemView();
120
121     QVariant model() const;
122     void setModel(const QVariant &);
123
124     QQmlComponent *delegate() const;
125     void setDelegate(QQmlComponent *);
126
127     int count() const;
128
129     int currentIndex() const;
130     void setCurrentIndex(int idx);
131
132     QQuickItem *currentItem() const;
133
134     bool isWrapEnabled() const;
135     void setWrapEnabled(bool);
136
137     int cacheBuffer() const;
138     void setCacheBuffer(int);
139
140     Qt::LayoutDirection layoutDirection() const;
141     void setLayoutDirection(Qt::LayoutDirection);
142     Qt::LayoutDirection effectiveLayoutDirection() const;
143
144     VerticalLayoutDirection verticalLayoutDirection() const;
145     void setVerticalLayoutDirection(VerticalLayoutDirection layoutDirection);
146
147     QQmlComponent *footer() const;
148     void setFooter(QQmlComponent *);
149     QQuickItem *footerItem() const;
150
151     QQmlComponent *header() const;
152     void setHeader(QQmlComponent *);
153     QQuickItem *headerItem() const;
154
155     QQuickTransition *populateTransition() const;
156     void setPopulateTransition(QQuickTransition *transition);
157
158     QQuickTransition *addTransition() const;
159     void setAddTransition(QQuickTransition *transition);
160
161     QQuickTransition *addDisplacedTransition() const;
162     void setAddDisplacedTransition(QQuickTransition *transition);
163
164     QQuickTransition *moveTransition() const;
165     void setMoveTransition(QQuickTransition *transition);
166
167     QQuickTransition *moveDisplacedTransition() const;
168     void setMoveDisplacedTransition(QQuickTransition *transition);
169
170     QQuickTransition *removeTransition() const;
171     void setRemoveTransition(QQuickTransition *transition);
172
173     QQuickTransition *removeDisplacedTransition() const;
174     void setRemoveDisplacedTransition(QQuickTransition *transition);
175
176     QQuickTransition *displacedTransition() const;
177     void setDisplacedTransition(QQuickTransition *transition);
178
179     QQmlComponent *highlight() const;
180     void setHighlight(QQmlComponent *);
181
182     QQuickItem *highlightItem() const;
183
184     bool highlightFollowsCurrentItem() const;
185     virtual void setHighlightFollowsCurrentItem(bool);
186
187     enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
188     HighlightRangeMode highlightRangeMode() const;
189     void setHighlightRangeMode(HighlightRangeMode mode);
190
191     qreal preferredHighlightBegin() const;
192     void setPreferredHighlightBegin(qreal);
193     void resetPreferredHighlightBegin();
194
195     qreal preferredHighlightEnd() const;
196     void setPreferredHighlightEnd(qreal);
197     void resetPreferredHighlightEnd();
198
199     int highlightMoveDuration() const;
200     virtual void setHighlightMoveDuration(int);
201
202     enum PositionMode { Beginning, Center, End, Visible, Contain };
203
204     Q_INVOKABLE void positionViewAtIndex(int index, int mode);
205     Q_INVOKABLE int indexAt(qreal x, qreal y) const;
206     Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const;
207     Q_INVOKABLE void positionViewAtBeginning();
208     Q_INVOKABLE void positionViewAtEnd();
209
210     virtual void setContentX(qreal pos);
211     virtual void setContentY(qreal pos);
212     virtual qreal originX() const;
213     virtual qreal originY() const;
214
215 signals:
216     void modelChanged();
217     void delegateChanged();
218     void countChanged();
219     void currentIndexChanged();
220     void currentItemChanged();
221
222     void keyNavigationWrapsChanged();
223     void cacheBufferChanged();
224
225     void layoutDirectionChanged();
226     void effectiveLayoutDirectionChanged();
227     void verticalLayoutDirectionChanged();
228
229     void headerChanged();
230     void footerChanged();
231     void headerItemChanged();
232     void footerItemChanged();
233
234     void populateTransitionChanged();
235     void addTransitionChanged();
236     void addDisplacedTransitionChanged();
237     void moveTransitionChanged();
238     void moveDisplacedTransitionChanged();
239     void removeTransitionChanged();
240     void removeDisplacedTransitionChanged();
241     void displacedTransitionChanged();
242
243     void highlightChanged();
244     void highlightItemChanged();
245     void highlightFollowsCurrentItemChanged();
246     void highlightRangeModeChanged();
247     void preferredHighlightBeginChanged();
248     void preferredHighlightEndChanged();
249     void highlightMoveDurationChanged();
250
251 protected:
252     virtual void updatePolish();
253     virtual void componentComplete();
254     virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
255     virtual qreal minYExtent() const;
256     virtual qreal maxYExtent() const;
257     virtual qreal minXExtent() const;
258     virtual qreal maxXExtent() const;
259
260 protected slots:
261     void destroyRemoved();
262     void createdItem(int index, QQuickItem *item);
263     virtual void initItem(int index, QQuickItem *item);
264     void modelUpdated(const QQuickChangeSet &changeSet, bool reset);
265     void destroyingItem(QQuickItem *item);
266     void animStopped();
267     void trackedPositionChanged();
268
269 private:
270     Q_DECLARE_PRIVATE(QQuickItemView)
271 };
272
273
274 class Q_AUTOTEST_EXPORT QQuickItemViewAttached : public QObject
275 {
276     Q_OBJECT
277
278     Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
279     Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
280
281     Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
282     Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
283     Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
284
285 public:
286     QQuickItemViewAttached(QObject *parent)
287         : QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
288     ~QQuickItemViewAttached() {}
289
290     bool isCurrentItem() const { return m_isCurrent; }
291     void setIsCurrentItem(bool c) {
292         if (m_isCurrent != c) {
293             m_isCurrent = c;
294             emit currentItemChanged();
295         }
296     }
297
298     bool delayRemove() const { return m_delayRemove; }
299     void setDelayRemove(bool delay) {
300         if (m_delayRemove != delay) {
301             m_delayRemove = delay;
302             emit delayRemoveChanged();
303         }
304     }
305
306     QString section() const { return m_section; }
307     void setSection(const QString &sect) {
308         if (m_section != sect) {
309             m_section = sect;
310             emit sectionChanged();
311         }
312     }
313
314     QString prevSection() const { return m_prevSection; }
315     void setPrevSection(const QString &sect) {
316         if (m_prevSection != sect) {
317             m_prevSection = sect;
318             emit prevSectionChanged();
319         }
320     }
321
322     QString nextSection() const { return m_nextSection; }
323     void setNextSection(const QString &sect) {
324         if (m_nextSection != sect) {
325             m_nextSection = sect;
326             emit nextSectionChanged();
327         }
328     }
329
330     void emitAdd() { emit add(); }
331     void emitRemove() { emit remove(); }
332
333 signals:
334     void currentItemChanged();
335     void delayRemoveChanged();
336
337     void add();
338     void remove();
339
340     void sectionChanged();
341     void prevSectionChanged();
342     void nextSectionChanged();
343
344 public:
345     bool m_isCurrent : 1;
346     bool m_delayRemove : 1;
347
348     // current only used by list view
349     mutable QString m_section;
350     QString m_prevSection;
351     QString m_nextSection;
352 };
353
354
355 QT_END_NAMESPACE
356
357 QT_END_HEADER
358
359 #endif // QQUICKITEMVIEW_P_H
360