Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativegridview_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
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 "QtDeclarative/private/qdeclarativeguard_p.h"
47
48 QT_BEGIN_HEADER
49
50 QT_BEGIN_NAMESPACE
51
52 class QDeclarative1VisualModel;
53 class QDeclarative1GridViewAttached;
54 class QDeclarative1GridViewPrivate;
55 class Q_AUTOTEST_EXPORT QDeclarative1GridView : public QDeclarative1Flickable
56 {
57     Q_OBJECT
58     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1GridView)
59
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)
65
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)
70
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)
74
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)
82
83     Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
84
85     Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
86     Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
87
88     Q_ENUMS(HighlightRangeMode)
89     Q_ENUMS(SnapMode)
90     Q_ENUMS(Flow)
91     Q_ENUMS(PositionMode)
92     Q_CLASSINFO("DefaultProperty", "data")
93
94 public:
95     QDeclarative1GridView(QDeclarativeItem *parent=0);
96     ~QDeclarative1GridView();
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 QDeclarative1GridViewAttached *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     Q_REVISION(1) void effectiveLayoutDirectionChanged();
197     void keyNavigationWrapsChanged();
198     void cacheBufferChanged();
199     void snapModeChanged();
200     void headerChanged();
201     void footerChanged();
202
203 protected:
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();
212
213 private Q_SLOTS:
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);
218     void modelReset();
219     void destroyRemoved();
220     void createdItem(int index, QDeclarativeItem *item);
221     void destroyingItem(QDeclarativeItem *item);
222     void animStopped();
223
224 private:
225     void refill();
226 };
227
228 class QDeclarative1GridViewAttached : public QObject
229 {
230     Q_OBJECT
231 public:
232     QDeclarative1GridViewAttached(QObject *parent)
233         : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
234     ~QDeclarative1GridViewAttached() {}
235
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) {
240             m_view = view;
241             emit viewChanged();
242         }
243     }
244
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) {
249             m_isCurrent = c;
250             emit currentItemChanged();
251         }
252     }
253
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();
260         }
261     }
262
263     void emitAdd() { emit add(); }
264     void emitRemove() { emit remove(); }
265
266 Q_SIGNALS:
267     void currentItemChanged();
268     void delayRemoveChanged();
269     void add();
270     void remove();
271     void viewChanged();
272
273 public:
274     QDeclarativeGuard<QDeclarative1GridView> m_view;
275     bool m_isCurrent : 1;
276     bool m_delayRemove : 1;
277 };
278
279
280 QT_END_NAMESPACE
281
282 QML_DECLARE_TYPE(QDeclarative1GridView)
283 QML_DECLARE_TYPEINFO(QDeclarative1GridView, QML_HAS_ATTACHED_PROPERTIES)
284
285 QT_END_HEADER
286
287 #endif