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 QDECLARATIVELAYOUTS_P_H
43 #define QDECLARATIVELAYOUTS_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "private/qdeclarativepositioners_p.h"
58 #include "private/qdeclarativeimplicitsizeitem_p_p.h"
60 #include <QtQuick1/private/qdeclarativestate_p.h>
61 #include <QtQuick1/private/qdeclarativetransitionmanager_p_p.h>
62 #include <QtQuick1/private/qdeclarativestateoperations_p.h>
64 #include <QtCore/QObject>
65 #include <QtCore/QString>
66 #include <QtCore/QTimer>
71 class QDeclarative1BasePositionerPrivate : public QDeclarative1ImplicitSizeItemPrivate, public QDeclarativeItemChangeListener
73 Q_DECLARE_PUBLIC(QDeclarative1BasePositioner)
76 QDeclarative1BasePositionerPrivate()
77 : spacing(0), type(QDeclarative1BasePositioner::None)
78 , moveTransition(0), addTransition(0), queuedPositioning(false)
79 , doingPositioning(false), anchorConflict(false), layoutDirection(Qt::LeftToRight)
83 void init(QDeclarative1BasePositioner::PositionerType at)
90 QDeclarative1BasePositioner::PositionerType type;
91 QDeclarative1Transition *moveTransition;
92 QDeclarative1Transition *addTransition;
93 QDeclarative1StateOperation::ActionList addActions;
94 QDeclarative1StateOperation::ActionList moveActions;
95 QDeclarative1TransitionManager addTransitionManager;
96 QDeclarative1TransitionManager moveTransitionManager;
98 void watchChanges(QGraphicsObject *other);
99 void unwatchChanges(QGraphicsObject* other);
100 bool queuedPositioning : 1;
101 bool doingPositioning : 1;
102 bool anchorConflict : 1;
104 Qt::LayoutDirection layoutDirection;
107 void schedulePositioning()
109 Q_Q(QDeclarative1BasePositioner);
110 if(!queuedPositioning){
111 QTimer::singleShot(0,q,SLOT(prePositioning()));
112 queuedPositioning = true;
116 void mirrorChange() {
117 Q_Q(QDeclarative1BasePositioner);
118 if (type != QDeclarative1BasePositioner::Vertical)
121 bool isLeftToRight() const {
122 if (type == QDeclarative1BasePositioner::Vertical)
125 return effectiveLayoutMirror ? layoutDirection == Qt::RightToLeft : layoutDirection == Qt::LeftToRight;
128 virtual void itemSiblingOrderChanged(QDeclarativeItem* other)
131 //Delay is due to many children often being reordered at once
132 //And we only want to reposition them all once
133 schedulePositioning();
136 void itemGeometryChanged(QDeclarativeItem *, const QRectF &newGeometry, const QRectF &oldGeometry)
138 Q_Q(QDeclarative1BasePositioner);
139 if (newGeometry.size() != oldGeometry.size())
143 virtual void itemVisibilityChanged(QDeclarativeItem *)
145 schedulePositioning();
147 virtual void itemOpacityChanged(QDeclarativeItem *)
149 Q_Q(QDeclarative1BasePositioner);
153 void itemDestroyed(QDeclarativeItem *item)
155 Q_Q(QDeclarative1BasePositioner);
156 q->positionedItems.removeOne(QDeclarative1BasePositioner::PositionedItem(item));
159 static Qt::LayoutDirection getLayoutDirection(const QDeclarative1BasePositioner *positioner)
161 return positioner->d_func()->layoutDirection;
164 static Qt::LayoutDirection getEffectiveLayoutDirection(const QDeclarative1BasePositioner *positioner)
166 if (positioner->d_func()->effectiveLayoutMirror)
167 return positioner->d_func()->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft;
169 return positioner->d_func()->layoutDirection;