Merge branch 'master' into refactor
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativepositioners_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVELAYOUTS_H
43 #define QDECLARATIVELAYOUTS_H
44
45 #include "qdeclarativeimplicitsizeitem_p.h"
46
47 #include <QtQuick1/private/qdeclarativestate_p.h>
48 #include <private/qpodvector_p.h>
49
50 #include <QtCore/QObject>
51 #include <QtCore/QString>
52
53 QT_BEGIN_HEADER
54
55 QT_BEGIN_NAMESPACE
56
57 QT_MODULE(Declarative)
58 class QDeclarative1BasePositionerPrivate;
59
60 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarative1BasePositioner : public QDeclarative1ImplicitSizeItem
61 {
62     Q_OBJECT
63
64     Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
65     Q_PROPERTY(QDeclarative1Transition *move READ move WRITE setMove NOTIFY moveChanged)
66     Q_PROPERTY(QDeclarative1Transition *add READ add WRITE setAdd NOTIFY addChanged)
67 public:
68     enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 };
69     QDeclarative1BasePositioner(PositionerType, QDeclarativeItem *parent);
70     ~QDeclarative1BasePositioner();
71
72     int spacing() const;
73     void setSpacing(int);
74
75     QDeclarative1Transition *move() const;
76     void setMove(QDeclarative1Transition *);
77
78     QDeclarative1Transition *add() const;
79     void setAdd(QDeclarative1Transition *);
80
81 protected:
82     QDeclarative1BasePositioner(QDeclarative1BasePositionerPrivate &dd, PositionerType at, QDeclarativeItem *parent);
83     virtual void componentComplete();
84     virtual QVariant itemChange(GraphicsItemChange, const QVariant &);
85     void finishApplyTransitions();
86
87 Q_SIGNALS:
88     void spacingChanged();
89     void moveChanged();
90     void addChanged();
91
92 protected Q_SLOTS:
93     void prePositioning();
94     void graphicsWidgetGeometryChanged();
95
96 protected:
97     virtual void doPositioning(QSizeF *contentSize)=0;
98     virtual void reportConflictingAnchors()=0;
99     class PositionedItem {
100     public :
101         PositionedItem(QGraphicsObject *i) : item(i), isNew(false), isVisible(true) {}
102         bool operator==(const PositionedItem &other) const { return other.item == item; }
103         QGraphicsObject *item;
104         bool isNew;
105         bool isVisible;
106     };
107
108     QPODVector<PositionedItem,8> positionedItems;
109     void positionX(int,const PositionedItem &target);
110     void positionY(int,const PositionedItem &target);
111
112 private:
113     Q_DISABLE_COPY(QDeclarative1BasePositioner)
114     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1BasePositioner)
115 };
116
117 class Q_AUTOTEST_EXPORT QDeclarative1Column : public QDeclarative1BasePositioner
118 {
119     Q_OBJECT
120 public:
121     QDeclarative1Column(QDeclarativeItem *parent=0);
122 protected:
123     virtual void doPositioning(QSizeF *contentSize);
124     virtual void reportConflictingAnchors();
125 private:
126     Q_DISABLE_COPY(QDeclarative1Column)
127 };
128
129 class Q_AUTOTEST_EXPORT QDeclarative1Row: public QDeclarative1BasePositioner
130 {
131     Q_OBJECT
132     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged REVISION 1)
133     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged REVISION 1)
134 public:
135     QDeclarative1Row(QDeclarativeItem *parent=0);
136
137     Qt::LayoutDirection layoutDirection() const;
138     void setLayoutDirection (Qt::LayoutDirection);
139     Qt::LayoutDirection effectiveLayoutDirection() const;
140
141 Q_SIGNALS:
142     Q_REVISION(1) void layoutDirectionChanged();
143     Q_REVISION(1) void effectiveLayoutDirectionChanged();
144
145 protected:
146     virtual void doPositioning(QSizeF *contentSize);
147     virtual void reportConflictingAnchors();
148 private:
149     Q_DISABLE_COPY(QDeclarative1Row)
150 };
151
152 class Q_AUTOTEST_EXPORT QDeclarative1Grid : public QDeclarative1BasePositioner
153 {
154     Q_OBJECT
155     Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
156     Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
157     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
158     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged REVISION 1)
159     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged REVISION 1)
160 public:
161     QDeclarative1Grid(QDeclarativeItem *parent=0);
162
163     int rows() const {return m_rows;}
164     void setRows(const int rows);
165
166     int columns() const {return m_columns;}
167     void setColumns(const int columns);
168
169     Q_ENUMS(Flow)
170     enum Flow { LeftToRight, TopToBottom };
171     Flow flow() const;
172     void setFlow(Flow);
173
174     Qt::LayoutDirection layoutDirection() const;
175     void setLayoutDirection (Qt::LayoutDirection);
176     Qt::LayoutDirection effectiveLayoutDirection() const;
177
178 Q_SIGNALS:
179     void rowsChanged();
180     void columnsChanged();
181     void flowChanged();
182     Q_REVISION(1) void layoutDirectionChanged();
183     Q_REVISION(1) void effectiveLayoutDirectionChanged();
184
185 protected:
186     virtual void doPositioning(QSizeF *contentSize);
187     virtual void reportConflictingAnchors();
188
189 private:
190     int m_rows;
191     int m_columns;
192     Flow m_flow;
193     Q_DISABLE_COPY(QDeclarative1Grid)
194 };
195
196 class QDeclarative1FlowPrivate;
197 class Q_AUTOTEST_EXPORT QDeclarative1Flow: public QDeclarative1BasePositioner
198 {
199     Q_OBJECT
200     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
201     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged REVISION 1)
202     Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged REVISION 1)
203 public:
204     QDeclarative1Flow(QDeclarativeItem *parent=0);
205
206     Q_ENUMS(Flow)
207     enum Flow { LeftToRight, TopToBottom };
208     Flow flow() const;
209     void setFlow(Flow);
210
211     Qt::LayoutDirection layoutDirection() const;
212     void setLayoutDirection (Qt::LayoutDirection);
213     Qt::LayoutDirection effectiveLayoutDirection() const;
214 Q_SIGNALS:
215     void flowChanged();
216     Q_REVISION(1) void layoutDirectionChanged();
217     Q_REVISION(1) void effectiveLayoutDirectionChanged();
218
219 protected:
220     virtual void doPositioning(QSizeF *contentSize);
221     virtual void reportConflictingAnchors();
222 protected:
223     QDeclarative1Flow(QDeclarative1FlowPrivate &dd, QDeclarativeItem *parent);
224 private:
225     Q_DISABLE_COPY(QDeclarative1Flow)
226     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1Flow)
227 };
228
229
230 QT_END_NAMESPACE
231
232 QML_DECLARE_TYPE(QDeclarative1Column)
233 QML_DECLARE_TYPE(QDeclarative1Row)
234 QML_DECLARE_TYPE(QDeclarative1Grid)
235 QML_DECLARE_TYPE(QDeclarative1Flow)
236
237 QT_END_HEADER
238
239 #endif