1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKPOSITIONERS_P_H
43 #define QQUICKPOSITIONERS_P_H
45 #include "qquickimplicitsizeitem_p.h"
46 #include "qquickitemviewtransition_p.h"
48 #include <QtQuick/private/qdeclarativestate_p.h>
49 #include <private/qpodvector_p.h>
51 #include <QtCore/qobject.h>
52 #include <QtCore/qstring.h>
58 class QQuickBasePositionerPrivate;
60 class QQuickPositionerAttached : public QObject
65 QQuickPositionerAttached(QObject *parent);
67 Q_PROPERTY(int index READ index NOTIFY indexChanged)
68 Q_PROPERTY(bool isFirstItem READ isFirstItem NOTIFY isFirstItemChanged)
69 Q_PROPERTY(bool isLastItem READ isLastItem NOTIFY isLastItemChanged)
71 int index() const { return m_index; }
72 void setIndex(int index);
74 bool isFirstItem() const { return m_isFirstItem; }
75 void setIsFirstItem(bool isFirstItem);
77 bool isLastItem() const { return m_isLastItem; }
78 void setIsLastItem(bool isLastItem);
82 void isFirstItemChanged();
83 void isLastItemChanged();
91 class Q_QUICK_PRIVATE_EXPORT QQuickBasePositioner : public QQuickImplicitSizeItem
95 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
96 Q_PROPERTY(QDeclarativeTransition *move READ move WRITE setMove NOTIFY moveChanged)
97 Q_PROPERTY(QDeclarativeTransition *add READ add WRITE setAdd NOTIFY addChanged)
99 enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 };
101 QQuickBasePositioner(PositionerType, QQuickItem *parent);
102 ~QQuickBasePositioner();
104 qreal spacing() const;
105 void setSpacing(qreal);
107 QDeclarativeTransition *move() const;
108 void setMove(QDeclarativeTransition *);
110 QDeclarativeTransition *add() const;
111 void setAdd(QDeclarativeTransition *);
113 static QQuickPositionerAttached *qmlAttachedProperties(QObject *obj);
115 void updateAttachedProperties(QQuickPositionerAttached *specificProperty = 0, QQuickItem *specificPropertyOwner = 0) const;
118 QQuickBasePositioner(QQuickBasePositionerPrivate &dd, PositionerType at, QQuickItem *parent);
119 virtual void componentComplete();
120 virtual void itemChange(ItemChange, const ItemChangeData &);
122 virtual void updatePolish();
125 void spacingChanged();
130 void prePositioning();
133 virtual void doPositioning(QSizeF *contentSize)=0;
134 virtual void reportConflictingAnchors()=0;
136 class PositionedItem : public QQuickViewItem
139 PositionedItem(QQuickItem *i) : QQuickViewItem(i), isNew(false), isVisible(true) {}
140 bool operator==(const PositionedItem &other) const { return other.item == item; }
146 QPODVector<PositionedItem,8> positionedItems;
147 QPODVector<PositionedItem,8> unpositionedItems;//Still 'in' the positioner, just not positioned
148 void positionItem(qreal x, qreal y, PositionedItem *target);
149 void positionItemX(qreal, PositionedItem *target);
150 void positionItemY(qreal, PositionedItem *target);
153 Q_DISABLE_COPY(QQuickBasePositioner)
154 Q_DECLARE_PRIVATE(QQuickBasePositioner)
157 class Q_AUTOTEST_EXPORT QQuickColumn : public QQuickBasePositioner
161 QQuickColumn(QQuickItem *parent=0);
164 virtual void doPositioning(QSizeF *contentSize);
165 virtual void reportConflictingAnchors();
167 Q_DISABLE_COPY(QQuickColumn)
170 class Q_AUTOTEST_EXPORT QQuickRow: public QQuickBasePositioner
173 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
174 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
176 QQuickRow(QQuickItem *parent=0);
178 Qt::LayoutDirection layoutDirection() const;
179 void setLayoutDirection (Qt::LayoutDirection);
180 Qt::LayoutDirection effectiveLayoutDirection() const;
183 void layoutDirectionChanged();
184 void effectiveLayoutDirectionChanged();
187 virtual void doPositioning(QSizeF *contentSize);
188 virtual void reportConflictingAnchors();
190 Q_DISABLE_COPY(QQuickRow)
193 class Q_AUTOTEST_EXPORT QQuickGrid : public QQuickBasePositioner
196 Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
197 Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
198 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged RESET resetRowSpacing)
199 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged RESET resetColumnSpacing)
200 Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
201 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
202 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
205 QQuickGrid(QQuickItem *parent=0);
207 int rows() const { return m_rows; }
208 void setRows(const int rows);
210 int columns() const { return m_columns; }
211 void setColumns(const int columns);
213 qreal rowSpacing() const { return m_rowSpacing; }
214 void setRowSpacing(qreal);
215 void resetRowSpacing() { m_useRowSpacing = false; }
217 qreal columnSpacing() const { return m_columnSpacing; }
218 void setColumnSpacing(qreal);
219 void resetColumnSpacing() { m_useColumnSpacing = false; }
222 enum Flow { LeftToRight, TopToBottom };
226 Qt::LayoutDirection layoutDirection() const;
227 void setLayoutDirection (Qt::LayoutDirection);
228 Qt::LayoutDirection effectiveLayoutDirection() const;
232 void columnsChanged();
234 void layoutDirectionChanged();
235 void effectiveLayoutDirectionChanged();
236 void rowSpacingChanged();
237 void columnSpacingChanged();
240 virtual void doPositioning(QSizeF *contentSize);
241 virtual void reportConflictingAnchors();
247 qreal m_columnSpacing;
248 bool m_useRowSpacing;
249 bool m_useColumnSpacing;
251 Q_DISABLE_COPY(QQuickGrid)
254 class QQuickFlowPrivate;
255 class Q_AUTOTEST_EXPORT QQuickFlow: public QQuickBasePositioner
258 Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
259 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
260 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
262 QQuickFlow(QQuickItem *parent=0);
265 enum Flow { LeftToRight, TopToBottom };
269 Qt::LayoutDirection layoutDirection() const;
270 void setLayoutDirection (Qt::LayoutDirection);
271 Qt::LayoutDirection effectiveLayoutDirection() const;
275 void layoutDirectionChanged();
276 void effectiveLayoutDirectionChanged();
279 virtual void doPositioning(QSizeF *contentSize);
280 virtual void reportConflictingAnchors();
282 QQuickFlow(QQuickFlowPrivate &dd, QQuickItem *parent);
284 Q_DISABLE_COPY(QQuickFlow)
285 Q_DECLARE_PRIVATE(QQuickFlow)
291 QML_DECLARE_TYPE(QQuickColumn)
292 QML_DECLARE_TYPE(QQuickRow)
293 QML_DECLARE_TYPE(QQuickGrid)
294 QML_DECLARE_TYPE(QQuickFlow)
296 QML_DECLARE_TYPE(QQuickBasePositioner)
297 QML_DECLARE_TYPEINFO(QQuickBasePositioner, QML_HAS_ATTACHED_PROPERTIES)
301 #endif // QQUICKPOSITIONERS_P_H