1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
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 QQUICKITEMVIEW_P_H
43 #define QQUICKITEMVIEW_P_H
45 #include "qquickflickable_p.h"
51 class QDeclarativeChangeSet;
53 class QQuickItemViewPrivate;
55 class Q_AUTOTEST_EXPORT QQuickItemView : public QQuickFlickable
59 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
60 Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
61 Q_PROPERTY(int count READ count NOTIFY countChanged)
63 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
64 Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged)
66 Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
67 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
69 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
70 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
72 Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
73 Q_PROPERTY(QQuickItem *headerItem READ headerItem NOTIFY headerItemChanged)
74 Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
75 Q_PROPERTY(QQuickItem *footerItem READ footerItem NOTIFY footerItemChanged)
77 Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
78 Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
79 Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
80 Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
81 Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
82 Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
83 Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
85 Q_ENUMS(HighlightRangeMode)
89 QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent = 0);
92 QVariant model() const;
93 void setModel(const QVariant &);
95 QDeclarativeComponent *delegate() const;
96 void setDelegate(QDeclarativeComponent *);
100 int currentIndex() const;
101 void setCurrentIndex(int idx);
103 QQuickItem *currentItem() const;
105 bool isWrapEnabled() const;
106 void setWrapEnabled(bool);
108 int cacheBuffer() const;
109 void setCacheBuffer(int);
111 Qt::LayoutDirection layoutDirection() const;
112 void setLayoutDirection(Qt::LayoutDirection);
113 Qt::LayoutDirection effectiveLayoutDirection() const;
115 QDeclarativeComponent *footer() const;
116 void setFooter(QDeclarativeComponent *);
117 QQuickItem *footerItem() const;
119 QDeclarativeComponent *header() const;
120 void setHeader(QDeclarativeComponent *);
121 QQuickItem *headerItem() const;
123 QDeclarativeComponent *highlight() const;
124 void setHighlight(QDeclarativeComponent *);
126 QQuickItem *highlightItem() const;
128 bool highlightFollowsCurrentItem() const;
129 virtual void setHighlightFollowsCurrentItem(bool);
131 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
132 HighlightRangeMode highlightRangeMode() const;
133 void setHighlightRangeMode(HighlightRangeMode mode);
135 qreal preferredHighlightBegin() const;
136 void setPreferredHighlightBegin(qreal);
137 void resetPreferredHighlightBegin();
139 qreal preferredHighlightEnd() const;
140 void setPreferredHighlightEnd(qreal);
141 void resetPreferredHighlightEnd();
143 int highlightMoveDuration() const;
144 virtual void setHighlightMoveDuration(int);
146 enum PositionMode { Beginning, Center, End, Visible, Contain };
148 Q_INVOKABLE void positionViewAtIndex(int index, int mode);
149 Q_INVOKABLE int indexAt(qreal x, qreal y) const;
150 Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const;
151 Q_INVOKABLE void positionViewAtBeginning();
152 Q_INVOKABLE void positionViewAtEnd();
154 virtual void setContentX(qreal pos);
155 virtual void setContentY(qreal pos);
156 virtual qreal xOrigin() const;
160 void delegateChanged();
162 void currentIndexChanged();
163 void currentItemChanged();
165 void keyNavigationWrapsChanged();
166 void cacheBufferChanged();
168 void layoutDirectionChanged();
169 void effectiveLayoutDirectionChanged();
171 void headerChanged();
172 void footerChanged();
173 void headerItemChanged();
174 void footerItemChanged();
176 void highlightChanged();
177 void highlightItemChanged();
178 void highlightFollowsCurrentItemChanged();
179 void highlightRangeModeChanged();
180 void preferredHighlightBeginChanged();
181 void preferredHighlightEndChanged();
182 void highlightMoveDurationChanged();
185 virtual void updatePolish();
186 virtual void componentComplete();
187 virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
188 virtual qreal minYExtent() const;
189 virtual qreal maxYExtent() const;
190 virtual qreal minXExtent() const;
191 virtual qreal maxXExtent() const;
194 virtual void updateSections() {}
195 void destroyRemoved();
196 void createdItem(int index, QQuickItem *item);
197 void initItem(int index, QQuickItem *item);
198 void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset);
199 void destroyingItem(QQuickItem *item);
201 void trackedPositionChanged();
206 Q_DECLARE_PRIVATE(QQuickItemView)
210 class Q_AUTOTEST_EXPORT QQuickItemViewAttached : public QObject
214 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
215 Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
217 Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
218 Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
219 Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
222 QQuickItemViewAttached(QObject *parent)
223 : QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
224 ~QQuickItemViewAttached() {}
226 bool isCurrentItem() const { return m_isCurrent; }
227 void setIsCurrentItem(bool c) {
228 if (m_isCurrent != c) {
230 emit currentItemChanged();
234 bool delayRemove() const { return m_delayRemove; }
235 void setDelayRemove(bool delay) {
236 if (m_delayRemove != delay) {
237 m_delayRemove = delay;
238 emit delayRemoveChanged();
242 QString section() const { return m_section; }
243 void setSection(const QString §) {
244 if (m_section != sect) {
246 emit sectionChanged();
250 QString prevSection() const { return m_prevSection; }
251 void setPrevSection(const QString §) {
252 if (m_prevSection != sect) {
253 m_prevSection = sect;
254 emit prevSectionChanged();
258 QString nextSection() const { return m_nextSection; }
259 void setNextSection(const QString §) {
260 if (m_nextSection != sect) {
261 m_nextSection = sect;
262 emit nextSectionChanged();
266 void emitAdd() { emit add(); }
267 void emitRemove() { emit remove(); }
270 void currentItemChanged();
271 void delayRemoveChanged();
276 void sectionChanged();
277 void prevSectionChanged();
278 void nextSectionChanged();
281 bool m_isCurrent : 1;
282 bool m_delayRemove : 1;
284 // current only used by list view
285 mutable QString m_section;
286 QString m_prevSection;
287 QString m_nextSection;
294 #endif // QQUICKITEMVIEW_P_H