Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgpositioners_p_p.h
1 // Commit: 2c7cab4172f1acc86fd49345a2847417e162f2c3
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
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
15 ** this package.
16 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGPOSITIONERS_P_P_H
44 #define QSGPOSITIONERS_P_P_H
45
46 //
47 //  W A R N I N G
48 //  -------------
49 //
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.
53 //
54 // We mean it.
55 //
56
57 #include "qsgpositioners_p.h"
58 #include "qsgimplicitsizeitem_p_p.h"
59
60 #include <private/qdeclarativestate_p.h>
61 #include <private/qdeclarativetransitionmanager_p_p.h>
62 #include <private/qdeclarativestateoperations_p.h>
63
64 #include <QtCore/qobject.h>
65 #include <QtCore/qstring.h>
66 #include <QtCore/qtimer.h>
67
68 QT_BEGIN_NAMESPACE
69
70 class QSGBasePositionerPrivate : public QSGImplicitSizeItemPrivate, public QSGItemChangeListener
71 {
72     Q_DECLARE_PUBLIC(QSGBasePositioner)
73
74 public:
75     QSGBasePositionerPrivate()
76         : spacing(0), type(QSGBasePositioner::None)
77         , moveTransition(0), addTransition(0), queuedPositioning(false)
78         , doingPositioning(false), anchorConflict(false), layoutDirection(Qt::LeftToRight)
79     {
80     }
81
82     void init(QSGBasePositioner::PositionerType at)
83     {
84         type = at;
85     }
86
87     int spacing;
88
89     QSGBasePositioner::PositionerType type;
90     QDeclarativeTransition *moveTransition;
91     QDeclarativeTransition *addTransition;
92     QDeclarativeStateOperation::ActionList addActions;
93     QDeclarativeStateOperation::ActionList moveActions;
94     QDeclarativeTransitionManager addTransitionManager;
95     QDeclarativeTransitionManager moveTransitionManager;
96
97     void watchChanges(QSGItem *other);
98     void unwatchChanges(QSGItem* other);
99     bool queuedPositioning : 1;
100     bool doingPositioning : 1;
101     bool anchorConflict : 1;
102
103     Qt::LayoutDirection layoutDirection;
104
105     void schedulePositioning()
106     {
107         Q_Q(QSGBasePositioner);
108         if(!queuedPositioning){
109             QTimer::singleShot(0,q,SLOT(prePositioning()));
110             queuedPositioning = true;
111         }
112     }
113
114     void mirrorChange() {
115         Q_Q(QSGBasePositioner);
116         if (type != QSGBasePositioner::Vertical)
117             q->prePositioning();
118     }
119     bool isLeftToRight() const {
120         if (type == QSGBasePositioner::Vertical)
121             return true;
122         else
123             return effectiveLayoutMirror ? layoutDirection == Qt::RightToLeft : layoutDirection == Qt::LeftToRight;
124     }
125
126     virtual void itemSiblingOrderChanged(QSGItem* other)
127     {
128         Q_UNUSED(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();
132     }
133
134     void itemGeometryChanged(QSGItem *, const QRectF &newGeometry, const QRectF &oldGeometry)
135     {
136         Q_Q(QSGBasePositioner);
137         if (newGeometry.size() != oldGeometry.size())
138             q->prePositioning();
139     }
140
141     virtual void itemVisibilityChanged(QSGItem *)
142     {
143         schedulePositioning();
144     }
145     virtual void itemOpacityChanged(QSGItem *)
146     {
147         Q_Q(QSGBasePositioner);
148         q->prePositioning();
149     }
150
151     void itemDestroyed(QSGItem *item)
152     {
153         Q_Q(QSGBasePositioner);
154         q->positionedItems.removeOne(QSGBasePositioner::PositionedItem(item));
155     }
156
157     static Qt::LayoutDirection getLayoutDirection(const QSGBasePositioner *positioner)
158     {
159         return positioner->d_func()->layoutDirection;
160     }
161
162     static Qt::LayoutDirection getEffectiveLayoutDirection(const QSGBasePositioner *positioner)
163     {
164         if (positioner->d_func()->effectiveLayoutMirror)
165             return positioner->d_func()->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft;
166         else
167             return positioner->d_func()->layoutDirection;
168     }
169 };
170
171 QT_END_NAMESPACE
172
173 #endif // QSGPOSITIONERS_P_P_H