6de5001359fe0dcb8eaf0bfc43e3768d4b358d30
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativepositioners_p_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVELAYOUTS_P_H
43 #define QDECLARATIVELAYOUTS_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
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.
52 //
53 // We mean it.
54 //
55
56 #include "private/qdeclarativepositioners_p.h"
57
58 #include "private/qdeclarativeimplicitsizeitem_p_p.h"
59
60 #include <QtQuick1/private/qdeclarativestate_p.h>
61 #include <QtQuick1/private/qdeclarativetransitionmanager_p_p.h>
62 #include <QtQuick1/private/qdeclarativestateoperations_p.h>
63
64 #include <QtCore/QObject>
65 #include <QtCore/QString>
66 #include <QtCore/QTimer>
67 #include <QDebug>
68
69 QT_BEGIN_NAMESPACE
70
71 class QDeclarative1BasePositionerPrivate : public QDeclarative1ImplicitSizeItemPrivate, public QDeclarativeItemChangeListener
72 {
73     Q_DECLARE_PUBLIC(QDeclarative1BasePositioner)
74
75 public:
76     QDeclarative1BasePositionerPrivate()
77         : spacing(0), type(QDeclarative1BasePositioner::None)
78         , moveTransition(0), addTransition(0), queuedPositioning(false)
79         , doingPositioning(false), anchorConflict(false), layoutDirection(Qt::LeftToRight)
80     {
81     }
82
83     void init(QDeclarative1BasePositioner::PositionerType at)
84     {
85         type = at;
86     }
87
88     int spacing;
89
90     QDeclarative1BasePositioner::PositionerType type;
91     QDeclarative1Transition *moveTransition;
92     QDeclarative1Transition *addTransition;
93     QDeclarative1StateOperation::ActionList addActions;
94     QDeclarative1StateOperation::ActionList moveActions;
95     QDeclarative1TransitionManager addTransitionManager;
96     QDeclarative1TransitionManager moveTransitionManager;
97
98     void watchChanges(QGraphicsObject *other);
99     void unwatchChanges(QGraphicsObject* other);
100     bool queuedPositioning : 1;
101     bool doingPositioning : 1;
102     bool anchorConflict : 1;
103
104     Qt::LayoutDirection layoutDirection;
105
106
107     void schedulePositioning()
108     {
109         Q_Q(QDeclarative1BasePositioner);
110         if(!queuedPositioning){
111             QTimer::singleShot(0,q,SLOT(prePositioning()));
112             queuedPositioning = true;
113         }
114     }
115
116     void mirrorChange() {
117         Q_Q(QDeclarative1BasePositioner);
118         if (type != QDeclarative1BasePositioner::Vertical)
119             q->prePositioning();
120     }
121     bool isLeftToRight() const {
122         if (type == QDeclarative1BasePositioner::Vertical)
123             return true;
124         else
125             return effectiveLayoutMirror ? layoutDirection == Qt::RightToLeft : layoutDirection == Qt::LeftToRight;
126     }
127
128     virtual void itemSiblingOrderChanged(QDeclarativeItem* other)
129     {
130         Q_UNUSED(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();
134     }
135
136     void itemGeometryChanged(QDeclarativeItem *, const QRectF &newGeometry, const QRectF &oldGeometry)
137     {
138         Q_Q(QDeclarative1BasePositioner);
139         if (newGeometry.size() != oldGeometry.size())
140             q->prePositioning();
141     }
142
143     virtual void itemVisibilityChanged(QDeclarativeItem *)
144     {
145         schedulePositioning();
146     }
147     virtual void itemOpacityChanged(QDeclarativeItem *)
148     {
149         Q_Q(QDeclarative1BasePositioner);
150         q->prePositioning();
151     }
152
153     void itemDestroyed(QDeclarativeItem *item)
154     {
155         Q_Q(QDeclarative1BasePositioner);
156         q->positionedItems.removeOne(QDeclarative1BasePositioner::PositionedItem(item));
157     }
158
159     static Qt::LayoutDirection getLayoutDirection(const QDeclarative1BasePositioner *positioner)
160     {
161         return positioner->d_func()->layoutDirection;
162     }
163
164     static Qt::LayoutDirection getEffectiveLayoutDirection(const QDeclarative1BasePositioner *positioner)
165     {
166         if (positioner->d_func()->effectiveLayoutMirror)
167             return positioner->d_func()->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft;
168         else
169             return positioner->d_func()->layoutDirection;
170     }
171 };
172
173 QT_END_NAMESPACE
174 #endif