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