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 QSGGRIDVIEW_P_H
44 #define QSGGRIDVIEW_P_H
46 #include "qsgflickable_p.h"
48 #include <private/qdeclarativeguard_p.h>
54 QT_MODULE(Declarative)
56 class QSGGridViewAttached;
57 class QSGGridViewPrivate;
58 class Q_AUTOTEST_EXPORT QSGGridView : public QSGFlickable
61 Q_DECLARE_PRIVATE(QSGGridView)
63 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
64 Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
65 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
66 Q_PROPERTY(QSGItem *currentItem READ currentItem NOTIFY currentIndexChanged)
67 Q_PROPERTY(int count READ count NOTIFY countChanged)
69 Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
70 Q_PROPERTY(QSGItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
71 Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem)
72 Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
74 Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
75 Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
76 Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
78 Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
79 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
80 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
81 Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
82 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
83 Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged)
84 Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged)
86 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
88 Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
89 Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
91 Q_ENUMS(HighlightRangeMode)
95 Q_CLASSINFO("DefaultProperty", "data")
98 QSGGridView(QSGItem *parent=0);
101 QVariant model() const;
102 int modelCount() const;
103 void setModel(const QVariant &);
105 QDeclarativeComponent *delegate() const;
106 void setDelegate(QDeclarativeComponent *);
108 int currentIndex() const;
109 void setCurrentIndex(int idx);
111 QSGItem *currentItem();
112 QSGItem *highlightItem();
115 QDeclarativeComponent *highlight() const;
116 void setHighlight(QDeclarativeComponent *highlight);
118 bool highlightFollowsCurrentItem() const;
119 void setHighlightFollowsCurrentItem(bool);
121 int highlightMoveDuration() const;
122 void setHighlightMoveDuration(int);
124 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
125 HighlightRangeMode highlightRangeMode() const;
126 void setHighlightRangeMode(HighlightRangeMode mode);
128 qreal preferredHighlightBegin() const;
129 void setPreferredHighlightBegin(qreal);
130 void resetPreferredHighlightBegin();
132 qreal preferredHighlightEnd() const;
133 void setPreferredHighlightEnd(qreal);
134 void resetPreferredHighlightEnd();
136 Qt::LayoutDirection layoutDirection() const;
137 void setLayoutDirection(Qt::LayoutDirection);
138 Qt::LayoutDirection effectiveLayoutDirection() const;
140 enum Flow { LeftToRight, TopToBottom };
144 bool isWrapEnabled() const;
145 void setWrapEnabled(bool);
147 int cacheBuffer() const;
148 void setCacheBuffer(int);
150 int cellWidth() const;
151 void setCellWidth(int);
153 int cellHeight() const;
154 void setCellHeight(int);
156 enum SnapMode { NoSnap, SnapToRow, SnapOneRow };
157 SnapMode snapMode() const;
158 void setSnapMode(SnapMode mode);
160 QDeclarativeComponent *footer() const;
161 void setFooter(QDeclarativeComponent *);
163 QDeclarativeComponent *header() const;
164 void setHeader(QDeclarativeComponent *);
166 virtual void setContentX(qreal pos);
167 virtual void setContentY(qreal pos);
169 enum PositionMode { Beginning, Center, End, Visible, Contain };
171 Q_INVOKABLE void positionViewAtIndex(int index, int mode);
172 Q_INVOKABLE int indexAt(qreal x, qreal y) const;
173 Q_INVOKABLE void positionViewAtBeginning();
174 Q_INVOKABLE void positionViewAtEnd();
176 static QSGGridViewAttached *qmlAttachedProperties(QObject *);
179 void moveCurrentIndexUp();
180 void moveCurrentIndexDown();
181 void moveCurrentIndexLeft();
182 void moveCurrentIndexRight();
186 void currentIndexChanged();
187 void cellWidthChanged();
188 void cellHeightChanged();
189 void highlightChanged();
190 void highlightItemChanged();
191 void preferredHighlightBeginChanged();
192 void preferredHighlightEndChanged();
193 void highlightRangeModeChanged();
194 void highlightMoveDurationChanged();
196 void delegateChanged();
198 void layoutDirectionChanged();
199 void effectiveLayoutDirectionChanged();
200 void keyNavigationWrapsChanged();
201 void cacheBufferChanged();
202 void snapModeChanged();
203 void headerChanged();
204 void footerChanged();
207 virtual void updatePolish();
208 virtual void viewportMoved();
209 virtual qreal minYExtent() const;
210 virtual qreal maxYExtent() const;
211 virtual qreal minXExtent() const;
212 virtual qreal maxXExtent() const;
213 virtual void keyPressEvent(QKeyEvent *);
214 virtual void componentComplete();
217 void trackedPositionChanged();
218 void itemsInserted(int index, int count);
219 void itemsRemoved(int index, int count);
220 void itemsMoved(int from, int to, int count);
222 void destroyRemoved();
223 void createdItem(int index, QSGItem *item);
224 void destroyingItem(QSGItem *item);
231 class QSGGridViewAttached : public QObject
235 QSGGridViewAttached(QObject *parent)
236 : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
237 ~QSGGridViewAttached() {}
239 Q_PROPERTY(QSGGridView *view READ view NOTIFY viewChanged)
240 QSGGridView *view() { return m_view; }
241 void setView(QSGGridView *view) {
242 if (view != m_view) {
248 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
249 bool isCurrentItem() const { return m_isCurrent; }
250 void setIsCurrentItem(bool c) {
251 if (m_isCurrent != c) {
253 emit currentItemChanged();
257 Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
258 bool delayRemove() const { return m_delayRemove; }
259 void setDelayRemove(bool delay) {
260 if (m_delayRemove != delay) {
261 m_delayRemove = delay;
262 emit delayRemoveChanged();
266 void emitAdd() { emit add(); }
267 void emitRemove() { emit remove(); }
270 void currentItemChanged();
271 void delayRemoveChanged();
277 QDeclarativeGuard<QSGGridView> m_view;
278 bool m_isCurrent : 1;
279 bool m_delayRemove : 1;
285 QML_DECLARE_TYPE(QSGGridView)
286 QML_DECLARE_TYPEINFO(QSGGridView, QML_HAS_ATTACHED_PROPERTIES)
290 #endif // QSGGRIDVIEW_P_H