Merge branch 'master' into refactor
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativelistview_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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 QDECLARATIVELISTVIEW_H
43 #define QDECLARATIVELISTVIEW_H
44
45 #include "private/qdeclarativeflickable_p.h"
46 #include "QtDeclarative/private/qdeclarativeguard_p.h"
47
48 QT_BEGIN_HEADER
49
50 QT_BEGIN_NAMESPACE
51
52 QT_MODULE(Declarative)
53
54 class Q_AUTOTEST_EXPORT QDeclarative1ViewSection : public QObject
55 {
56     Q_OBJECT
57     Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
58     Q_PROPERTY(SectionCriteria criteria READ criteria WRITE setCriteria NOTIFY criteriaChanged)
59     Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
60     Q_ENUMS(SectionCriteria)
61 public:
62     QDeclarative1ViewSection(QObject *parent=0) : QObject(parent), m_criteria(FullString), m_delegate(0) {}
63
64     QString property() const { return m_property; }
65     void setProperty(const QString &);
66
67     enum SectionCriteria { FullString, FirstCharacter };
68     SectionCriteria criteria() const { return m_criteria; }
69     void setCriteria(SectionCriteria);
70
71     QDeclarativeComponent *delegate() const { return m_delegate; }
72     void setDelegate(QDeclarativeComponent *delegate);
73
74     QString sectionString(const QString &value);
75
76 Q_SIGNALS:
77     void propertyChanged();
78     void criteriaChanged();
79     void delegateChanged();
80
81 private:
82     QString m_property;
83     SectionCriteria m_criteria;
84     QDeclarativeComponent *m_delegate;
85 };
86
87
88 class QDeclarative1VisualModel;
89 class QDeclarative1ListViewAttached;
90 class QDeclarative1ListViewPrivate;
91 class Q_AUTOTEST_EXPORT QDeclarative1ListView : public QDeclarative1Flickable
92 {
93     Q_OBJECT
94     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1ListView)
95
96     Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
97     Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
98     Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
99     Q_PROPERTY(QDeclarativeItem *currentItem READ currentItem NOTIFY currentIndexChanged)
100     Q_PROPERTY(int count READ count NOTIFY countChanged)
101
102     Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
103     Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
104     Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
105     Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged)
106     Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
107     Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged)
108     Q_PROPERTY(int highlightResizeDuration READ highlightResizeDuration WRITE setHighlightResizeDuration NOTIFY highlightResizeDurationChanged)
109
110     Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
111     Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
112     Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
113
114     Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
115     Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
116     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged REVISION 1)
117     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged REVISION 1)
118     Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
119     Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
120     Q_PROPERTY(QDeclarative1ViewSection *section READ sectionCriteria CONSTANT)
121     Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged)
122
123     Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
124
125     Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
126     Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
127
128     Q_ENUMS(HighlightRangeMode)
129     Q_ENUMS(Orientation)
130     Q_ENUMS(SnapMode)
131     Q_ENUMS(PositionMode)
132     Q_CLASSINFO("DefaultProperty", "data")
133
134 public:
135     QDeclarative1ListView(QDeclarativeItem *parent=0);
136     ~QDeclarative1ListView();
137
138     QVariant model() const;
139     void setModel(const QVariant &);
140
141     QDeclarativeComponent *delegate() const;
142     void setDelegate(QDeclarativeComponent *);
143
144     int currentIndex() const;
145     void setCurrentIndex(int idx);
146
147     QDeclarativeItem *currentItem();
148     QDeclarativeItem *highlightItem();
149     int count() const;
150
151     QDeclarativeComponent *highlight() const;
152     void setHighlight(QDeclarativeComponent *highlight);
153
154     bool highlightFollowsCurrentItem() const;
155     void setHighlightFollowsCurrentItem(bool);
156
157     enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
158     HighlightRangeMode highlightRangeMode() const;
159     void setHighlightRangeMode(HighlightRangeMode mode);
160
161     qreal preferredHighlightBegin() const;
162     void setPreferredHighlightBegin(qreal);
163     void resetPreferredHighlightBegin();
164
165     qreal preferredHighlightEnd() const;
166     void setPreferredHighlightEnd(qreal);
167     void resetPreferredHighlightEnd();
168
169     qreal spacing() const;
170     void setSpacing(qreal spacing);
171
172     enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical };
173     Orientation orientation() const;
174     void setOrientation(Orientation);
175
176     Qt::LayoutDirection layoutDirection() const;
177     void setLayoutDirection(Qt::LayoutDirection);
178     Qt::LayoutDirection effectiveLayoutDirection() const;
179
180     bool isWrapEnabled() const;
181     void setWrapEnabled(bool);
182
183     int cacheBuffer() const;
184     void setCacheBuffer(int);
185
186     QDeclarative1ViewSection *sectionCriteria();
187     QString currentSection() const;
188
189     qreal highlightMoveSpeed() const;
190     void setHighlightMoveSpeed(qreal);
191
192     int highlightMoveDuration() const;
193     void setHighlightMoveDuration(int);
194
195     qreal highlightResizeSpeed() const;
196     void setHighlightResizeSpeed(qreal);
197
198     int highlightResizeDuration() const;
199     void setHighlightResizeDuration(int);
200
201     enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
202     SnapMode snapMode() const;
203     void setSnapMode(SnapMode mode);
204
205     QDeclarativeComponent *footer() const;
206     void setFooter(QDeclarativeComponent *);
207
208     QDeclarativeComponent *header() const;
209     void setHeader(QDeclarativeComponent *);
210
211     virtual void setContentX(qreal pos);
212     virtual void setContentY(qreal pos);
213
214     static QDeclarative1ListViewAttached *qmlAttachedProperties(QObject *);
215
216     enum PositionMode { Beginning, Center, End, Visible, Contain };
217
218     Q_INVOKABLE void positionViewAtIndex(int index, int mode);
219     Q_INVOKABLE int indexAt(qreal x, qreal y) const;
220     Q_INVOKABLE Q_REVISION(1) void positionViewAtBeginning();
221     Q_INVOKABLE Q_REVISION(1) void positionViewAtEnd();
222
223 public Q_SLOTS:
224     void incrementCurrentIndex();
225     void decrementCurrentIndex();
226
227 Q_SIGNALS:
228     void countChanged();
229     void spacingChanged();
230     void orientationChanged();
231     Q_REVISION(1) void layoutDirectionChanged();
232     Q_REVISION(1) void effectiveLayoutDirectionChanged();
233     void currentIndexChanged();
234     void currentSectionChanged();
235     void highlightMoveSpeedChanged();
236     void highlightMoveDurationChanged();
237     void highlightResizeSpeedChanged();
238     void highlightResizeDurationChanged();
239     void highlightChanged();
240     void highlightItemChanged();
241     void modelChanged();
242     void delegateChanged();
243     void highlightFollowsCurrentItemChanged();
244     void preferredHighlightBeginChanged();
245     void preferredHighlightEndChanged();
246     void highlightRangeModeChanged();
247     void keyNavigationWrapsChanged();
248     void cacheBufferChanged();
249     void snapModeChanged();
250     void headerChanged();
251     void footerChanged();
252
253 protected:
254     virtual bool event(QEvent *event);
255     virtual void viewportMoved();
256     virtual qreal minYExtent() const;
257     virtual qreal maxYExtent() const;
258     virtual qreal minXExtent() const;
259     virtual qreal maxXExtent() const;
260     virtual void keyPressEvent(QKeyEvent *);
261     virtual void geometryChanged(const QRectF &newGeometry,const QRectF &oldGeometry);
262     virtual void componentComplete();
263
264 private Q_SLOTS:
265     void updateSections();
266     void refill();
267     void trackedPositionChanged();
268     void itemsInserted(int index, int count);
269     void itemsRemoved(int index, int count);
270     void itemsMoved(int from, int to, int count);
271     void itemsChanged(int index, int count);
272     void modelReset();
273     void destroyRemoved();
274     void createdItem(int index, QDeclarativeItem *item);
275     void destroyingItem(QDeclarativeItem *item);
276     void animStopped();
277 };
278
279 class QDeclarative1ListViewAttached : public QObject
280 {
281     Q_OBJECT
282 public:
283     QDeclarative1ListViewAttached(QObject *parent)
284         : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
285     ~QDeclarative1ListViewAttached() {}
286
287     Q_PROPERTY(QDeclarative1ListView *view READ view NOTIFY viewChanged)
288     QDeclarative1ListView *view() { return m_view; }
289     void setView(QDeclarative1ListView *view) {
290         if (view != m_view) {
291             m_view = view;
292             emit viewChanged();
293         }
294     }
295
296     Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
297     bool isCurrentItem() const { return m_isCurrent; }
298     void setIsCurrentItem(bool c) {
299         if (m_isCurrent != c) {
300             m_isCurrent = c;
301             emit currentItemChanged();
302         }
303     }
304
305     Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
306     QString prevSection() const { return m_prevSection; }
307     void setPrevSection(const QString &sect) {
308         if (m_prevSection != sect) {
309             m_prevSection = sect;
310             emit prevSectionChanged();
311         }
312     }
313
314     Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
315     QString nextSection() const { return m_nextSection; }
316     void setNextSection(const QString &sect) {
317         if (m_nextSection != sect) {
318             m_nextSection = sect;
319             emit nextSectionChanged();
320         }
321     }
322
323     Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
324     QString section() const { return m_section; }
325     void setSection(const QString &sect) {
326         if (m_section != sect) {
327             m_section = sect;
328             emit sectionChanged();
329         }
330     }
331
332     Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
333     bool delayRemove() const { return m_delayRemove; }
334     void setDelayRemove(bool delay) {
335         if (m_delayRemove != delay) {
336             m_delayRemove = delay;
337             emit delayRemoveChanged();
338         }
339     }
340
341     void emitAdd() { emit add(); }
342     void emitRemove() { emit remove(); }
343
344 Q_SIGNALS:
345     void currentItemChanged();
346     void sectionChanged();
347     void prevSectionChanged();
348     void nextSectionChanged();
349     void delayRemoveChanged();
350     void add();
351     void remove();
352     void viewChanged();
353
354 public:
355     QDeclarativeGuard<QDeclarative1ListView> m_view;
356     mutable QString m_section;
357     QString m_prevSection;
358     QString m_nextSection;
359     bool m_isCurrent : 1;
360     bool m_delayRemove : 1;
361 };
362
363 QT_END_NAMESPACE
364
365 QML_DECLARE_TYPEINFO(QDeclarative1ListView, QML_HAS_ATTACHED_PROPERTIES)
366 QML_DECLARE_TYPE(QDeclarative1ListView)
367 QML_DECLARE_TYPE(QDeclarative1ViewSection)
368
369 QT_END_HEADER
370
371 #endif