1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QDECLARATIVELISTVIEW_H
43 #define QDECLARATIVELISTVIEW_H
45 #include "private/qdeclarativeflickable_p.h"
46 #include "QtDeclarative/private/qdeclarativeguard_p.h"
53 class Q_AUTOTEST_EXPORT QDeclarative1ViewSection : public QObject
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)
61 QDeclarative1ViewSection(QObject *parent=0) : QObject(parent), m_criteria(FullString), m_delegate(0) {}
63 QString property() const { return m_property; }
64 void setProperty(const QString &);
66 enum SectionCriteria { FullString, FirstCharacter };
67 SectionCriteria criteria() const { return m_criteria; }
68 void setCriteria(SectionCriteria);
70 QDeclarativeComponent *delegate() const { return m_delegate; }
71 void setDelegate(QDeclarativeComponent *delegate);
73 QString sectionString(const QString &value);
76 void propertyChanged();
77 void criteriaChanged();
78 void delegateChanged();
82 SectionCriteria m_criteria;
83 QDeclarativeComponent *m_delegate;
87 class QDeclarative1VisualModel;
88 class QDeclarative1ListViewAttached;
89 class QDeclarative1ListViewPrivate;
90 class Q_AUTOTEST_EXPORT QDeclarative1ListView : public QDeclarative1Flickable
93 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1ListView)
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)
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)
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)
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)
122 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
124 Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
125 Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
127 Q_ENUMS(HighlightRangeMode)
130 Q_ENUMS(PositionMode)
131 Q_CLASSINFO("DefaultProperty", "data")
134 QDeclarative1ListView(QDeclarativeItem *parent=0);
135 ~QDeclarative1ListView();
137 QVariant model() const;
138 void setModel(const QVariant &);
140 QDeclarativeComponent *delegate() const;
141 void setDelegate(QDeclarativeComponent *);
143 int currentIndex() const;
144 void setCurrentIndex(int idx);
146 QDeclarativeItem *currentItem();
147 QDeclarativeItem *highlightItem();
150 QDeclarativeComponent *highlight() const;
151 void setHighlight(QDeclarativeComponent *highlight);
153 bool highlightFollowsCurrentItem() const;
154 void setHighlightFollowsCurrentItem(bool);
156 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
157 HighlightRangeMode highlightRangeMode() const;
158 void setHighlightRangeMode(HighlightRangeMode mode);
160 qreal preferredHighlightBegin() const;
161 void setPreferredHighlightBegin(qreal);
162 void resetPreferredHighlightBegin();
164 qreal preferredHighlightEnd() const;
165 void setPreferredHighlightEnd(qreal);
166 void resetPreferredHighlightEnd();
168 qreal spacing() const;
169 void setSpacing(qreal spacing);
171 enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical };
172 Orientation orientation() const;
173 void setOrientation(Orientation);
175 Qt::LayoutDirection layoutDirection() const;
176 void setLayoutDirection(Qt::LayoutDirection);
177 Qt::LayoutDirection effectiveLayoutDirection() const;
179 bool isWrapEnabled() const;
180 void setWrapEnabled(bool);
182 int cacheBuffer() const;
183 void setCacheBuffer(int);
185 QDeclarative1ViewSection *sectionCriteria();
186 QString currentSection() const;
188 qreal highlightMoveSpeed() const;
189 void setHighlightMoveSpeed(qreal);
191 int highlightMoveDuration() const;
192 void setHighlightMoveDuration(int);
194 qreal highlightResizeSpeed() const;
195 void setHighlightResizeSpeed(qreal);
197 int highlightResizeDuration() const;
198 void setHighlightResizeDuration(int);
200 enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
201 SnapMode snapMode() const;
202 void setSnapMode(SnapMode mode);
204 QDeclarativeComponent *footer() const;
205 void setFooter(QDeclarativeComponent *);
207 QDeclarativeComponent *header() const;
208 void setHeader(QDeclarativeComponent *);
210 virtual void setContentX(qreal pos);
211 virtual void setContentY(qreal pos);
213 static QDeclarative1ListViewAttached *qmlAttachedProperties(QObject *);
215 enum PositionMode { Beginning, Center, End, Visible, Contain };
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();
223 void incrementCurrentIndex();
224 void decrementCurrentIndex();
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();
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();
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();
264 void updateSections();
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);
272 void destroyRemoved();
273 void createdItem(int index, QDeclarativeItem *item);
274 void destroyingItem(QDeclarativeItem *item);
278 class QDeclarative1ListViewAttached : public QObject
282 QDeclarative1ListViewAttached(QObject *parent)
283 : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
284 ~QDeclarative1ListViewAttached() {}
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) {
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) {
300 emit currentItemChanged();
304 Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
305 QString prevSection() const { return m_prevSection; }
306 void setPrevSection(const QString §) {
307 if (m_prevSection != sect) {
308 m_prevSection = sect;
309 emit prevSectionChanged();
313 Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
314 QString nextSection() const { return m_nextSection; }
315 void setNextSection(const QString §) {
316 if (m_nextSection != sect) {
317 m_nextSection = sect;
318 emit nextSectionChanged();
322 Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
323 QString section() const { return m_section; }
324 void setSection(const QString §) {
325 if (m_section != sect) {
327 emit sectionChanged();
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();
340 void emitAdd() { emit add(); }
341 void emitRemove() { emit remove(); }
344 void currentItemChanged();
345 void sectionChanged();
346 void prevSectionChanged();
347 void nextSectionChanged();
348 void delayRemoveChanged();
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;
364 QML_DECLARE_TYPEINFO(QDeclarative1ListView, QML_HAS_ATTACHED_PROPERTIES)
365 QML_DECLARE_TYPE(QDeclarative1ListView)
366 QML_DECLARE_TYPE(QDeclarative1ViewSection)