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