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)
74 Q_PROPERTY(QQmlComponent *header READ header WRITE setHeader NOTIFY headerChanged)
75 Q_PROPERTY(QQuickItem *headerItem READ headerItem NOTIFY headerItemChanged)
76 Q_PROPERTY(QQmlComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
77 Q_PROPERTY(QQuickItem *footerItem READ footerItem NOTIFY footerItemChanged)
79 Q_PROPERTY(QQuickTransition *populate READ populateTransition WRITE setPopulateTransition NOTIFY populateTransitionChanged)
80 Q_PROPERTY(QQuickTransition *add READ addTransition WRITE setAddTransition NOTIFY addTransitionChanged)
81 Q_PROPERTY(QQuickTransition *addDisplaced READ addDisplacedTransition WRITE setAddDisplacedTransition NOTIFY addDisplacedTransitionChanged)
82 Q_PROPERTY(QQuickTransition *move READ moveTransition WRITE setMoveTransition NOTIFY moveTransitionChanged)
83 Q_PROPERTY(QQuickTransition *moveDisplaced READ moveDisplacedTransition WRITE setMoveDisplacedTransition NOTIFY moveDisplacedTransitionChanged)
84 Q_PROPERTY(QQuickTransition *remove READ removeTransition WRITE setRemoveTransition NOTIFY removeTransitionChanged)
85 Q_PROPERTY(QQuickTransition *removeDisplaced READ removeDisplacedTransition WRITE setRemoveDisplacedTransition NOTIFY removeDisplacedTransitionChanged)
87 Q_PROPERTY(QQmlComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
88 Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
89 Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
90 Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
91 Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
92 Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
93 Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
95 Q_ENUMS(HighlightRangeMode)
99 QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent = 0);
102 QVariant model() const;
103 void setModel(const QVariant &);
105 QQmlComponent *delegate() const;
106 void setDelegate(QQmlComponent *);
110 int currentIndex() const;
111 void setCurrentIndex(int idx);
113 QQuickItem *currentItem() const;
115 bool isWrapEnabled() const;
116 void setWrapEnabled(bool);
118 int cacheBuffer() const;
119 void setCacheBuffer(int);
121 Qt::LayoutDirection layoutDirection() const;
122 void setLayoutDirection(Qt::LayoutDirection);
123 Qt::LayoutDirection effectiveLayoutDirection() const;
125 QQmlComponent *footer() const;
126 void setFooter(QQmlComponent *);
127 QQuickItem *footerItem() const;
129 QQmlComponent *header() const;
130 void setHeader(QQmlComponent *);
131 QQuickItem *headerItem() const;
133 QQuickTransition *populateTransition() const;
134 void setPopulateTransition(QQuickTransition *transition);
136 QQuickTransition *addTransition() const;
137 void setAddTransition(QQuickTransition *transition);
139 QQuickTransition *addDisplacedTransition() const;
140 void setAddDisplacedTransition(QQuickTransition *transition);
142 QQuickTransition *moveTransition() const;
143 void setMoveTransition(QQuickTransition *transition);
145 QQuickTransition *moveDisplacedTransition() const;
146 void setMoveDisplacedTransition(QQuickTransition *transition);
148 QQuickTransition *removeTransition() const;
149 void setRemoveTransition(QQuickTransition *transition);
151 QQuickTransition *removeDisplacedTransition() const;
152 void setRemoveDisplacedTransition(QQuickTransition *transition);
154 QQmlComponent *highlight() const;
155 void setHighlight(QQmlComponent *);
157 QQuickItem *highlightItem() const;
159 bool highlightFollowsCurrentItem() const;
160 virtual void setHighlightFollowsCurrentItem(bool);
162 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
163 HighlightRangeMode highlightRangeMode() const;
164 void setHighlightRangeMode(HighlightRangeMode mode);
166 qreal preferredHighlightBegin() const;
167 void setPreferredHighlightBegin(qreal);
168 void resetPreferredHighlightBegin();
170 qreal preferredHighlightEnd() const;
171 void setPreferredHighlightEnd(qreal);
172 void resetPreferredHighlightEnd();
174 int highlightMoveDuration() const;
175 virtual void setHighlightMoveDuration(int);
177 enum PositionMode { Beginning, Center, End, Visible, Contain };
179 Q_INVOKABLE void positionViewAtIndex(int index, int mode);
180 Q_INVOKABLE int indexAt(qreal x, qreal y) const;
181 Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const;
182 Q_INVOKABLE void positionViewAtBeginning();
183 Q_INVOKABLE void positionViewAtEnd();
185 virtual void setContentX(qreal pos);
186 virtual void setContentY(qreal pos);
187 virtual qreal xOrigin() const;
191 void delegateChanged();
193 void currentIndexChanged();
194 void currentItemChanged();
196 void keyNavigationWrapsChanged();
197 void cacheBufferChanged();
199 void layoutDirectionChanged();
200 void effectiveLayoutDirectionChanged();
202 void headerChanged();
203 void footerChanged();
204 void headerItemChanged();
205 void footerItemChanged();
207 void populateTransitionChanged();
208 void addTransitionChanged();
209 void addDisplacedTransitionChanged();
210 void moveTransitionChanged();
211 void moveDisplacedTransitionChanged();
212 void removeTransitionChanged();
213 void removeDisplacedTransitionChanged();
215 void highlightChanged();
216 void highlightItemChanged();
217 void highlightFollowsCurrentItemChanged();
218 void highlightRangeModeChanged();
219 void preferredHighlightBeginChanged();
220 void preferredHighlightEndChanged();
221 void highlightMoveDurationChanged();
224 virtual void updatePolish();
225 virtual void componentComplete();
226 virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
227 virtual qreal minYExtent() const;
228 virtual qreal maxYExtent() const;
229 virtual qreal minXExtent() const;
230 virtual qreal maxXExtent() const;
233 virtual void updateSections() {}
234 void destroyRemoved();
235 void createdItem(int index, QQuickItem *item);
236 void initItem(int index, QQuickItem *item);
237 void modelUpdated(const QQuickChangeSet &changeSet, bool reset);
238 void destroyingItem(QQuickItem *item);
240 void trackedPositionChanged();
243 Q_DECLARE_PRIVATE(QQuickItemView)
247 class Q_AUTOTEST_EXPORT QQuickItemViewAttached : public QObject
251 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
252 Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
254 Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
255 Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
256 Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
259 QQuickItemViewAttached(QObject *parent)
260 : QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
261 ~QQuickItemViewAttached() {}
263 bool isCurrentItem() const { return m_isCurrent; }
264 void setIsCurrentItem(bool c) {
265 if (m_isCurrent != c) {
267 emit currentItemChanged();
271 bool delayRemove() const { return m_delayRemove; }
272 void setDelayRemove(bool delay) {
273 if (m_delayRemove != delay) {
274 m_delayRemove = delay;
275 emit delayRemoveChanged();
279 QString section() const { return m_section; }
280 void setSection(const QString §) {
281 if (m_section != sect) {
283 emit sectionChanged();
287 QString prevSection() const { return m_prevSection; }
288 void setPrevSection(const QString §) {
289 if (m_prevSection != sect) {
290 m_prevSection = sect;
291 emit prevSectionChanged();
295 QString nextSection() const { return m_nextSection; }
296 void setNextSection(const QString §) {
297 if (m_nextSection != sect) {
298 m_nextSection = sect;
299 emit nextSectionChanged();
303 void emitAdd() { emit add(); }
304 void emitRemove() { emit remove(); }
307 void currentItemChanged();
308 void delayRemoveChanged();
313 void sectionChanged();
314 void prevSectionChanged();
315 void nextSectionChanged();
318 bool m_isCurrent : 1;
319 bool m_delayRemove : 1;
321 // current only used by list view
322 mutable QString m_section;
323 QString m_prevSection;
324 QString m_nextSection;
327 class QQuickViewTransitionAttached : public QObject
331 Q_PROPERTY(int index READ index NOTIFY indexChanged)
332 Q_PROPERTY(QQuickItem* item READ item NOTIFY itemChanged)
333 Q_PROPERTY(QPointF destination READ destination NOTIFY destinationChanged)
335 Q_PROPERTY(QList<int> targetIndexes READ targetIndexes NOTIFY targetIndexesChanged)
336 Q_PROPERTY(QQmlListProperty<QObject> targetItems READ targetItems NOTIFY targetItemsChanged)
339 QQuickViewTransitionAttached(QObject *parent);
341 int index() const { return m_index; }
342 QQuickItem *item() const { return m_item; }
343 QPointF destination() const { return m_destination; }
345 QList<int> targetIndexes() const { return m_targetIndexes; }
346 QQmlListProperty<QObject> targetItems();
348 static QQuickViewTransitionAttached *qmlAttachedProperties(QObject *);
353 void destinationChanged();
355 void targetIndexesChanged();
356 void targetItemsChanged();
359 friend class FxViewItemTransitionManager;
362 QPointF m_destination;
364 QList<int> m_targetIndexes;
365 QList<QObject *> m_targetItems;
371 QML_DECLARE_TYPE(QQuickViewTransitionAttached)
372 QML_DECLARE_TYPEINFO(QQuickViewTransitionAttached, QML_HAS_ATTACHED_PROPERTIES)
376 #endif // QQUICKITEMVIEW_P_H