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