1 // Commit: 2c7cab4172f1acc86fd49345a2847417e162f2c3
2 /****************************************************************************
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
41 ****************************************************************************/
43 #ifndef QSGPOSITIONERS_P_H
44 #define QSGPOSITIONERS_P_H
46 #include "qsgimplicitsizeitem_p.h"
48 #include <private/qdeclarativestate_p.h>
49 #include <private/qpodvector_p.h>
51 #include <QtCore/qobject.h>
52 #include <QtCore/qstring.h>
58 QT_MODULE(Declarative)
60 class QSGBasePositionerPrivate;
62 class QSGPositionerAttached : public QObject
67 QSGPositionerAttached(QObject *parent);
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)
73 int index() const { return m_index; }
74 void setIndex(int index);
76 bool isFirstItem() const { return m_isFirstItem; }
77 void setIsFirstItem(bool isFirstItem);
79 bool isLastItem() const { return m_isLastItem; }
80 void setIsLastItem(bool isLastItem);
84 void isFirstItemChanged();
85 void isLastItemChanged();
93 class Q_DECLARATIVE_PRIVATE_EXPORT QSGBasePositioner : public QSGImplicitSizeItem
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)
101 enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 };
102 QSGBasePositioner(PositionerType, QSGItem *parent);
103 ~QSGBasePositioner();
106 void setSpacing(int);
108 QDeclarativeTransition *move() const;
109 void setMove(QDeclarativeTransition *);
111 QDeclarativeTransition *add() const;
112 void setAdd(QDeclarativeTransition *);
114 static QSGPositionerAttached *qmlAttachedProperties(QObject *obj);
116 void updateAttachedProperties(QSGPositionerAttached *specificProperty = 0, QSGItem *specificPropertyOwner = 0) const;
119 QSGBasePositioner(QSGBasePositionerPrivate &dd, PositionerType at, QSGItem *parent);
120 virtual void componentComplete();
121 virtual void itemChange(ItemChange, const ItemChangeData &);
122 void finishApplyTransitions();
124 virtual void updatePolish();
127 void spacingChanged();
132 void prePositioning();
135 virtual void doPositioning(QSizeF *contentSize)=0;
136 virtual void reportConflictingAnchors()=0;
137 class PositionedItem {
139 PositionedItem(QSGItem *i) : item(i), isNew(false), isVisible(true) {}
140 bool operator==(const PositionedItem &other) const { return other.item == item; }
146 QPODVector<PositionedItem,8> positionedItems;
147 void positionX(int,const PositionedItem &target);
148 void positionY(int,const PositionedItem &target);
151 Q_DISABLE_COPY(QSGBasePositioner)
152 Q_DECLARE_PRIVATE(QSGBasePositioner)
155 class Q_AUTOTEST_EXPORT QSGColumn : public QSGBasePositioner
159 QSGColumn(QSGItem *parent=0);
162 virtual void doPositioning(QSizeF *contentSize);
163 virtual void reportConflictingAnchors();
165 Q_DISABLE_COPY(QSGColumn)
168 class Q_AUTOTEST_EXPORT QSGRow: public QSGBasePositioner
171 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
172 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
174 QSGRow(QSGItem *parent=0);
176 Qt::LayoutDirection layoutDirection() const;
177 void setLayoutDirection (Qt::LayoutDirection);
178 Qt::LayoutDirection effectiveLayoutDirection() const;
181 void layoutDirectionChanged();
182 void effectiveLayoutDirectionChanged();
185 virtual void doPositioning(QSizeF *contentSize);
186 virtual void reportConflictingAnchors();
188 Q_DISABLE_COPY(QSGRow)
191 class Q_AUTOTEST_EXPORT QSGGrid : public QSGBasePositioner
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)
203 QSGGrid(QSGItem *parent=0);
205 int rows() const {return m_rows;}
206 void setRows(const int rows);
208 int columns() const {return m_columns;}
209 void setColumns(const int columns);
211 int rowSpacing() const { return m_rowSpacing; }
212 void setRowSpacing(int);
214 int columnSpacing() const { return m_columnSpacing; }
215 void setColumnSpacing(int);
218 enum Flow { LeftToRight, TopToBottom };
222 Qt::LayoutDirection layoutDirection() const;
223 void setLayoutDirection (Qt::LayoutDirection);
224 Qt::LayoutDirection effectiveLayoutDirection() const;
228 void columnsChanged();
230 void layoutDirectionChanged();
231 void effectiveLayoutDirectionChanged();
232 void rowSpacingChanged();
233 void columnSpacingChanged();
236 virtual void doPositioning(QSizeF *contentSize);
237 virtual void reportConflictingAnchors();
245 Q_DISABLE_COPY(QSGGrid)
248 class QSGFlowPrivate;
249 class Q_AUTOTEST_EXPORT QSGFlow: public QSGBasePositioner
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)
256 QSGFlow(QSGItem *parent=0);
259 enum Flow { LeftToRight, TopToBottom };
263 Qt::LayoutDirection layoutDirection() const;
264 void setLayoutDirection (Qt::LayoutDirection);
265 Qt::LayoutDirection effectiveLayoutDirection() const;
269 void layoutDirectionChanged();
270 void effectiveLayoutDirectionChanged();
273 virtual void doPositioning(QSizeF *contentSize);
274 virtual void reportConflictingAnchors();
276 QSGFlow(QSGFlowPrivate &dd, QSGItem *parent);
278 Q_DISABLE_COPY(QSGFlow)
279 Q_DECLARE_PRIVATE(QSGFlow)
285 QML_DECLARE_TYPE(QSGColumn)
286 QML_DECLARE_TYPE(QSGRow)
287 QML_DECLARE_TYPE(QSGGrid)
288 QML_DECLARE_TYPE(QSGFlow)
290 QML_DECLARE_TYPE(QSGBasePositioner)
291 QML_DECLARE_TYPEINFO(QSGBasePositioner, QML_HAS_ATTACHED_PROPERTIES)
295 #endif // QSGPOSITIONERS_P_H