f426f0dcdf715bb7c90e7eaa072b66b66e0fb0ce
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitemview_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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 class QDeclarativeChangeSet;
52
53 class QQuickItemViewPrivate;
54
55 class Q_AUTOTEST_EXPORT QQuickItemView : public QQuickFlickable
56 {
57     Q_OBJECT
58
59     Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
60     Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
61     Q_PROPERTY(int count READ count NOTIFY countChanged)
62
63     Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
64     Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged)
65
66     Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
67     Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
68
69     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
70     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
71
72     Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
73     Q_PROPERTY(QQuickItem *headerItem READ headerItem NOTIFY headerItemChanged)
74     Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
75     Q_PROPERTY(QQuickItem *footerItem READ footerItem NOTIFY footerItemChanged)
76
77     Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
78     Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
79     Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
80     Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
81     Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
82     Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
83     Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
84
85     Q_ENUMS(HighlightRangeMode)
86     Q_ENUMS(PositionMode)
87
88 public:
89     QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent = 0);
90     ~QQuickItemView();
91
92     QVariant model() const;
93     void setModel(const QVariant &);
94
95     QDeclarativeComponent *delegate() const;
96     void setDelegate(QDeclarativeComponent *);
97
98     int count() const;
99
100     int currentIndex() const;
101     void setCurrentIndex(int idx);
102
103     QQuickItem *currentItem() const;
104
105     bool isWrapEnabled() const;
106     void setWrapEnabled(bool);
107
108     int cacheBuffer() const;
109     void setCacheBuffer(int);
110
111     Qt::LayoutDirection layoutDirection() const;
112     void setLayoutDirection(Qt::LayoutDirection);
113     Qt::LayoutDirection effectiveLayoutDirection() const;
114
115     QDeclarativeComponent *footer() const;
116     void setFooter(QDeclarativeComponent *);
117     QQuickItem *footerItem() const;
118
119     QDeclarativeComponent *header() const;
120     void setHeader(QDeclarativeComponent *);
121     QQuickItem *headerItem() const;
122
123     QDeclarativeComponent *highlight() const;
124     void setHighlight(QDeclarativeComponent *);
125
126     QQuickItem *highlightItem() const;
127
128     bool highlightFollowsCurrentItem() const;
129     virtual void setHighlightFollowsCurrentItem(bool);
130
131     enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
132     HighlightRangeMode highlightRangeMode() const;
133     void setHighlightRangeMode(HighlightRangeMode mode);
134
135     qreal preferredHighlightBegin() const;
136     void setPreferredHighlightBegin(qreal);
137     void resetPreferredHighlightBegin();
138
139     qreal preferredHighlightEnd() const;
140     void setPreferredHighlightEnd(qreal);
141     void resetPreferredHighlightEnd();
142
143     int highlightMoveDuration() const;
144     virtual void setHighlightMoveDuration(int);
145
146     enum PositionMode { Beginning, Center, End, Visible, Contain };
147
148     Q_INVOKABLE void positionViewAtIndex(int index, int mode);
149     Q_INVOKABLE int indexAt(qreal x, qreal y) const;
150     Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const;
151     Q_INVOKABLE void positionViewAtBeginning();
152     Q_INVOKABLE void positionViewAtEnd();
153
154     virtual void setContentX(qreal pos);
155     virtual void setContentY(qreal pos);
156     virtual qreal xOrigin() const;
157
158 signals:
159     void modelChanged();
160     void delegateChanged();
161     void countChanged();
162     void currentIndexChanged();
163     void currentItemChanged();
164
165     void keyNavigationWrapsChanged();
166     void cacheBufferChanged();
167
168     void layoutDirectionChanged();
169     void effectiveLayoutDirectionChanged();
170
171     void headerChanged();
172     void footerChanged();
173     void headerItemChanged();
174     void footerItemChanged();
175
176     void highlightChanged();
177     void highlightItemChanged();
178     void highlightFollowsCurrentItemChanged();
179     void highlightRangeModeChanged();
180     void preferredHighlightBeginChanged();
181     void preferredHighlightEndChanged();
182     void highlightMoveDurationChanged();
183
184 protected:
185     virtual void updatePolish();
186     virtual void componentComplete();
187     virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
188     virtual qreal minYExtent() const;
189     virtual qreal maxYExtent() const;
190     virtual qreal minXExtent() const;
191     virtual qreal maxXExtent() const;
192
193 protected slots:
194     virtual void updateSections() {}
195     void destroyRemoved();
196     void createdItem(int index, QQuickItem *item);
197     void initItem(int index, QQuickItem *item);
198     void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset);
199     void destroyingItem(QQuickItem *item);
200     void animStopped();
201     void trackedPositionChanged();
202
203
204
205 private:
206     Q_DECLARE_PRIVATE(QQuickItemView)
207 };
208
209
210 class Q_AUTOTEST_EXPORT QQuickItemViewAttached : public QObject
211 {
212     Q_OBJECT
213
214     Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
215     Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
216
217     Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
218     Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
219     Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
220
221 public:
222     QQuickItemViewAttached(QObject *parent)
223         : QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
224     ~QQuickItemViewAttached() {}
225
226     bool isCurrentItem() const { return m_isCurrent; }
227     void setIsCurrentItem(bool c) {
228         if (m_isCurrent != c) {
229             m_isCurrent = c;
230             emit currentItemChanged();
231         }
232     }
233
234     bool delayRemove() const { return m_delayRemove; }
235     void setDelayRemove(bool delay) {
236         if (m_delayRemove != delay) {
237             m_delayRemove = delay;
238             emit delayRemoveChanged();
239         }
240     }
241
242     QString section() const { return m_section; }
243     void setSection(const QString &sect) {
244         if (m_section != sect) {
245             m_section = sect;
246             emit sectionChanged();
247         }
248     }
249
250     QString prevSection() const { return m_prevSection; }
251     void setPrevSection(const QString &sect) {
252         if (m_prevSection != sect) {
253             m_prevSection = sect;
254             emit prevSectionChanged();
255         }
256     }
257
258     QString nextSection() const { return m_nextSection; }
259     void setNextSection(const QString &sect) {
260         if (m_nextSection != sect) {
261             m_nextSection = sect;
262             emit nextSectionChanged();
263         }
264     }
265
266     void emitAdd() { emit add(); }
267     void emitRemove() { emit remove(); }
268
269 signals:
270     void currentItemChanged();
271     void delayRemoveChanged();
272
273     void add();
274     void remove();
275
276     void sectionChanged();
277     void prevSectionChanged();
278     void nextSectionChanged();
279
280 public:
281     bool m_isCurrent : 1;
282     bool m_delayRemove : 1;
283
284     // current only used by list view
285     mutable QString m_section;
286     QString m_prevSection;
287     QString m_nextSection;
288 };
289
290
291 QT_END_NAMESPACE
292 QT_END_HEADER
293
294 #endif // QQUICKITEMVIEW_P_H
295