1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEGRIDVIEW_H
43 #define QDECLARATIVEGRIDVIEW_H
45 #include "private/qdeclarativeflickable_p.h"
46 #include "private/qdeclarativeguard_p.h"
52 QT_MODULE(Declarative)
53 class QDeclarativeVisualModel;
54 class QDeclarativeGridViewAttached;
55 class QDeclarativeGridViewPrivate;
56 class Q_AUTOTEST_EXPORT QDeclarativeGridView : public QDeclarativeFlickable
59 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeGridView)
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 currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
64 Q_PROPERTY(QDeclarativeItem *currentItem READ currentItem NOTIFY currentIndexChanged)
65 Q_PROPERTY(int count READ count NOTIFY countChanged)
67 Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
68 Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
69 Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem)
70 Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
72 Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
73 Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
74 Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
76 Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
77 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged REVISION 1)
78 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged REVISION 1)
79 Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
80 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
81 Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged)
82 Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged)
84 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
86 Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
87 Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
89 Q_ENUMS(HighlightRangeMode)
93 Q_CLASSINFO("DefaultProperty", "data")
96 QDeclarativeGridView(QDeclarativeItem *parent=0);
97 ~QDeclarativeGridView();
99 QVariant model() const;
100 int modelCount() const;
101 void setModel(const QVariant &);
103 QDeclarativeComponent *delegate() const;
104 void setDelegate(QDeclarativeComponent *);
106 int currentIndex() const;
107 void setCurrentIndex(int idx);
109 QDeclarativeItem *currentItem();
110 QDeclarativeItem *highlightItem();
113 QDeclarativeComponent *highlight() const;
114 void setHighlight(QDeclarativeComponent *highlight);
116 bool highlightFollowsCurrentItem() const;
117 void setHighlightFollowsCurrentItem(bool);
119 int highlightMoveDuration() const;
120 void setHighlightMoveDuration(int);
122 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
123 HighlightRangeMode highlightRangeMode() const;
124 void setHighlightRangeMode(HighlightRangeMode mode);
126 qreal preferredHighlightBegin() const;
127 void setPreferredHighlightBegin(qreal);
128 void resetPreferredHighlightBegin();
130 qreal preferredHighlightEnd() const;
131 void setPreferredHighlightEnd(qreal);
132 void resetPreferredHighlightEnd();
134 Qt::LayoutDirection layoutDirection() const;
135 void setLayoutDirection(Qt::LayoutDirection);
136 Qt::LayoutDirection effectiveLayoutDirection() const;
138 enum Flow { LeftToRight, TopToBottom };
142 bool isWrapEnabled() const;
143 void setWrapEnabled(bool);
145 int cacheBuffer() const;
146 void setCacheBuffer(int);
148 int cellWidth() const;
149 void setCellWidth(int);
151 int cellHeight() const;
152 void setCellHeight(int);
154 enum SnapMode { NoSnap, SnapToRow, SnapOneRow };
155 SnapMode snapMode() const;
156 void setSnapMode(SnapMode mode);
158 QDeclarativeComponent *footer() const;
159 void setFooter(QDeclarativeComponent *);
161 QDeclarativeComponent *header() const;
162 void setHeader(QDeclarativeComponent *);
164 virtual void setContentX(qreal pos);
165 virtual void setContentY(qreal pos);
167 enum PositionMode { Beginning, Center, End, Visible, Contain };
169 Q_INVOKABLE void positionViewAtIndex(int index, int mode);
170 Q_INVOKABLE int indexAt(qreal x, qreal y) const;
171 Q_INVOKABLE Q_REVISION(1) void positionViewAtBeginning();
172 Q_INVOKABLE Q_REVISION(1) void positionViewAtEnd();
174 static QDeclarativeGridViewAttached *qmlAttachedProperties(QObject *);
177 void moveCurrentIndexUp();
178 void moveCurrentIndexDown();
179 void moveCurrentIndexLeft();
180 void moveCurrentIndexRight();
184 void currentIndexChanged();
185 void cellWidthChanged();
186 void cellHeightChanged();
187 void highlightChanged();
188 void highlightItemChanged();
189 void preferredHighlightBeginChanged();
190 void preferredHighlightEndChanged();
191 void highlightRangeModeChanged();
192 void highlightMoveDurationChanged();
194 void delegateChanged();
196 Q_REVISION(1) void layoutDirectionChanged();
197 Q_REVISION(1) void effectiveLayoutDirectionChanged();
198 void keyNavigationWrapsChanged();
199 void cacheBufferChanged();
200 void snapModeChanged();
201 void headerChanged();
202 void footerChanged();
205 virtual bool event(QEvent *event);
206 virtual void viewportMoved();
207 virtual qreal minYExtent() const;
208 virtual qreal maxYExtent() const;
209 virtual qreal minXExtent() const;
210 virtual qreal maxXExtent() const;
211 virtual void keyPressEvent(QKeyEvent *);
212 virtual void componentComplete();
215 void trackedPositionChanged();
216 void itemsInserted(int index, int count);
217 void itemsRemoved(int index, int count);
218 void itemsMoved(int from, int to, int count);
220 void destroyRemoved();
221 void createdItem(int index, QDeclarativeItem *item);
222 void destroyingItem(QDeclarativeItem *item);
229 class QDeclarativeGridViewAttached : public QObject
233 QDeclarativeGridViewAttached(QObject *parent)
234 : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
235 ~QDeclarativeGridViewAttached() {}
237 Q_PROPERTY(QDeclarativeGridView *view READ view NOTIFY viewChanged)
238 QDeclarativeGridView *view() { return m_view; }
239 void setView(QDeclarativeGridView *view) {
240 if (view != m_view) {
246 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
247 bool isCurrentItem() const { return m_isCurrent; }
248 void setIsCurrentItem(bool c) {
249 if (m_isCurrent != c) {
251 emit currentItemChanged();
255 Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
256 bool delayRemove() const { return m_delayRemove; }
257 void setDelayRemove(bool delay) {
258 if (m_delayRemove != delay) {
259 m_delayRemove = delay;
260 emit delayRemoveChanged();
264 void emitAdd() { emit add(); }
265 void emitRemove() { emit remove(); }
268 void currentItemChanged();
269 void delayRemoveChanged();
275 QDeclarativeGuard<QDeclarativeGridView> m_view;
276 bool m_isCurrent : 1;
277 bool m_delayRemove : 1;
283 QML_DECLARE_TYPE(QDeclarativeGridView)
284 QML_DECLARE_TYPEINFO(QDeclarativeGridView, QML_HAS_ATTACHED_PROPERTIES)