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 QtQml 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"
53 class QQuickChangeSet;
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(QQmlComponent *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)
73 Q_PROPERTY(VerticalLayoutDirection verticalLayoutDirection READ verticalLayoutDirection WRITE setVerticalLayoutDirection NOTIFY verticalLayoutDirectionChanged)
75 Q_PROPERTY(QQmlComponent *header READ header WRITE setHeader NOTIFY headerChanged)
76 Q_PROPERTY(QQuickItem *headerItem READ headerItem NOTIFY headerItemChanged)
77 Q_PROPERTY(QQmlComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
78 Q_PROPERTY(QQuickItem *footerItem READ footerItem NOTIFY footerItemChanged)
80 Q_PROPERTY(QQuickTransition *populate READ populateTransition WRITE setPopulateTransition NOTIFY populateTransitionChanged)
81 Q_PROPERTY(QQuickTransition *add READ addTransition WRITE setAddTransition NOTIFY addTransitionChanged)
82 Q_PROPERTY(QQuickTransition *addDisplaced READ addDisplacedTransition WRITE setAddDisplacedTransition NOTIFY addDisplacedTransitionChanged)
83 Q_PROPERTY(QQuickTransition *move READ moveTransition WRITE setMoveTransition NOTIFY moveTransitionChanged)
84 Q_PROPERTY(QQuickTransition *moveDisplaced READ moveDisplacedTransition WRITE setMoveDisplacedTransition NOTIFY moveDisplacedTransitionChanged)
85 Q_PROPERTY(QQuickTransition *remove READ removeTransition WRITE setRemoveTransition NOTIFY removeTransitionChanged)
86 Q_PROPERTY(QQuickTransition *removeDisplaced READ removeDisplacedTransition WRITE setRemoveDisplacedTransition NOTIFY removeDisplacedTransitionChanged)
87 Q_PROPERTY(QQuickTransition *displaced READ displacedTransition WRITE setDisplacedTransition NOTIFY displacedTransitionChanged)
89 Q_PROPERTY(QQmlComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
90 Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
91 Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
92 Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
93 Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
94 Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
95 Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
97 Q_ENUMS(HighlightRangeMode)
99 Q_ENUMS(VerticalLayoutDirection)
100 Q_ENUMS(LayoutDirection)
103 // this holds all layout enum values so they can be referred to by other enums
104 // to ensure consistent values - e.g. QML references to GridView.TopToBottom flow
105 // and GridView.TopToBottom vertical layout direction should have same value
106 enum LayoutDirection {
107 LeftToRight = Qt::LeftToRight,
108 RightToLeft = Qt::RightToLeft,
113 enum VerticalLayoutDirection {
114 TopToBottom = VerticalTopToBottom,
115 BottomToTop = VerticalBottomToTop
118 QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent = 0);
121 QVariant model() const;
122 void setModel(const QVariant &);
124 QQmlComponent *delegate() const;
125 void setDelegate(QQmlComponent *);
129 int currentIndex() const;
130 void setCurrentIndex(int idx);
132 QQuickItem *currentItem() const;
134 bool isWrapEnabled() const;
135 void setWrapEnabled(bool);
137 int cacheBuffer() const;
138 void setCacheBuffer(int);
140 Qt::LayoutDirection layoutDirection() const;
141 void setLayoutDirection(Qt::LayoutDirection);
142 Qt::LayoutDirection effectiveLayoutDirection() const;
144 VerticalLayoutDirection verticalLayoutDirection() const;
145 void setVerticalLayoutDirection(VerticalLayoutDirection layoutDirection);
147 QQmlComponent *footer() const;
148 void setFooter(QQmlComponent *);
149 QQuickItem *footerItem() const;
151 QQmlComponent *header() const;
152 void setHeader(QQmlComponent *);
153 QQuickItem *headerItem() const;
155 QQuickTransition *populateTransition() const;
156 void setPopulateTransition(QQuickTransition *transition);
158 QQuickTransition *addTransition() const;
159 void setAddTransition(QQuickTransition *transition);
161 QQuickTransition *addDisplacedTransition() const;
162 void setAddDisplacedTransition(QQuickTransition *transition);
164 QQuickTransition *moveTransition() const;
165 void setMoveTransition(QQuickTransition *transition);
167 QQuickTransition *moveDisplacedTransition() const;
168 void setMoveDisplacedTransition(QQuickTransition *transition);
170 QQuickTransition *removeTransition() const;
171 void setRemoveTransition(QQuickTransition *transition);
173 QQuickTransition *removeDisplacedTransition() const;
174 void setRemoveDisplacedTransition(QQuickTransition *transition);
176 QQuickTransition *displacedTransition() const;
177 void setDisplacedTransition(QQuickTransition *transition);
179 QQmlComponent *highlight() const;
180 void setHighlight(QQmlComponent *);
182 QQuickItem *highlightItem() const;
184 bool highlightFollowsCurrentItem() const;
185 virtual void setHighlightFollowsCurrentItem(bool);
187 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
188 HighlightRangeMode highlightRangeMode() const;
189 void setHighlightRangeMode(HighlightRangeMode mode);
191 qreal preferredHighlightBegin() const;
192 void setPreferredHighlightBegin(qreal);
193 void resetPreferredHighlightBegin();
195 qreal preferredHighlightEnd() const;
196 void setPreferredHighlightEnd(qreal);
197 void resetPreferredHighlightEnd();
199 int highlightMoveDuration() const;
200 virtual void setHighlightMoveDuration(int);
202 enum PositionMode { Beginning, Center, End, Visible, Contain };
204 Q_INVOKABLE void positionViewAtIndex(int index, int mode);
205 Q_INVOKABLE int indexAt(qreal x, qreal y) const;
206 Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const;
207 Q_INVOKABLE void positionViewAtBeginning();
208 Q_INVOKABLE void positionViewAtEnd();
210 virtual void setContentX(qreal pos);
211 virtual void setContentY(qreal pos);
212 virtual qreal originX() const;
213 virtual qreal originY() const;
217 void delegateChanged();
219 void currentIndexChanged();
220 void currentItemChanged();
222 void keyNavigationWrapsChanged();
223 void cacheBufferChanged();
225 void layoutDirectionChanged();
226 void effectiveLayoutDirectionChanged();
227 void verticalLayoutDirectionChanged();
229 void headerChanged();
230 void footerChanged();
231 void headerItemChanged();
232 void footerItemChanged();
234 void populateTransitionChanged();
235 void addTransitionChanged();
236 void addDisplacedTransitionChanged();
237 void moveTransitionChanged();
238 void moveDisplacedTransitionChanged();
239 void removeTransitionChanged();
240 void removeDisplacedTransitionChanged();
241 void displacedTransitionChanged();
243 void highlightChanged();
244 void highlightItemChanged();
245 void highlightFollowsCurrentItemChanged();
246 void highlightRangeModeChanged();
247 void preferredHighlightBeginChanged();
248 void preferredHighlightEndChanged();
249 void highlightMoveDurationChanged();
252 virtual void updatePolish();
253 virtual void componentComplete();
254 virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
255 virtual qreal minYExtent() const;
256 virtual qreal maxYExtent() const;
257 virtual qreal minXExtent() const;
258 virtual qreal maxXExtent() const;
261 virtual void updateSections() {}
262 void destroyRemoved();
263 void createdItem(int index, QQuickItem *item);
264 virtual void initItem(int index, QQuickItem *item);
265 void modelUpdated(const QQuickChangeSet &changeSet, bool reset);
266 void destroyingItem(QQuickItem *item);
268 void trackedPositionChanged();
271 Q_DECLARE_PRIVATE(QQuickItemView)
275 class Q_AUTOTEST_EXPORT QQuickItemViewAttached : public QObject
279 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
280 Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
282 Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
283 Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
284 Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
287 QQuickItemViewAttached(QObject *parent)
288 : QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
289 ~QQuickItemViewAttached() {}
291 bool isCurrentItem() const { return m_isCurrent; }
292 void setIsCurrentItem(bool c) {
293 if (m_isCurrent != c) {
295 emit currentItemChanged();
299 bool delayRemove() const { return m_delayRemove; }
300 void setDelayRemove(bool delay) {
301 if (m_delayRemove != delay) {
302 m_delayRemove = delay;
303 emit delayRemoveChanged();
307 QString section() const { return m_section; }
308 void setSection(const QString §) {
309 if (m_section != sect) {
311 emit sectionChanged();
315 QString prevSection() const { return m_prevSection; }
316 void setPrevSection(const QString §) {
317 if (m_prevSection != sect) {
318 m_prevSection = sect;
319 emit prevSectionChanged();
323 QString nextSection() const { return m_nextSection; }
324 void setNextSection(const QString §) {
325 if (m_nextSection != sect) {
326 m_nextSection = sect;
327 emit nextSectionChanged();
331 void emitAdd() { emit add(); }
332 void emitRemove() { emit remove(); }
335 void currentItemChanged();
336 void delayRemoveChanged();
341 void sectionChanged();
342 void prevSectionChanged();
343 void nextSectionChanged();
346 bool m_isCurrent : 1;
347 bool m_delayRemove : 1;
349 // current only used by list view
350 mutable QString m_section;
351 QString m_prevSection;
352 QString m_nextSection;
360 #endif // QQUICKITEMVIEW_P_H