1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QDECLARATIVELISTVIEW_H
43 #define QDECLARATIVELISTVIEW_H
45 #include "private/qdeclarativeflickable_p.h"
46 #include "QtDeclarative/private/qdeclarativeguard_p.h"
52 QT_MODULE(Declarative)
54 class Q_AUTOTEST_EXPORT QDeclarative1ViewSection : public QObject
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)
62 QDeclarative1ViewSection(QObject *parent=0) : QObject(parent), m_criteria(FullString), m_delegate(0) {}
64 QString property() const { return m_property; }
65 void setProperty(const QString &);
67 enum SectionCriteria { FullString, FirstCharacter };
68 SectionCriteria criteria() const { return m_criteria; }
69 void setCriteria(SectionCriteria);
71 QDeclarativeComponent *delegate() const { return m_delegate; }
72 void setDelegate(QDeclarativeComponent *delegate);
74 QString sectionString(const QString &value);
77 void propertyChanged();
78 void criteriaChanged();
79 void delegateChanged();
83 SectionCriteria m_criteria;
84 QDeclarativeComponent *m_delegate;
88 class QDeclarative1VisualModel;
89 class QDeclarative1ListViewAttached;
90 class QDeclarative1ListViewPrivate;
91 class Q_AUTOTEST_EXPORT QDeclarative1ListView : public QDeclarative1Flickable
94 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1ListView)
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)
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)
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)
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)
123 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
125 Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
126 Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
128 Q_ENUMS(HighlightRangeMode)
131 Q_ENUMS(PositionMode)
132 Q_CLASSINFO("DefaultProperty", "data")
135 QDeclarative1ListView(QDeclarativeItem *parent=0);
136 ~QDeclarative1ListView();
138 QVariant model() const;
139 void setModel(const QVariant &);
141 QDeclarativeComponent *delegate() const;
142 void setDelegate(QDeclarativeComponent *);
144 int currentIndex() const;
145 void setCurrentIndex(int idx);
147 QDeclarativeItem *currentItem();
148 QDeclarativeItem *highlightItem();
151 QDeclarativeComponent *highlight() const;
152 void setHighlight(QDeclarativeComponent *highlight);
154 bool highlightFollowsCurrentItem() const;
155 void setHighlightFollowsCurrentItem(bool);
157 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
158 HighlightRangeMode highlightRangeMode() const;
159 void setHighlightRangeMode(HighlightRangeMode mode);
161 qreal preferredHighlightBegin() const;
162 void setPreferredHighlightBegin(qreal);
163 void resetPreferredHighlightBegin();
165 qreal preferredHighlightEnd() const;
166 void setPreferredHighlightEnd(qreal);
167 void resetPreferredHighlightEnd();
169 qreal spacing() const;
170 void setSpacing(qreal spacing);
172 enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical };
173 Orientation orientation() const;
174 void setOrientation(Orientation);
176 Qt::LayoutDirection layoutDirection() const;
177 void setLayoutDirection(Qt::LayoutDirection);
178 Qt::LayoutDirection effectiveLayoutDirection() const;
180 bool isWrapEnabled() const;
181 void setWrapEnabled(bool);
183 int cacheBuffer() const;
184 void setCacheBuffer(int);
186 QDeclarative1ViewSection *sectionCriteria();
187 QString currentSection() const;
189 qreal highlightMoveSpeed() const;
190 void setHighlightMoveSpeed(qreal);
192 int highlightMoveDuration() const;
193 void setHighlightMoveDuration(int);
195 qreal highlightResizeSpeed() const;
196 void setHighlightResizeSpeed(qreal);
198 int highlightResizeDuration() const;
199 void setHighlightResizeDuration(int);
201 enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
202 SnapMode snapMode() const;
203 void setSnapMode(SnapMode mode);
205 QDeclarativeComponent *footer() const;
206 void setFooter(QDeclarativeComponent *);
208 QDeclarativeComponent *header() const;
209 void setHeader(QDeclarativeComponent *);
211 virtual void setContentX(qreal pos);
212 virtual void setContentY(qreal pos);
214 static QDeclarative1ListViewAttached *qmlAttachedProperties(QObject *);
216 enum PositionMode { Beginning, Center, End, Visible, Contain };
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();
224 void incrementCurrentIndex();
225 void decrementCurrentIndex();
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();
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();
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();
265 void updateSections();
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);
273 void destroyRemoved();
274 void createdItem(int index, QDeclarativeItem *item);
275 void destroyingItem(QDeclarativeItem *item);
279 class QDeclarative1ListViewAttached : public QObject
283 QDeclarative1ListViewAttached(QObject *parent)
284 : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
285 ~QDeclarative1ListViewAttached() {}
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) {
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) {
301 emit currentItemChanged();
305 Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
306 QString prevSection() const { return m_prevSection; }
307 void setPrevSection(const QString §) {
308 if (m_prevSection != sect) {
309 m_prevSection = sect;
310 emit prevSectionChanged();
314 Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
315 QString nextSection() const { return m_nextSection; }
316 void setNextSection(const QString §) {
317 if (m_nextSection != sect) {
318 m_nextSection = sect;
319 emit nextSectionChanged();
323 Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
324 QString section() const { return m_section; }
325 void setSection(const QString §) {
326 if (m_section != sect) {
328 emit sectionChanged();
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();
341 void emitAdd() { emit add(); }
342 void emitRemove() { emit remove(); }
345 void currentItemChanged();
346 void sectionChanged();
347 void prevSectionChanged();
348 void nextSectionChanged();
349 void delayRemoveChanged();
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;
365 QML_DECLARE_TYPEINFO(QDeclarative1ListView, QML_HAS_ATTACHED_PROPERTIES)
366 QML_DECLARE_TYPE(QDeclarative1ListView)
367 QML_DECLARE_TYPE(QDeclarative1ViewSection)