Initial import from qtquick2.
[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 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
15 ** this package.
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, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
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 Q_DECLARATIVE_PRIVATE_EXPORT QSGBasePositioner : public QSGImplicitSizeItem
63 {
64     Q_OBJECT
65
66     Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
67     Q_PROPERTY(QDeclarativeTransition *move READ move WRITE setMove NOTIFY moveChanged)
68     Q_PROPERTY(QDeclarativeTransition *add READ add WRITE setAdd NOTIFY addChanged)
69 public:
70     enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 };
71     QSGBasePositioner(PositionerType, QSGItem *parent);
72     ~QSGBasePositioner();
73
74     int spacing() const;
75     void setSpacing(int);
76
77     QDeclarativeTransition *move() const;
78     void setMove(QDeclarativeTransition *);
79
80     QDeclarativeTransition *add() const;
81     void setAdd(QDeclarativeTransition *);
82
83 protected:
84     QSGBasePositioner(QSGBasePositionerPrivate &dd, PositionerType at, QSGItem *parent);
85     virtual void componentComplete();
86     virtual void itemChange(ItemChange, const ItemChangeData &);
87     void finishApplyTransitions();
88
89 Q_SIGNALS:
90     void spacingChanged();
91     void moveChanged();
92     void addChanged();
93
94 protected Q_SLOTS:
95     void prePositioning();
96
97 protected:
98     virtual void doPositioning(QSizeF *contentSize)=0;
99     virtual void reportConflictingAnchors()=0;
100     class PositionedItem {
101     public :
102         PositionedItem(QSGItem *i) : item(i), isNew(false), isVisible(true) {}
103         bool operator==(const PositionedItem &other) const { return other.item == item; }
104         QSGItem *item;
105         bool isNew;
106         bool isVisible;
107     };
108
109     QPODVector<PositionedItem,8> positionedItems;
110     void positionX(int,const PositionedItem &target);
111     void positionY(int,const PositionedItem &target);
112
113 private:
114     Q_DISABLE_COPY(QSGBasePositioner)
115     Q_DECLARE_PRIVATE(QSGBasePositioner)
116 };
117
118 class Q_AUTOTEST_EXPORT QSGColumn : public QSGBasePositioner
119 {
120     Q_OBJECT
121 public:
122     QSGColumn(QSGItem *parent=0);
123 protected:
124     virtual void doPositioning(QSizeF *contentSize);
125     virtual void reportConflictingAnchors();
126 private:
127     Q_DISABLE_COPY(QSGColumn)
128 };
129
130 class Q_AUTOTEST_EXPORT QSGRow: public QSGBasePositioner
131 {
132     Q_OBJECT
133     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
134     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
135 public:
136     QSGRow(QSGItem *parent=0);
137
138     Qt::LayoutDirection layoutDirection() const;
139     void setLayoutDirection (Qt::LayoutDirection);
140     Qt::LayoutDirection effectiveLayoutDirection() const;
141
142 Q_SIGNALS:
143     void layoutDirectionChanged();
144     void effectiveLayoutDirectionChanged();
145
146 protected:
147     virtual void doPositioning(QSizeF *contentSize);
148     virtual void reportConflictingAnchors();
149 private:
150     Q_DISABLE_COPY(QSGRow)
151 };
152
153 class Q_AUTOTEST_EXPORT QSGGrid : public QSGBasePositioner
154 {
155     Q_OBJECT
156     Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
157     Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
158     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
159     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
160     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
161
162 public:
163     QSGGrid(QSGItem *parent=0);
164
165     int rows() const {return m_rows;}
166     void setRows(const int rows);
167
168     int columns() const {return m_columns;}
169     void setColumns(const int columns);
170
171     Q_ENUMS(Flow)
172     enum Flow { LeftToRight, TopToBottom };
173     Flow flow() const;
174     void setFlow(Flow);
175
176     Qt::LayoutDirection layoutDirection() const;
177     void setLayoutDirection (Qt::LayoutDirection);
178     Qt::LayoutDirection effectiveLayoutDirection() const;
179
180 Q_SIGNALS:
181     void rowsChanged();
182     void columnsChanged();
183     void flowChanged();
184     void layoutDirectionChanged();
185     void effectiveLayoutDirectionChanged();
186
187 protected:
188     virtual void doPositioning(QSizeF *contentSize);
189     virtual void reportConflictingAnchors();
190
191 private:
192     int m_rows;
193     int m_columns;
194     Flow m_flow;
195     Q_DISABLE_COPY(QSGGrid)
196 };
197
198 class QSGFlowPrivate;
199 class Q_AUTOTEST_EXPORT QSGFlow: public QSGBasePositioner
200 {
201     Q_OBJECT
202     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
203     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
204     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
205 public:
206     QSGFlow(QSGItem *parent=0);
207
208     Q_ENUMS(Flow)
209     enum Flow { LeftToRight, TopToBottom };
210     Flow flow() const;
211     void setFlow(Flow);
212
213     Qt::LayoutDirection layoutDirection() const;
214     void setLayoutDirection (Qt::LayoutDirection);
215     Qt::LayoutDirection effectiveLayoutDirection() const;
216
217 Q_SIGNALS:
218     void flowChanged();
219     void layoutDirectionChanged();
220     void effectiveLayoutDirectionChanged();
221
222 protected:
223     virtual void doPositioning(QSizeF *contentSize);
224     virtual void reportConflictingAnchors();
225 protected:
226     QSGFlow(QSGFlowPrivate &dd, QSGItem *parent);
227 private:
228     Q_DISABLE_COPY(QSGFlow)
229     Q_DECLARE_PRIVATE(QSGFlow)
230 };
231
232
233 QT_END_NAMESPACE
234
235 QML_DECLARE_TYPE(QSGColumn)
236 QML_DECLARE_TYPE(QSGRow)
237 QML_DECLARE_TYPE(QSGGrid)
238 QML_DECLARE_TYPE(QSGFlow)
239
240 QT_END_HEADER
241
242 #endif // QSGPOSITIONERS_P_H