Qt 4.8
qdeclarativegridview_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
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.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
49 
51 
52 QT_MODULE(Declarative)
57 {
58  Q_OBJECT
60 
61  QVariant model;
63  int currentIndex;
64  QDeclarativeItem *currentItem;
65  int count;
66 
68  QDeclarativeItem *highlightItem;
69  bool highlightFollowsCurrentItem;
70  int highlightMoveDuration;
71 
72  qreal preferredHighlightBegin;
73  qreal preferredHighlightEnd;
74  HighlightRangeMode highlightRangeMode;
75 
76  Flow flow;
77  Qt::LayoutDirection layoutDirection;
78  bool keyNavigationWraps;
79  int cacheBuffer;
80  int cellWidth;
81  int cellHeight;
82 
83  SnapMode snapMode;
84 
87 
90  Q_ENUMS(Flow)
92  Q_CLASSINFO("DefaultProperty", "data")
93 
94 public:
97 
98  QVariant model() const;
99  int modelCount() const;
100  void setModel(const QVariant &);
101 
102  QDeclarativeComponent *delegate() const;
103  void setDelegate(QDeclarativeComponent *);
104 
105  int currentIndex() const;
106  void setCurrentIndex(int idx);
107 
108  QDeclarativeItem *currentItem();
109  QDeclarativeItem *highlightItem();
110  int count() const;
111 
112  QDeclarativeComponent *highlight() const;
113  void setHighlight(QDeclarativeComponent *highlight);
114 
115  bool highlightFollowsCurrentItem() const;
116  void setHighlightFollowsCurrentItem(bool);
117 
118  int highlightMoveDuration() const;
119  void setHighlightMoveDuration(int);
120 
121  enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
122  HighlightRangeMode highlightRangeMode() const;
123  void setHighlightRangeMode(HighlightRangeMode mode);
124 
125  qreal preferredHighlightBegin() const;
126  void setPreferredHighlightBegin(qreal);
127  void resetPreferredHighlightBegin();
128 
129  qreal preferredHighlightEnd() const;
130  void setPreferredHighlightEnd(qreal);
131  void resetPreferredHighlightEnd();
132 
133  Qt::LayoutDirection layoutDirection() const;
134  void setLayoutDirection(Qt::LayoutDirection);
135  Qt::LayoutDirection effectiveLayoutDirection() const;
136 
137  enum Flow { LeftToRight, TopToBottom };
138  Flow flow() const;
139  void setFlow(Flow);
140 
141  bool isWrapEnabled() const;
142  void setWrapEnabled(bool);
143 
144  int cacheBuffer() const;
145  void setCacheBuffer(int);
146 
147  int cellWidth() const;
148  void setCellWidth(int);
149 
150  int cellHeight() const;
151  void setCellHeight(int);
152 
153  enum SnapMode { NoSnap, SnapToRow, SnapOneRow };
154  SnapMode snapMode() const;
155  void setSnapMode(SnapMode mode);
156 
157  QDeclarativeComponent *footer() const;
158  void setFooter(QDeclarativeComponent *);
159 
160  QDeclarativeComponent *header() const;
161  void setHeader(QDeclarativeComponent *);
162 
163  virtual void setContentX(qreal pos);
164  virtual void setContentY(qreal pos);
165 
166  enum PositionMode { Beginning, Center, End, Visible, Contain };
167 
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();
172 
173  static QDeclarativeGridViewAttached *qmlAttachedProperties(QObject *);
174 
175 public Q_SLOTS:
176  void moveCurrentIndexUp();
177  void moveCurrentIndexDown();
178  void moveCurrentIndexLeft();
179  void moveCurrentIndexRight();
180 
181 Q_SIGNALS:
182  void countChanged();
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();
192  void modelChanged();
193  void delegateChanged();
194  void flowChanged();
195  Q_REVISION(1) void layoutDirectionChanged();
196  void keyNavigationWrapsChanged();
197  void cacheBufferChanged();
198  void snapModeChanged();
199  void headerChanged();
200  void footerChanged();
201 
202 protected:
203  virtual bool event(QEvent *event);
204  virtual void viewportMoved();
205  virtual qreal minYExtent() const;
206  virtual qreal maxYExtent() const;
207  virtual qreal minXExtent() const;
208  virtual qreal maxXExtent() const;
209  virtual void keyPressEvent(QKeyEvent *);
210  virtual void componentComplete();
211 
212 private Q_SLOTS:
213  void trackedPositionChanged();
214  void itemsInserted(int index, int count);
215  void itemsRemoved(int index, int count);
216  void itemsMoved(int from, int to, int count);
217  void modelReset();
218  void destroyRemoved();
219  void createdItem(int index, QDeclarativeItem *item);
220  void destroyingItem(QDeclarativeItem *item);
221  void animStopped();
222 
223 private:
224  void refill();
225 };
226 
228 {
229  Q_OBJECT
230 public:
232  : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
234 
236  QDeclarativeGridView *view() { return m_view; }
238  if (view != m_view) {
239  m_view = view;
240  emit viewChanged();
241  }
242  }
243 
245  bool isCurrentItem() const { return m_isCurrent; }
246  void setIsCurrentItem(bool c) {
247  if (m_isCurrent != c) {
248  m_isCurrent = c;
249  emit currentItemChanged();
250  }
251  }
252 
254  bool delayRemove() const { return m_delayRemove; }
255  void setDelayRemove(bool delay) {
256  if (m_delayRemove != delay) {
257  m_delayRemove = delay;
258  emit delayRemoveChanged();
259  }
260  }
261 
262  void emitAdd() { emit add(); }
263  void emitRemove() { emit remove(); }
264 
265 Q_SIGNALS:
266  void currentItemChanged();
267  void delayRemoveChanged();
268  void add();
269  void remove();
270  void viewChanged();
271 
272 public:
274  bool m_isCurrent : 1;
275  bool m_delayRemove : 1;
276 };
277 
278 
280 
283 
285 
286 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QKeyEvent class describes a key event.
Definition: qevent.h:224
#define Q_CLASSINFO(name, value)
This macro associates extra information to the class, which is available using QObject::metaObject()...
Definition: qobjectdefs.h:78
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual qreal maxYExtent() const
QScopedPointer< QGraphicsItemPrivate > d_ptr
#define add(aName)
#define QML_DECLARE_TYPE(TYPE)
Definition: qdeclarative.h:56
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual bool event(QEvent *)
#define Q_INVOKABLE
Definition: qobjectdefs.h:90
virtual void keyPressEvent(QKeyEvent *event)
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
virtual qreal minYExtent() const
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
#define QML_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition: qdeclarative.h:73
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QDeclarativeComponent class encapsulates a QML component definition.
The QDeclarativeItem class provides the most basic of all visual items in QML.
QVariant data(int key) const
Returns this item&#39;s custom data for the key key as a QVariant.
#define emit
Definition: qobjectdefs.h:76
LayoutDirection
Definition: qnamespace.h:1580
static const char * data(const QByteArray &arr)
virtual qreal minXExtent() const
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_DECLARE_PRIVATE_D(Dptr, Class)
Definition: qglobal.h:2472
The Flow item arranges its children side by side, wrapping as necessary.
void setView(QDeclarativeGridView *view)
virtual void componentComplete()
Definition: qnamespace.h:54
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
quint16 index
QDeclarativeGuard< QDeclarativeGridView > m_view
virtual void setContentX(qreal pos)
virtual qreal maxXExtent() const
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
virtual IFMETHOD End(void)=0
virtual void setContentY(qreal pos)