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 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
41 ****************************************************************************/
43 #ifndef QSGPOSITIONERS_P_P_H
44 #define QSGPOSITIONERS_P_P_H
50 // This file is not part of the Qt API. It exists purely as an
51 // implementation detail. This header file may change from version to
52 // version without notice, or even be removed.
57 #include "qsgpositioners_p.h"
58 #include "qsgimplicitsizeitem_p_p.h"
60 #include <private/qdeclarativestate_p.h>
61 #include <private/qdeclarativetransitionmanager_p_p.h>
62 #include <private/qdeclarativestateoperations_p.h>
64 #include <QtCore/qobject.h>
65 #include <QtCore/qstring.h>
66 #include <QtCore/qtimer.h>
70 class QSGBasePositionerPrivate : public QSGImplicitSizeItemPrivate, public QSGItemChangeListener
72 Q_DECLARE_PUBLIC(QSGBasePositioner)
75 QSGBasePositionerPrivate()
76 : spacing(0), type(QSGBasePositioner::None)
77 , moveTransition(0), addTransition(0), queuedPositioning(false)
78 , doingPositioning(false), anchorConflict(false), layoutDirection(Qt::LeftToRight)
82 void init(QSGBasePositioner::PositionerType at)
89 QSGBasePositioner::PositionerType type;
90 QDeclarativeTransition *moveTransition;
91 QDeclarativeTransition *addTransition;
92 QDeclarativeStateOperation::ActionList addActions;
93 QDeclarativeStateOperation::ActionList moveActions;
94 QDeclarativeTransitionManager addTransitionManager;
95 QDeclarativeTransitionManager moveTransitionManager;
97 void watchChanges(QSGItem *other);
98 void unwatchChanges(QSGItem* other);
99 bool queuedPositioning : 1;
100 bool doingPositioning : 1;
101 bool anchorConflict : 1;
103 Qt::LayoutDirection layoutDirection;
105 void schedulePositioning()
107 Q_Q(QSGBasePositioner);
108 if(!queuedPositioning){
109 QTimer::singleShot(0,q,SLOT(prePositioning()));
110 queuedPositioning = true;
114 void mirrorChange() {
115 Q_Q(QSGBasePositioner);
116 if (type != QSGBasePositioner::Vertical)
119 bool isLeftToRight() const {
120 if (type == QSGBasePositioner::Vertical)
123 return effectiveLayoutMirror ? layoutDirection == Qt::RightToLeft : layoutDirection == Qt::LeftToRight;
126 virtual void itemSiblingOrderChanged(QSGItem* other)
129 //Delay is due to many children often being reordered at once
130 //And we only want to reposition them all once
131 schedulePositioning();
134 void itemGeometryChanged(QSGItem *, const QRectF &newGeometry, const QRectF &oldGeometry)
136 Q_Q(QSGBasePositioner);
137 if (newGeometry.size() != oldGeometry.size())
141 virtual void itemVisibilityChanged(QSGItem *)
143 schedulePositioning();
145 virtual void itemOpacityChanged(QSGItem *)
147 Q_Q(QSGBasePositioner);
151 void itemDestroyed(QSGItem *item)
153 Q_Q(QSGBasePositioner);
154 q->positionedItems.removeOne(QSGBasePositioner::PositionedItem(item));
157 static Qt::LayoutDirection getLayoutDirection(const QSGBasePositioner *positioner)
159 return positioner->d_func()->layoutDirection;
162 static Qt::LayoutDirection getEffectiveLayoutDirection(const QSGBasePositioner *positioner)
164 if (positioner->d_func()->effectiveLayoutMirror)
165 return positioner->d_func()->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft;
167 return positioner->d_func()->layoutDirection;
173 #endif // QSGPOSITIONERS_P_P_H