Fix test fails related to QTBUG-22237
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgpositioners_p.h
1 // Commit: 2c7cab4172f1acc86fd49345a2847417e162f2c3
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGPOSITIONERS_P_H
44 #define QSGPOSITIONERS_P_H
45
46 #include "qsgimplicitsizeitem_p.h"
47
48 #include <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 QT_MODULE(Declarative)
59
60 class QSGBasePositionerPrivate;
61
62 class QSGPositionerAttached : public QObject
63 {
64     Q_OBJECT
65
66 public:
67     QSGPositionerAttached(QObject *parent);
68
69     Q_PROPERTY(int index READ index NOTIFY indexChanged)
70     Q_PROPERTY(bool isFirstItem READ isFirstItem NOTIFY isFirstItemChanged)
71     Q_PROPERTY(bool isLastItem READ isLastItem NOTIFY isLastItemChanged)
72
73     int index() const { return m_index; }
74     void setIndex(int index);
75
76     bool isFirstItem() const { return m_isFirstItem; }
77     void setIsFirstItem(bool isFirstItem);
78
79     bool isLastItem() const { return m_isLastItem; }
80     void setIsLastItem(bool isLastItem);
81
82 Q_SIGNALS:
83     void indexChanged();
84     void isFirstItemChanged();
85     void isLastItemChanged();
86
87 private:
88     int m_index;
89     bool m_isFirstItem;
90     bool m_isLastItem;
91 };
92
93 class Q_DECLARATIVE_PRIVATE_EXPORT QSGBasePositioner : public QSGImplicitSizeItem
94 {
95     Q_OBJECT
96
97     Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
98     Q_PROPERTY(QDeclarativeTransition *move READ move WRITE setMove NOTIFY moveChanged)
99     Q_PROPERTY(QDeclarativeTransition *add READ add WRITE setAdd NOTIFY addChanged)
100 public:
101     enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 };
102     QSGBasePositioner(PositionerType, QSGItem *parent);
103     ~QSGBasePositioner();
104
105     int spacing() const;
106     void setSpacing(int);
107
108     QDeclarativeTransition *move() const;
109     void setMove(QDeclarativeTransition *);
110
111     QDeclarativeTransition *add() const;
112     void setAdd(QDeclarativeTransition *);
113
114     static QSGPositionerAttached *qmlAttachedProperties(QObject *obj);
115
116     void updateAttachedProperties(QSGPositionerAttached *specificProperty = 0, QSGItem *specificPropertyOwner = 0) const;
117
118 protected:
119     QSGBasePositioner(QSGBasePositionerPrivate &dd, PositionerType at, QSGItem *parent);
120     virtual void componentComplete();
121     virtual void itemChange(ItemChange, const ItemChangeData &);
122     void finishApplyTransitions();
123
124     virtual void updatePolish();
125
126 Q_SIGNALS:
127     void spacingChanged();
128     void moveChanged();
129     void addChanged();
130
131 protected Q_SLOTS:
132     void prePositioning();
133
134 protected:
135     virtual void doPositioning(QSizeF *contentSize)=0;
136     virtual void reportConflictingAnchors()=0;
137     class PositionedItem {
138     public :
139         PositionedItem(QSGItem *i) : item(i), isNew(false), isVisible(true) {}
140         bool operator==(const PositionedItem &other) const { return other.item == item; }
141         QSGItem *item;
142         bool isNew;
143         bool isVisible;
144     };
145
146     QPODVector<PositionedItem,8> positionedItems;
147     void positionX(int,const PositionedItem &target);
148     void positionY(int,const PositionedItem &target);
149
150 private:
151     Q_DISABLE_COPY(QSGBasePositioner)
152     Q_DECLARE_PRIVATE(QSGBasePositioner)
153 };
154
155 class Q_AUTOTEST_EXPORT QSGColumn : public QSGBasePositioner
156 {
157     Q_OBJECT
158 public:
159     QSGColumn(QSGItem *parent=0);
160
161 protected:
162     virtual void doPositioning(QSizeF *contentSize);
163     virtual void reportConflictingAnchors();
164 private:
165     Q_DISABLE_COPY(QSGColumn)
166 };
167
168 class Q_AUTOTEST_EXPORT QSGRow: public QSGBasePositioner
169 {
170     Q_OBJECT
171     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
172     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
173 public:
174     QSGRow(QSGItem *parent=0);
175
176     Qt::LayoutDirection layoutDirection() const;
177     void setLayoutDirection (Qt::LayoutDirection);
178     Qt::LayoutDirection effectiveLayoutDirection() const;
179
180 Q_SIGNALS:
181     void layoutDirectionChanged();
182     void effectiveLayoutDirectionChanged();
183
184 protected:
185     virtual void doPositioning(QSizeF *contentSize);
186     virtual void reportConflictingAnchors();
187 private:
188     Q_DISABLE_COPY(QSGRow)
189 };
190
191 class Q_AUTOTEST_EXPORT QSGGrid : public QSGBasePositioner
192 {
193     Q_OBJECT
194     Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
195     Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
196     Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
197     Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
198     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
199     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
200     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
201
202 public:
203     QSGGrid(QSGItem *parent=0);
204
205     int rows() const {return m_rows;}
206     void setRows(const int rows);
207
208     int columns() const {return m_columns;}
209     void setColumns(const int columns);
210
211     int rowSpacing() const { return m_rowSpacing; }
212     void setRowSpacing(int);
213
214     int columnSpacing() const { return m_columnSpacing; }
215     void setColumnSpacing(int);
216
217     Q_ENUMS(Flow)
218     enum Flow { LeftToRight, TopToBottom };
219     Flow flow() const;
220     void setFlow(Flow);
221
222     Qt::LayoutDirection layoutDirection() const;
223     void setLayoutDirection (Qt::LayoutDirection);
224     Qt::LayoutDirection effectiveLayoutDirection() const;
225
226 Q_SIGNALS:
227     void rowsChanged();
228     void columnsChanged();
229     void flowChanged();
230     void layoutDirectionChanged();
231     void effectiveLayoutDirectionChanged();
232     void rowSpacingChanged();
233     void columnSpacingChanged();
234
235 protected:
236     virtual void doPositioning(QSizeF *contentSize);
237     virtual void reportConflictingAnchors();
238
239 private:
240     int m_rows;
241     int m_columns;
242     int m_rowSpacing;
243     int m_columnSpacing;
244     Flow m_flow;
245     Q_DISABLE_COPY(QSGGrid)
246 };
247
248 class QSGFlowPrivate;
249 class Q_AUTOTEST_EXPORT QSGFlow: public QSGBasePositioner
250 {
251     Q_OBJECT
252     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
253     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
254     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
255 public:
256     QSGFlow(QSGItem *parent=0);
257
258     Q_ENUMS(Flow)
259     enum Flow { LeftToRight, TopToBottom };
260     Flow flow() const;
261     void setFlow(Flow);
262
263     Qt::LayoutDirection layoutDirection() const;
264     void setLayoutDirection (Qt::LayoutDirection);
265     Qt::LayoutDirection effectiveLayoutDirection() const;
266
267 Q_SIGNALS:
268     void flowChanged();
269     void layoutDirectionChanged();
270     void effectiveLayoutDirectionChanged();
271
272 protected:
273     virtual void doPositioning(QSizeF *contentSize);
274     virtual void reportConflictingAnchors();
275 protected:
276     QSGFlow(QSGFlowPrivate &dd, QSGItem *parent);
277 private:
278     Q_DISABLE_COPY(QSGFlow)
279     Q_DECLARE_PRIVATE(QSGFlow)
280 };
281
282
283 QT_END_NAMESPACE
284
285 QML_DECLARE_TYPE(QSGColumn)
286 QML_DECLARE_TYPE(QSGRow)
287 QML_DECLARE_TYPE(QSGGrid)
288 QML_DECLARE_TYPE(QSGFlow)
289
290 QML_DECLARE_TYPE(QSGBasePositioner)
291 QML_DECLARE_TYPEINFO(QSGBasePositioner, QML_HAS_ATTACHED_PROPERTIES)
292
293 QT_END_HEADER
294
295 #endif // QSGPOSITIONERS_P_H