1 // Commit: 95814418f9d6adeba365c795462e8afb00138211
2 /****************************************************************************
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
41 ****************************************************************************/
43 #ifndef QSGLISTVIEW_P_H
44 #define QSGLISTVIEW_P_H
46 #include "qsgflickable_p.h"
48 #include <private/qdeclarativeguard_p.h>
54 QT_MODULE(Declarative)
56 class Q_AUTOTEST_EXPORT QSGViewSection : public QObject
59 Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
60 Q_PROPERTY(SectionCriteria criteria READ criteria WRITE setCriteria NOTIFY criteriaChanged)
61 Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
62 Q_ENUMS(SectionCriteria)
64 QSGViewSection(QObject *parent=0) : QObject(parent), m_criteria(FullString), m_delegate(0) {}
66 QString property() const { return m_property; }
67 void setProperty(const QString &);
69 enum SectionCriteria { FullString, FirstCharacter };
70 SectionCriteria criteria() const { return m_criteria; }
71 void setCriteria(SectionCriteria);
73 QDeclarativeComponent *delegate() const { return m_delegate; }
74 void setDelegate(QDeclarativeComponent *delegate);
76 QString sectionString(const QString &value);
79 void propertyChanged();
80 void criteriaChanged();
81 void delegateChanged();
85 SectionCriteria m_criteria;
86 QDeclarativeComponent *m_delegate;
91 class QSGListViewAttached;
92 class QSGListViewPrivate;
93 class Q_AUTOTEST_EXPORT QSGListView : public QSGFlickable
96 Q_DECLARE_PRIVATE(QSGListView)
98 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
99 Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
100 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
101 Q_PROPERTY(QSGItem *currentItem READ currentItem NOTIFY currentIndexChanged)
102 Q_PROPERTY(int count READ count NOTIFY countChanged)
104 Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
105 Q_PROPERTY(QSGItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
106 Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
107 Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged)
108 Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
109 Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged)
110 Q_PROPERTY(int highlightResizeDuration READ highlightResizeDuration WRITE setHighlightResizeDuration NOTIFY highlightResizeDurationChanged)
112 Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
113 Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
114 Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
116 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
117 Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
118 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
119 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
120 Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
121 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
122 Q_PROPERTY(QSGViewSection *section READ sectionCriteria CONSTANT)
123 Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged)
125 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
127 Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
128 Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
130 Q_ENUMS(HighlightRangeMode)
133 Q_ENUMS(PositionMode)
134 Q_CLASSINFO("DefaultProperty", "data")
137 QSGListView(QSGItem *parent=0);
140 QVariant model() const;
141 void setModel(const QVariant &);
143 QDeclarativeComponent *delegate() const;
144 void setDelegate(QDeclarativeComponent *);
146 int currentIndex() const;
147 void setCurrentIndex(int idx);
149 QSGItem *currentItem();
150 QSGItem *highlightItem();
153 QDeclarativeComponent *highlight() const;
154 void setHighlight(QDeclarativeComponent *highlight);
156 bool highlightFollowsCurrentItem() const;
157 void setHighlightFollowsCurrentItem(bool);
159 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
160 HighlightRangeMode highlightRangeMode() const;
161 void setHighlightRangeMode(HighlightRangeMode mode);
163 qreal preferredHighlightBegin() const;
164 void setPreferredHighlightBegin(qreal);
165 void resetPreferredHighlightBegin();
167 qreal preferredHighlightEnd() const;
168 void setPreferredHighlightEnd(qreal);
169 void resetPreferredHighlightEnd();
171 qreal spacing() const;
172 void setSpacing(qreal spacing);
174 enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical };
175 Orientation orientation() const;
176 void setOrientation(Orientation);
178 Qt::LayoutDirection layoutDirection() const;
179 void setLayoutDirection(Qt::LayoutDirection);
180 Qt::LayoutDirection effectiveLayoutDirection() const;
182 bool isWrapEnabled() const;
183 void setWrapEnabled(bool);
185 int cacheBuffer() const;
186 void setCacheBuffer(int);
188 QSGViewSection *sectionCriteria();
189 QString currentSection() const;
191 qreal highlightMoveSpeed() const;
192 void setHighlightMoveSpeed(qreal);
194 int highlightMoveDuration() const;
195 void setHighlightMoveDuration(int);
197 qreal highlightResizeSpeed() const;
198 void setHighlightResizeSpeed(qreal);
200 int highlightResizeDuration() const;
201 void setHighlightResizeDuration(int);
203 enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
204 SnapMode snapMode() const;
205 void setSnapMode(SnapMode mode);
207 QDeclarativeComponent *footer() const;
208 void setFooter(QDeclarativeComponent *);
210 QDeclarativeComponent *header() const;
211 void setHeader(QDeclarativeComponent *);
213 virtual void setContentX(qreal pos);
214 virtual void setContentY(qreal pos);
216 static QSGListViewAttached *qmlAttachedProperties(QObject *);
218 enum PositionMode { Beginning, Center, End, Visible, Contain };
220 Q_INVOKABLE void positionViewAtIndex(int index, int mode);
221 Q_INVOKABLE int indexAt(qreal x, qreal y) const;
222 Q_INVOKABLE void positionViewAtBeginning();
223 Q_INVOKABLE void positionViewAtEnd();
226 void incrementCurrentIndex();
227 void decrementCurrentIndex();
231 void spacingChanged();
232 void orientationChanged();
233 void layoutDirectionChanged();
234 void effectiveLayoutDirectionChanged();
235 void currentIndexChanged();
236 void currentSectionChanged();
237 void highlightMoveSpeedChanged();
238 void highlightMoveDurationChanged();
239 void highlightResizeSpeedChanged();
240 void highlightResizeDurationChanged();
241 void highlightChanged();
242 void highlightItemChanged();
244 void delegateChanged();
245 void highlightFollowsCurrentItemChanged();
246 void preferredHighlightBeginChanged();
247 void preferredHighlightEndChanged();
248 void highlightRangeModeChanged();
249 void keyNavigationWrapsChanged();
250 void cacheBufferChanged();
251 void snapModeChanged();
252 void headerChanged();
253 void footerChanged();
256 virtual void updatePolish();
257 virtual void viewportMoved();
258 virtual qreal minYExtent() const;
259 virtual qreal maxYExtent() const;
260 virtual qreal minXExtent() const;
261 virtual qreal maxXExtent() const;
262 virtual void keyPressEvent(QKeyEvent *);
263 virtual void geometryChanged(const QRectF &newGeometry,const QRectF &oldGeometry);
264 virtual void componentComplete();
267 void updateSections();
269 void trackedPositionChanged();
270 void itemsInserted(int index, int count);
271 void itemsRemoved(int index, int count);
272 void itemsMoved(int from, int to, int count);
273 void itemsChanged(int index, int count);
275 void destroyRemoved();
276 void createdItem(int index, QSGItem *item);
277 void destroyingItem(QSGItem *item);
281 class QSGListViewAttached : public QObject
285 QSGListViewAttached(QObject *parent)
286 : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
287 ~QSGListViewAttached() {}
289 Q_PROPERTY(QSGListView *view READ view NOTIFY viewChanged)
290 QSGListView *view() { return m_view; }
291 void setView(QSGListView *view) {
292 if (view != m_view) {
298 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
299 bool isCurrentItem() const { return m_isCurrent; }
300 void setIsCurrentItem(bool c) {
301 if (m_isCurrent != c) {
303 emit currentItemChanged();
307 Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
308 QString prevSection() const { return m_prevSection; }
309 void setPrevSection(const QString §) {
310 if (m_prevSection != sect) {
311 m_prevSection = sect;
312 emit prevSectionChanged();
316 Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
317 QString nextSection() const { return m_nextSection; }
318 void setNextSection(const QString §) {
319 if (m_nextSection != sect) {
320 m_nextSection = sect;
321 emit nextSectionChanged();
325 Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
326 QString section() const { return m_section; }
327 void setSection(const QString §) {
328 if (m_section != sect) {
330 emit sectionChanged();
334 Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
335 bool delayRemove() const { return m_delayRemove; }
336 void setDelayRemove(bool delay) {
337 if (m_delayRemove != delay) {
338 m_delayRemove = delay;
339 emit delayRemoveChanged();
343 void emitAdd() { emit add(); }
344 void emitRemove() { emit remove(); }
347 void currentItemChanged();
348 void sectionChanged();
349 void prevSectionChanged();
350 void nextSectionChanged();
351 void delayRemoveChanged();
357 QDeclarativeGuard<QSGListView> m_view;
358 mutable QString m_section;
359 QString m_prevSection;
360 QString m_nextSection;
361 bool m_isCurrent : 1;
362 bool m_delayRemove : 1;
368 QML_DECLARE_TYPEINFO(QSGListView, QML_HAS_ATTACHED_PROPERTIES)
369 QML_DECLARE_TYPE(QSGListView)
370 QML_DECLARE_TYPE(QSGViewSection)
374 #endif // QSGLISTVIEW_P_H