1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
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.
|
---|
23 | **
|
---|
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.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QDECLARATIVEGRIDVIEW_H
|
---|
43 | #define QDECLARATIVEGRIDVIEW_H
|
---|
44 |
|
---|
45 | #include "private/qdeclarativeflickable_p.h"
|
---|
46 | #include "private/qdeclarativeguard_p.h"
|
---|
47 |
|
---|
48 | QT_BEGIN_HEADER
|
---|
49 |
|
---|
50 | QT_BEGIN_NAMESPACE
|
---|
51 |
|
---|
52 | QT_MODULE(Declarative)
|
---|
53 | class QDeclarativeVisualModel;
|
---|
54 | class QDeclarativeGridViewAttached;
|
---|
55 | class QDeclarativeGridViewPrivate;
|
---|
56 | class Q_AUTOTEST_EXPORT QDeclarativeGridView : public QDeclarativeFlickable
|
---|
57 | {
|
---|
58 | Q_OBJECT
|
---|
59 | Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeGridView)
|
---|
60 |
|
---|
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)
|
---|
66 |
|
---|
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)
|
---|
71 |
|
---|
72 | Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged)
|
---|
73 | Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged)
|
---|
74 | Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
|
---|
75 |
|
---|
76 | Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
|
---|
77 | Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
|
---|
78 | Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
|
---|
79 | Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged)
|
---|
80 | Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged)
|
---|
81 |
|
---|
82 | Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
|
---|
83 |
|
---|
84 | Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
|
---|
85 | Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
|
---|
86 |
|
---|
87 | Q_ENUMS(HighlightRangeMode)
|
---|
88 | Q_ENUMS(SnapMode)
|
---|
89 | Q_ENUMS(Flow)
|
---|
90 | Q_ENUMS(PositionMode)
|
---|
91 | Q_CLASSINFO("DefaultProperty", "data")
|
---|
92 |
|
---|
93 | public:
|
---|
94 | QDeclarativeGridView(QDeclarativeItem *parent=0);
|
---|
95 | ~QDeclarativeGridView();
|
---|
96 |
|
---|
97 | QVariant model() const;
|
---|
98 | void setModel(const QVariant &);
|
---|
99 |
|
---|
100 | QDeclarativeComponent *delegate() const;
|
---|
101 | void setDelegate(QDeclarativeComponent *);
|
---|
102 |
|
---|
103 | int currentIndex() const;
|
---|
104 | void setCurrentIndex(int idx);
|
---|
105 |
|
---|
106 | QDeclarativeItem *currentItem();
|
---|
107 | QDeclarativeItem *highlightItem();
|
---|
108 | int count() const;
|
---|
109 |
|
---|
110 | QDeclarativeComponent *highlight() const;
|
---|
111 | void setHighlight(QDeclarativeComponent *highlight);
|
---|
112 |
|
---|
113 | bool highlightFollowsCurrentItem() const;
|
---|
114 | void setHighlightFollowsCurrentItem(bool);
|
---|
115 |
|
---|
116 | int highlightMoveDuration() const;
|
---|
117 | void setHighlightMoveDuration(int);
|
---|
118 |
|
---|
119 | enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
|
---|
120 | HighlightRangeMode highlightRangeMode() const;
|
---|
121 | void setHighlightRangeMode(HighlightRangeMode mode);
|
---|
122 |
|
---|
123 | qreal preferredHighlightBegin() const;
|
---|
124 | void setPreferredHighlightBegin(qreal);
|
---|
125 |
|
---|
126 | qreal preferredHighlightEnd() const;
|
---|
127 | void setPreferredHighlightEnd(qreal);
|
---|
128 |
|
---|
129 | enum Flow { LeftToRight, TopToBottom };
|
---|
130 | Flow flow() const;
|
---|
131 | void setFlow(Flow);
|
---|
132 |
|
---|
133 | bool isWrapEnabled() const;
|
---|
134 | void setWrapEnabled(bool);
|
---|
135 |
|
---|
136 | int cacheBuffer() const;
|
---|
137 | void setCacheBuffer(int);
|
---|
138 |
|
---|
139 | int cellWidth() const;
|
---|
140 | void setCellWidth(int);
|
---|
141 |
|
---|
142 | int cellHeight() const;
|
---|
143 | void setCellHeight(int);
|
---|
144 |
|
---|
145 | enum SnapMode { NoSnap, SnapToRow, SnapOneRow };
|
---|
146 | SnapMode snapMode() const;
|
---|
147 | void setSnapMode(SnapMode mode);
|
---|
148 |
|
---|
149 | QDeclarativeComponent *footer() const;
|
---|
150 | void setFooter(QDeclarativeComponent *);
|
---|
151 |
|
---|
152 | QDeclarativeComponent *header() const;
|
---|
153 | void setHeader(QDeclarativeComponent *);
|
---|
154 |
|
---|
155 | virtual void setContentX(qreal pos);
|
---|
156 | virtual void setContentY(qreal pos);
|
---|
157 |
|
---|
158 | enum PositionMode { Beginning, Center, End, Visible, Contain };
|
---|
159 |
|
---|
160 | Q_INVOKABLE void positionViewAtIndex(int index, int mode);
|
---|
161 | Q_INVOKABLE int indexAt(int x, int y) const;
|
---|
162 |
|
---|
163 | static QDeclarativeGridViewAttached *qmlAttachedProperties(QObject *);
|
---|
164 |
|
---|
165 | public Q_SLOTS:
|
---|
166 | void moveCurrentIndexUp();
|
---|
167 | void moveCurrentIndexDown();
|
---|
168 | void moveCurrentIndexLeft();
|
---|
169 | void moveCurrentIndexRight();
|
---|
170 |
|
---|
171 | Q_SIGNALS:
|
---|
172 | void countChanged();
|
---|
173 | void currentIndexChanged();
|
---|
174 | void cellWidthChanged();
|
---|
175 | void cellHeightChanged();
|
---|
176 | void highlightChanged();
|
---|
177 | void highlightItemChanged();
|
---|
178 | void preferredHighlightBeginChanged();
|
---|
179 | void preferredHighlightEndChanged();
|
---|
180 | void highlightRangeModeChanged();
|
---|
181 | void highlightMoveDurationChanged();
|
---|
182 | void modelChanged();
|
---|
183 | void delegateChanged();
|
---|
184 | void flowChanged();
|
---|
185 | void keyNavigationWrapsChanged();
|
---|
186 | void cacheBufferChanged();
|
---|
187 | void snapModeChanged();
|
---|
188 | void headerChanged();
|
---|
189 | void footerChanged();
|
---|
190 |
|
---|
191 | protected:
|
---|
192 | virtual bool event(QEvent *event);
|
---|
193 | virtual void viewportMoved();
|
---|
194 | virtual qreal minYExtent() const;
|
---|
195 | virtual qreal maxYExtent() const;
|
---|
196 | virtual qreal minXExtent() const;
|
---|
197 | virtual qreal maxXExtent() const;
|
---|
198 | virtual void keyPressEvent(QKeyEvent *);
|
---|
199 | virtual void componentComplete();
|
---|
200 |
|
---|
201 | private Q_SLOTS:
|
---|
202 | void trackedPositionChanged();
|
---|
203 | void itemsInserted(int index, int count);
|
---|
204 | void itemsRemoved(int index, int count);
|
---|
205 | void itemsMoved(int from, int to, int count);
|
---|
206 | void modelReset();
|
---|
207 | void destroyRemoved();
|
---|
208 | void createdItem(int index, QDeclarativeItem *item);
|
---|
209 | void destroyingItem(QDeclarativeItem *item);
|
---|
210 | void animStopped();
|
---|
211 |
|
---|
212 | private:
|
---|
213 | void refill();
|
---|
214 | };
|
---|
215 |
|
---|
216 | class QDeclarativeGridViewAttached : public QObject
|
---|
217 | {
|
---|
218 | Q_OBJECT
|
---|
219 | public:
|
---|
220 | QDeclarativeGridViewAttached(QObject *parent)
|
---|
221 | : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
|
---|
222 | ~QDeclarativeGridViewAttached() {}
|
---|
223 |
|
---|
224 | Q_PROPERTY(QDeclarativeGridView *view READ view NOTIFY viewChanged)
|
---|
225 | QDeclarativeGridView *view() { return m_view; }
|
---|
226 | void setView(QDeclarativeGridView *view) {
|
---|
227 | if (view != m_view) {
|
---|
228 | m_view = view;
|
---|
229 | emit viewChanged();
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
|
---|
234 | bool isCurrentItem() const { return m_isCurrent; }
|
---|
235 | void setIsCurrentItem(bool c) {
|
---|
236 | if (m_isCurrent != c) {
|
---|
237 | m_isCurrent = c;
|
---|
238 | emit currentItemChanged();
|
---|
239 | }
|
---|
240 | }
|
---|
241 |
|
---|
242 | Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged)
|
---|
243 | bool delayRemove() const { return m_delayRemove; }
|
---|
244 | void setDelayRemove(bool delay) {
|
---|
245 | if (m_delayRemove != delay) {
|
---|
246 | m_delayRemove = delay;
|
---|
247 | emit delayRemoveChanged();
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | void emitAdd() { emit add(); }
|
---|
252 | void emitRemove() { emit remove(); }
|
---|
253 |
|
---|
254 | Q_SIGNALS:
|
---|
255 | void currentItemChanged();
|
---|
256 | void delayRemoveChanged();
|
---|
257 | void add();
|
---|
258 | void remove();
|
---|
259 | void viewChanged();
|
---|
260 |
|
---|
261 | public:
|
---|
262 | QDeclarativeGuard<QDeclarativeGridView> m_view;
|
---|
263 | bool m_isCurrent : 1;
|
---|
264 | bool m_delayRemove : 1;
|
---|
265 | };
|
---|
266 |
|
---|
267 |
|
---|
268 | QT_END_NAMESPACE
|
---|
269 |
|
---|
270 | QML_DECLARE_TYPE(QDeclarativeGridView)
|
---|
271 | QML_DECLARE_TYPEINFO(QDeclarativeGridView, QML_HAS_ATTACHED_PROPERTIES)
|
---|
272 |
|
---|
273 | QT_END_HEADER
|
---|
274 |
|
---|
275 | #endif
|
---|