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 QQUICKITEMVIEW_P_H
43 #define QQUICKITEMVIEW_P_H
45 #include "qquickflickable_p.h"
51 QT_MODULE(Declarative)
53 class QDeclarativeChangeSet;
55 class QQuickItemViewPrivate;
57 class Q_AUTOTEST_EXPORT QQuickItemView : public QQuickFlickable
61 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
62 Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
63 Q_PROPERTY(int count READ count NOTIFY countChanged)
65 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
66 Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged)
68 Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
69 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
71 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
72 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
74 Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
75 Q_PROPERTY(QQuickItem *headerItem READ headerItem NOTIFY headerItemChanged)
76 Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
77 Q_PROPERTY(QQuickItem *footerItem READ footerItem NOTIFY footerItemChanged)
79 Q_PROPERTY(QDeclarativeTransition *populate READ populateTransition WRITE setPopulateTransition NOTIFY populateTransitionChanged)
80 Q_PROPERTY(QDeclarativeTransition *add READ addTransition WRITE setAddTransition NOTIFY addTransitionChanged)
81 Q_PROPERTY(QDeclarativeTransition *addDisplaced READ addDisplacedTransition WRITE setAddDisplacedTransition NOTIFY addDisplacedTransitionChanged)
82 Q_PROPERTY(QDeclarativeTransition *move READ moveTransition WRITE setMoveTransition NOTIFY moveTransitionChanged)
83 Q_PROPERTY(QDeclarativeTransition *moveDisplaced READ moveDisplacedTransition WRITE setMoveDisplacedTransition NOTIFY moveDisplacedTransitionChanged)
84 Q_PROPERTY(QDeclarativeTransition *remove READ removeTransition WRITE setRemoveTransition NOTIFY removeTransitionChanged)
85 Q_PROPERTY(QDeclarativeTransition *removeDisplaced READ removeDisplacedTransition WRITE setRemoveDisplacedTransition NOTIFY removeDisplacedTransitionChanged)
86 Q_PROPERTY(QDeclarativeTransition *displaced READ displacedTransition WRITE setDisplacedTransition NOTIFY displacedTransitionChanged)
88 Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
89 Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
90 Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
91 Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
92 Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
93 Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
94 Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
96 Q_ENUMS(HighlightRangeMode)
100 QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent = 0);
103 QVariant model() const;
104 void setModel(const QVariant &);
106 QDeclarativeComponent *delegate() const;
107 void setDelegate(QDeclarativeComponent *);
111 int currentIndex() const;
112 void setCurrentIndex(int idx);
114 QQuickItem *currentItem() const;
116 bool isWrapEnabled() const;
117 void setWrapEnabled(bool);
119 int cacheBuffer() const;
120 void setCacheBuffer(int);
122 Qt::LayoutDirection layoutDirection() const;
123 void setLayoutDirection(Qt::LayoutDirection);
124 Qt::LayoutDirection effectiveLayoutDirection() const;
126 QDeclarativeComponent *footer() const;
127 void setFooter(QDeclarativeComponent *);
128 QQuickItem *footerItem() const;
130 QDeclarativeComponent *header() const;
131 void setHeader(QDeclarativeComponent *);
132 QQuickItem *headerItem() const;
134 QDeclarativeTransition *populateTransition() const;
135 void setPopulateTransition(QDeclarativeTransition *transition);
137 QDeclarativeTransition *addTransition() const;
138 void setAddTransition(QDeclarativeTransition *transition);
140 QDeclarativeTransition *addDisplacedTransition() const;
141 void setAddDisplacedTransition(QDeclarativeTransition *transition);
143 QDeclarativeTransition *moveTransition() const;
144 void setMoveTransition(QDeclarativeTransition *transition);
146 QDeclarativeTransition *moveDisplacedTransition() const;
147 void setMoveDisplacedTransition(QDeclarativeTransition *transition);
149 QDeclarativeTransition *removeTransition() const;
150 void setRemoveTransition(QDeclarativeTransition *transition);
152 QDeclarativeTransition *removeDisplacedTransition() const;
153 void setRemoveDisplacedTransition(QDeclarativeTransition *transition);
155 QDeclarativeTransition *displacedTransition() const;
156 void setDisplacedTransition(QDeclarativeTransition *transition);
158 QDeclarativeComponent *highlight() const;
159 void setHighlight(QDeclarativeComponent *);
161 QQuickItem *highlightItem() const;
163 bool highlightFollowsCurrentItem() const;
164 virtual void setHighlightFollowsCurrentItem(bool);
166 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
167 HighlightRangeMode highlightRangeMode() const;
168 void setHighlightRangeMode(HighlightRangeMode mode);
170 qreal preferredHighlightBegin() const;
171 void setPreferredHighlightBegin(qreal);
172 void resetPreferredHighlightBegin();
174 qreal preferredHighlightEnd() const;
175 void setPreferredHighlightEnd(qreal);
176 void resetPreferredHighlightEnd();
178 int highlightMoveDuration() const;
179 virtual void setHighlightMoveDuration(int);
181 enum PositionMode { Beginning, Center, End, Visible, Contain };
183 Q_INVOKABLE void positionViewAtIndex(int index, int mode);
184 Q_INVOKABLE int indexAt(qreal x, qreal y) const;
185 Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const;
186 Q_INVOKABLE void positionViewAtBeginning();
187 Q_INVOKABLE void positionViewAtEnd();
189 virtual void setContentX(qreal pos);
190 virtual void setContentY(qreal pos);
191 virtual qreal xOrigin() const;
195 void delegateChanged();
197 void currentIndexChanged();
198 void currentItemChanged();
200 void keyNavigationWrapsChanged();
201 void cacheBufferChanged();
203 void layoutDirectionChanged();
204 void effectiveLayoutDirectionChanged();
206 void headerChanged();
207 void footerChanged();
208 void headerItemChanged();
209 void footerItemChanged();
211 void populateTransitionChanged();
212 void addTransitionChanged();
213 void addDisplacedTransitionChanged();
214 void moveTransitionChanged();
215 void moveDisplacedTransitionChanged();
216 void removeTransitionChanged();
217 void removeDisplacedTransitionChanged();
218 void displacedTransitionChanged();
220 void highlightChanged();
221 void highlightItemChanged();
222 void highlightFollowsCurrentItemChanged();
223 void highlightRangeModeChanged();
224 void preferredHighlightBeginChanged();
225 void preferredHighlightEndChanged();
226 void highlightMoveDurationChanged();
229 virtual void updatePolish();
230 virtual void componentComplete();
231 virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
232 virtual qreal minYExtent() const;
233 virtual qreal maxYExtent() const;
234 virtual qreal minXExtent() const;
235 virtual qreal maxXExtent() const;
238 virtual void updateSections() {}
239 void destroyRemoved();
240 void createdItem(int index, QQuickItem *item);
241 void initItem(int index, QQuickItem *item);
242 void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset);
243 void destroyingItem(QQuickItem *item);
245 void trackedPositionChanged();
248 Q_DECLARE_PRIVATE(QQuickItemView)
252 class Q_AUTOTEST_EXPORT QQuickItemViewAttached : public QObject
256 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
257 Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
259 Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
260 Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
261 Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
264 QQuickItemViewAttached(QObject *parent)
265 : QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
266 ~QQuickItemViewAttached() {}
268 bool isCurrentItem() const { return m_isCurrent; }
269 void setIsCurrentItem(bool c) {
270 if (m_isCurrent != c) {
272 emit currentItemChanged();
276 bool delayRemove() const { return m_delayRemove; }
277 void setDelayRemove(bool delay) {
278 if (m_delayRemove != delay) {
279 m_delayRemove = delay;
280 emit delayRemoveChanged();
284 QString section() const { return m_section; }
285 void setSection(const QString §) {
286 if (m_section != sect) {
288 emit sectionChanged();
292 QString prevSection() const { return m_prevSection; }
293 void setPrevSection(const QString §) {
294 if (m_prevSection != sect) {
295 m_prevSection = sect;
296 emit prevSectionChanged();
300 QString nextSection() const { return m_nextSection; }
301 void setNextSection(const QString §) {
302 if (m_nextSection != sect) {
303 m_nextSection = sect;
304 emit nextSectionChanged();
308 void emitAdd() { emit add(); }
309 void emitRemove() { emit remove(); }
312 void currentItemChanged();
313 void delayRemoveChanged();
318 void sectionChanged();
319 void prevSectionChanged();
320 void nextSectionChanged();
323 bool m_isCurrent : 1;
324 bool m_delayRemove : 1;
326 // current only used by list view
327 mutable QString m_section;
328 QString m_prevSection;
329 QString m_nextSection;
337 #endif // QQUICKITEMVIEW_P_H