More documentation about importing LocalStorage module from Javascript
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickpositioners_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 QQUICKPOSITIONERS_P_H
43 #define QQUICKPOSITIONERS_P_H
44
45 #include "qquickimplicitsizeitem_p.h"
46 #include "qquickitemviewtransition_p.h"
47
48 #include <QtQuick/private/qdeclarativestate_p.h>
49 #include <private/qpodvector_p.h>
50
51 #include <QtCore/qobject.h>
52 #include <QtCore/qstring.h>
53
54 QT_BEGIN_HEADER
55
56 QT_BEGIN_NAMESPACE
57
58 class QQuickBasePositionerPrivate;
59
60 class QQuickPositionerAttached : public QObject
61 {
62     Q_OBJECT
63
64 public:
65     QQuickPositionerAttached(QObject *parent);
66
67     Q_PROPERTY(int index READ index NOTIFY indexChanged)
68     Q_PROPERTY(bool isFirstItem READ isFirstItem NOTIFY isFirstItemChanged)
69     Q_PROPERTY(bool isLastItem READ isLastItem NOTIFY isLastItemChanged)
70
71     int index() const { return m_index; }
72     void setIndex(int index);
73
74     bool isFirstItem() const { return m_isFirstItem; }
75     void setIsFirstItem(bool isFirstItem);
76
77     bool isLastItem() const { return m_isLastItem; }
78     void setIsLastItem(bool isLastItem);
79
80 Q_SIGNALS:
81     void indexChanged();
82     void isFirstItemChanged();
83     void isLastItemChanged();
84
85 private:
86     int m_index;
87     bool m_isFirstItem;
88     bool m_isLastItem;
89 };
90
91 class Q_QUICK_PRIVATE_EXPORT QQuickBasePositioner : public QQuickImplicitSizeItem
92 {
93     Q_OBJECT
94
95     Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
96     Q_PROPERTY(QDeclarativeTransition *move READ move WRITE setMove NOTIFY moveChanged)
97     Q_PROPERTY(QDeclarativeTransition *add READ add WRITE setAdd NOTIFY addChanged)
98 public:
99     enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 };
100
101     QQuickBasePositioner(PositionerType, QQuickItem *parent);
102     ~QQuickBasePositioner();
103
104     qreal spacing() const;
105     void setSpacing(qreal);
106
107     QDeclarativeTransition *move() const;
108     void setMove(QDeclarativeTransition *);
109
110     QDeclarativeTransition *add() const;
111     void setAdd(QDeclarativeTransition *);
112
113     static QQuickPositionerAttached *qmlAttachedProperties(QObject *obj);
114
115     void updateAttachedProperties(QQuickPositionerAttached *specificProperty = 0, QQuickItem *specificPropertyOwner = 0) const;
116
117 protected:
118     QQuickBasePositioner(QQuickBasePositionerPrivate &dd, PositionerType at, QQuickItem *parent);
119     virtual void componentComplete();
120     virtual void itemChange(ItemChange, const ItemChangeData &);
121
122     virtual void updatePolish();
123
124 Q_SIGNALS:
125     void spacingChanged();
126     void moveChanged();
127     void addChanged();
128
129 protected Q_SLOTS:
130     void prePositioning();
131
132 protected:
133     virtual void doPositioning(QSizeF *contentSize)=0;
134     virtual void reportConflictingAnchors()=0;
135
136     class PositionedItem : public QQuickViewItem
137     {
138     public :
139         PositionedItem(QQuickItem *i) : QQuickViewItem(i), isNew(false), isVisible(true) {}
140         bool operator==(const PositionedItem &other) const { return other.item == item; }
141
142         bool isNew;
143         bool isVisible;
144     };
145
146     QPODVector<PositionedItem,8> positionedItems;
147     QPODVector<PositionedItem,8> unpositionedItems;//Still 'in' the positioner, just not positioned
148     void positionItem(qreal x, qreal y, PositionedItem *target);
149     void positionItemX(qreal, PositionedItem *target);
150     void positionItemY(qreal, PositionedItem *target);
151
152 private:
153     Q_DISABLE_COPY(QQuickBasePositioner)
154     Q_DECLARE_PRIVATE(QQuickBasePositioner)
155 };
156
157 class Q_AUTOTEST_EXPORT QQuickColumn : public QQuickBasePositioner
158 {
159     Q_OBJECT
160 public:
161     QQuickColumn(QQuickItem *parent=0);
162
163 protected:
164     virtual void doPositioning(QSizeF *contentSize);
165     virtual void reportConflictingAnchors();
166 private:
167     Q_DISABLE_COPY(QQuickColumn)
168 };
169
170 class Q_AUTOTEST_EXPORT QQuickRow: public QQuickBasePositioner
171 {
172     Q_OBJECT
173     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
174     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
175 public:
176     QQuickRow(QQuickItem *parent=0);
177
178     Qt::LayoutDirection layoutDirection() const;
179     void setLayoutDirection (Qt::LayoutDirection);
180     Qt::LayoutDirection effectiveLayoutDirection() const;
181
182 Q_SIGNALS:
183     void layoutDirectionChanged();
184     void effectiveLayoutDirectionChanged();
185
186 protected:
187     virtual void doPositioning(QSizeF *contentSize);
188     virtual void reportConflictingAnchors();
189 private:
190     Q_DISABLE_COPY(QQuickRow)
191 };
192
193 class Q_AUTOTEST_EXPORT QQuickGrid : public QQuickBasePositioner
194 {
195     Q_OBJECT
196     Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
197     Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
198     Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged RESET resetRowSpacing)
199     Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged RESET resetColumnSpacing)
200     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
201     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
202     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
203
204 public:
205     QQuickGrid(QQuickItem *parent=0);
206
207     int rows() const { return m_rows; }
208     void setRows(const int rows);
209
210     int columns() const { return m_columns; }
211     void setColumns(const int columns);
212
213     qreal rowSpacing() const { return m_rowSpacing; }
214     void setRowSpacing(qreal);
215     void resetRowSpacing() { m_useRowSpacing = false; }
216
217     qreal columnSpacing() const { return m_columnSpacing; }
218     void setColumnSpacing(qreal);
219     void resetColumnSpacing() { m_useColumnSpacing = false; }
220
221     Q_ENUMS(Flow)
222     enum Flow { LeftToRight, TopToBottom };
223     Flow flow() const;
224     void setFlow(Flow);
225
226     Qt::LayoutDirection layoutDirection() const;
227     void setLayoutDirection (Qt::LayoutDirection);
228     Qt::LayoutDirection effectiveLayoutDirection() const;
229
230 Q_SIGNALS:
231     void rowsChanged();
232     void columnsChanged();
233     void flowChanged();
234     void layoutDirectionChanged();
235     void effectiveLayoutDirectionChanged();
236     void rowSpacingChanged();
237     void columnSpacingChanged();
238
239 protected:
240     virtual void doPositioning(QSizeF *contentSize);
241     virtual void reportConflictingAnchors();
242
243 private:
244     int m_rows;
245     int m_columns;
246     qreal m_rowSpacing;
247     qreal m_columnSpacing;
248     bool m_useRowSpacing;
249     bool m_useColumnSpacing;
250     Flow m_flow;
251     Q_DISABLE_COPY(QQuickGrid)
252 };
253
254 class QQuickFlowPrivate;
255 class Q_AUTOTEST_EXPORT QQuickFlow: public QQuickBasePositioner
256 {
257     Q_OBJECT
258     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
259     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
260     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
261 public:
262     QQuickFlow(QQuickItem *parent=0);
263
264     Q_ENUMS(Flow)
265     enum Flow { LeftToRight, TopToBottom };
266     Flow flow() const;
267     void setFlow(Flow);
268
269     Qt::LayoutDirection layoutDirection() const;
270     void setLayoutDirection (Qt::LayoutDirection);
271     Qt::LayoutDirection effectiveLayoutDirection() const;
272
273 Q_SIGNALS:
274     void flowChanged();
275     void layoutDirectionChanged();
276     void effectiveLayoutDirectionChanged();
277
278 protected:
279     virtual void doPositioning(QSizeF *contentSize);
280     virtual void reportConflictingAnchors();
281 protected:
282     QQuickFlow(QQuickFlowPrivate &dd, QQuickItem *parent);
283 private:
284     Q_DISABLE_COPY(QQuickFlow)
285     Q_DECLARE_PRIVATE(QQuickFlow)
286 };
287
288
289 QT_END_NAMESPACE
290
291 QML_DECLARE_TYPE(QQuickColumn)
292 QML_DECLARE_TYPE(QQuickRow)
293 QML_DECLARE_TYPE(QQuickGrid)
294 QML_DECLARE_TYPE(QQuickFlow)
295
296 QML_DECLARE_TYPE(QQuickBasePositioner)
297 QML_DECLARE_TYPEINFO(QQuickBasePositioner, QML_HAS_ATTACHED_PROPERTIES)
298
299 QT_END_HEADER
300
301 #endif // QQUICKPOSITIONERS_P_H