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 QDECLARATIVEGRIDVIEW_H
43 #define QDECLARATIVEGRIDVIEW_H
45 #include "private/qdeclarativeflickable_p.h"
46 #include "QtDeclarative/private/qdeclarativeguard_p.h"
52 class QDeclarative1VisualModel;
53 class QDeclarative1GridViewAttached;
54 class QDeclarative1GridViewPrivate;
55 class Q_AUTOTEST_EXPORT QDeclarative1GridView : public QDeclarative1Flickable
58 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1GridView)
60 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
61 Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
62 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
63 Q_PROPERTY(QDeclarativeItem *currentItem READ currentItem NOTIFY currentIndexChanged)
64 Q_PROPERTY(int count READ count NOTIFY countChanged)
66 Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
67 Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
68 Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem)
69 Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
71 Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
72 Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
73 Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
75 Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
76 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged REVISION 1)
77 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged REVISION 1)
78 Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
79 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
80 Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged)
81 Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged)
83 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
85 Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
86 Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
88 Q_ENUMS(HighlightRangeMode)
92 Q_CLASSINFO("DefaultProperty", "data")
95 QDeclarative1GridView(QDeclarativeItem *parent=0);
96 ~QDeclarative1GridView();
98 QVariant model() const;
99 int modelCount() const;
100 void setModel(const QVariant &);
102 QDeclarativeComponent *delegate() const;
103 void setDelegate(QDeclarativeComponent *);
105 int currentIndex() const;
106 void setCurrentIndex(int idx);
108 QDeclarativeItem *currentItem();
109 QDeclarativeItem *highlightItem();
112 QDeclarativeComponent *highlight() const;
113 void setHighlight(QDeclarativeComponent *highlight);
115 bool highlightFollowsCurrentItem() const;
116 void setHighlightFollowsCurrentItem(bool);
118 int highlightMoveDuration() const;
119 void setHighlightMoveDuration(int);
121 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
122 HighlightRangeMode highlightRangeMode() const;
123 void setHighlightRangeMode(HighlightRangeMode mode);
125 qreal preferredHighlightBegin() const;
126 void setPreferredHighlightBegin(qreal);
127 void resetPreferredHighlightBegin();
129 qreal preferredHighlightEnd() const;
130 void setPreferredHighlightEnd(qreal);
131 void resetPreferredHighlightEnd();
133 Qt::LayoutDirection layoutDirection() const;
134 void setLayoutDirection(Qt::LayoutDirection);
135 Qt::LayoutDirection effectiveLayoutDirection() const;
137 enum Flow { LeftToRight, TopToBottom };
141 bool isWrapEnabled() const;
142 void setWrapEnabled(bool);
144 int cacheBuffer() const;
145 void setCacheBuffer(int);
147 int cellWidth() const;
148 void setCellWidth(int);
150 int cellHeight() const;
151 void setCellHeight(int);
153 enum SnapMode { NoSnap, SnapToRow, SnapOneRow };
154 SnapMode snapMode() const;
155 void setSnapMode(SnapMode mode);
157 QDeclarativeComponent *footer() const;
158 void setFooter(QDeclarativeComponent *);
160 QDeclarativeComponent *header() const;
161 void setHeader(QDeclarativeComponent *);
163 virtual void setContentX(qreal pos);
164 virtual void setContentY(qreal pos);
166 enum PositionMode { Beginning, Center, End, Visible, Contain };
168 Q_INVOKABLE void positionViewAtIndex(int index, int mode);
169 Q_INVOKABLE int indexAt(qreal x, qreal y) const;
170 Q_INVOKABLE Q_REVISION(1) void positionViewAtBeginning();
171 Q_INVOKABLE Q_REVISION(1) void positionViewAtEnd();
173 static QDeclarative1GridViewAttached *qmlAttachedProperties(QObject *);
176 void moveCurrentIndexUp();
177 void moveCurrentIndexDown();
178 void moveCurrentIndexLeft();
179 void moveCurrentIndexRight();
183 void currentIndexChanged();
184 void cellWidthChanged();
185 void cellHeightChanged();
186 void highlightChanged();
187 void highlightItemChanged();
188 void preferredHighlightBeginChanged();
189 void preferredHighlightEndChanged();
190 void highlightRangeModeChanged();
191 void highlightMoveDurationChanged();
193 void delegateChanged();
195 Q_REVISION(1) void layoutDirectionChanged();
196 Q_REVISION(1) void effectiveLayoutDirectionChanged();
197 void keyNavigationWrapsChanged();
198 void cacheBufferChanged();
199 void snapModeChanged();
200 void headerChanged();
201 void footerChanged();
204 virtual bool event(QEvent *event);
205 virtual void viewportMoved();
206 virtual qreal minYExtent() const;
207 virtual qreal maxYExtent() const;
208 virtual qreal minXExtent() const;
209 virtual qreal maxXExtent() const;
210 virtual void keyPressEvent(QKeyEvent *);
211 virtual void componentComplete();
214 void trackedPositionChanged();
215 void itemsInserted(int index, int count);
216 void itemsRemoved(int index, int count);
217 void itemsMoved(int from, int to, int count);
219 void destroyRemoved();
220 void createdItem(int index, QDeclarativeItem *item);
221 void destroyingItem(QDeclarativeItem *item);
228 class QDeclarative1GridViewAttached : public QObject
232 QDeclarative1GridViewAttached(QObject *parent)
233 : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
234 ~QDeclarative1GridViewAttached() {}
236 Q_PROPERTY(QDeclarative1GridView *view READ view NOTIFY viewChanged)
237 QDeclarative1GridView *view() { return m_view; }
238 void setView(QDeclarative1GridView *view) {
239 if (view != m_view) {
245 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
246 bool isCurrentItem() const { return m_isCurrent; }
247 void setIsCurrentItem(bool c) {
248 if (m_isCurrent != c) {
250 emit currentItemChanged();
254 Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
255 bool delayRemove() const { return m_delayRemove; }
256 void setDelayRemove(bool delay) {
257 if (m_delayRemove != delay) {
258 m_delayRemove = delay;
259 emit delayRemoveChanged();
263 void emitAdd() { emit add(); }
264 void emitRemove() { emit remove(); }
267 void currentItemChanged();
268 void delayRemoveChanged();
274 QDeclarativeGuard<QDeclarative1GridView> m_view;
275 bool m_isCurrent : 1;
276 bool m_delayRemove : 1;
282 QML_DECLARE_TYPE(QDeclarative1GridView)
283 QML_DECLARE_TYPEINFO(QDeclarative1GridView, QML_HAS_ATTACHED_PROPERTIES)