Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickpositioners_p.h
1 // Commit: 2c7cab4172f1acc86fd49345a2847417e162f2c3
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKPOSITIONERS_P_H
44 #define QQUICKPOSITIONERS_P_H
45
46 #include "qquickimplicitsizeitem_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(int 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     QQuickBasePositioner(PositionerType, QQuickItem *parent);
101     ~QQuickBasePositioner();
102
103     int spacing() const;
104     void setSpacing(int);
105
106     QDeclarativeTransition *move() const;
107     void setMove(QDeclarativeTransition *);
108
109     QDeclarativeTransition *add() const;
110     void setAdd(QDeclarativeTransition *);
111
112     static QQuickPositionerAttached *qmlAttachedProperties(QObject *obj);
113
114     void updateAttachedProperties(QQuickPositionerAttached *specificProperty = 0, QQuickItem *specificPropertyOwner = 0) const;
115
116 protected:
117     QQuickBasePositioner(QQuickBasePositionerPrivate &dd, PositionerType at, QQuickItem *parent);
118     virtual void componentComplete();
119     virtual void itemChange(ItemChange, const ItemChangeData &);
120     void finishApplyTransitions();
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     class PositionedItem {
136     public :
137         PositionedItem(QQuickItem *i) : item(i), isNew(false), isVisible(true) {}
138         bool operator==(const PositionedItem &other) const { return other.item == item; }
139         QQuickItem *item;
140         bool isNew;
141         bool isVisible;
142     };
143
144     QPODVector<PositionedItem,8> positionedItems;
145     void positionX(int,const PositionedItem &target);
146     void positionY(int,const PositionedItem &target);
147
148 private:
149     Q_DISABLE_COPY(QQuickBasePositioner)
150     Q_DECLARE_PRIVATE(QQuickBasePositioner)
151 };
152
153 class Q_AUTOTEST_EXPORT QQuickColumn : public QQuickBasePositioner
154 {
155     Q_OBJECT
156 public:
157     QQuickColumn(QQuickItem *parent=0);
158
159 protected:
160     virtual void doPositioning(QSizeF *contentSize);
161     virtual void reportConflictingAnchors();
162 private:
163     Q_DISABLE_COPY(QQuickColumn)
164 };
165
166 class Q_AUTOTEST_EXPORT QQuickRow: public QQuickBasePositioner
167 {
168     Q_OBJECT
169     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
170     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
171 public:
172     QQuickRow(QQuickItem *parent=0);
173
174     Qt::LayoutDirection layoutDirection() const;
175     void setLayoutDirection (Qt::LayoutDirection);
176     Qt::LayoutDirection effectiveLayoutDirection() const;
177
178 Q_SIGNALS:
179     void layoutDirectionChanged();
180     void effectiveLayoutDirectionChanged();
181
182 protected:
183     virtual void doPositioning(QSizeF *contentSize);
184     virtual void reportConflictingAnchors();
185 private:
186     Q_DISABLE_COPY(QQuickRow)
187 };
188
189 class Q_AUTOTEST_EXPORT QQuickGrid : public QQuickBasePositioner
190 {
191     Q_OBJECT
192     Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
193     Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
194     Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
195     Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
196     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
197     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
198     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
199
200 public:
201     QQuickGrid(QQuickItem *parent=0);
202
203     int rows() const {return m_rows;}
204     void setRows(const int rows);
205
206     int columns() const {return m_columns;}
207     void setColumns(const int columns);
208
209     int rowSpacing() const { return m_rowSpacing; }
210     void setRowSpacing(int);
211
212     int columnSpacing() const { return m_columnSpacing; }
213     void setColumnSpacing(int);
214
215     Q_ENUMS(Flow)
216     enum Flow { LeftToRight, TopToBottom };
217     Flow flow() const;
218     void setFlow(Flow);
219
220     Qt::LayoutDirection layoutDirection() const;
221     void setLayoutDirection (Qt::LayoutDirection);
222     Qt::LayoutDirection effectiveLayoutDirection() const;
223
224 Q_SIGNALS:
225     void rowsChanged();
226     void columnsChanged();
227     void flowChanged();
228     void layoutDirectionChanged();
229     void effectiveLayoutDirectionChanged();
230     void rowSpacingChanged();
231     void columnSpacingChanged();
232
233 protected:
234     virtual void doPositioning(QSizeF *contentSize);
235     virtual void reportConflictingAnchors();
236
237 private:
238     int m_rows;
239     int m_columns;
240     int m_rowSpacing;
241     int m_columnSpacing;
242     Flow m_flow;
243     Q_DISABLE_COPY(QQuickGrid)
244 };
245
246 class QQuickFlowPrivate;
247 class Q_AUTOTEST_EXPORT QQuickFlow: public QQuickBasePositioner
248 {
249     Q_OBJECT
250     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
251     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
252     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
253 public:
254     QQuickFlow(QQuickItem *parent=0);
255
256     Q_ENUMS(Flow)
257     enum Flow { LeftToRight, TopToBottom };
258     Flow flow() const;
259     void setFlow(Flow);
260
261     Qt::LayoutDirection layoutDirection() const;
262     void setLayoutDirection (Qt::LayoutDirection);
263     Qt::LayoutDirection effectiveLayoutDirection() const;
264
265 Q_SIGNALS:
266     void flowChanged();
267     void layoutDirectionChanged();
268     void effectiveLayoutDirectionChanged();
269
270 protected:
271     virtual void doPositioning(QSizeF *contentSize);
272     virtual void reportConflictingAnchors();
273 protected:
274     QQuickFlow(QQuickFlowPrivate &dd, QQuickItem *parent);
275 private:
276     Q_DISABLE_COPY(QQuickFlow)
277     Q_DECLARE_PRIVATE(QQuickFlow)
278 };
279
280
281 QT_END_NAMESPACE
282
283 QML_DECLARE_TYPE(QQuickColumn)
284 QML_DECLARE_TYPE(QQuickRow)
285 QML_DECLARE_TYPE(QQuickGrid)
286 QML_DECLARE_TYPE(QQuickFlow)
287
288 QML_DECLARE_TYPE(QQuickBasePositioner)
289 QML_DECLARE_TYPEINFO(QQuickBasePositioner, QML_HAS_ATTACHED_PROPERTIES)
290
291 QT_END_HEADER
292
293 #endif // QQUICKPOSITIONERS_P_H