dbd6bac9311a3e5d10fcc9940f651b2c536f99ff
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickanchors_p_p.h
1 // Commit: 2c7cab4172f1acc86fd49345a2847417e162f2c3
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: http://www.qt-project.org/
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKANCHORS_P_P_H
44 #define QQUICKANCHORS_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 "qquickanchors_p.h"
58 #include "qquickitemchangelistener_p.h"
59 #include <private/qobject_p.h>
60
61 QT_BEGIN_NAMESPACE
62
63 class QQuickAnchorLine
64 {
65 public:
66     QQuickAnchorLine() : item(0), anchorLine(Invalid) {}
67
68     enum AnchorLine {
69         Invalid = 0x0,
70         Left = 0x01,
71         Right = 0x02,
72         Top = 0x04,
73         Bottom = 0x08,
74         HCenter = 0x10,
75         VCenter = 0x20,
76         Baseline = 0x40,
77         Horizontal_Mask = Left | Right | HCenter,
78         Vertical_Mask = Top | Bottom | VCenter | Baseline
79     };
80
81     QQuickItem *item;
82     AnchorLine anchorLine;
83 };
84
85 inline bool operator==(const QQuickAnchorLine& a, const QQuickAnchorLine& b)
86 {
87     return a.item == b.item && a.anchorLine == b.anchorLine;
88 }
89
90 class QQuickAnchorsPrivate : public QObjectPrivate, public QQuickItemChangeListener
91 {
92     Q_DECLARE_PUBLIC(QQuickAnchors)
93 public:
94     QQuickAnchorsPrivate(QQuickItem *i)
95       : componentComplete(true), updatingMe(false), inDestructor(false), updatingHorizontalAnchor(0),
96         updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0),
97         centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
98         margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)
99     {
100     }
101
102     void clearItem(QQuickItem *);
103
104     int calculateDependency(QQuickItem *);
105     void addDepend(QQuickItem *);
106     void remDepend(QQuickItem *);
107     bool isItemComplete() const;
108
109     bool componentComplete:1;
110     bool updatingMe:1;
111     bool inDestructor:1;
112     uint updatingHorizontalAnchor:2;
113     uint updatingVerticalAnchor:2;
114     uint updatingFill:2;
115     uint updatingCenterIn:2;
116
117     void setItemHeight(qreal);
118     void setItemWidth(qreal);
119     void setItemX(qreal);
120     void setItemY(qreal);
121     void setItemPos(const QPointF &);
122     void setItemSize(const QSizeF &);
123
124     void update();
125     void updateOnComplete();
126     void updateMe();
127
128     // QQuickItemGeometryListener interface
129     void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
130     QQuickAnchorsPrivate *anchorPrivate() { return this; }
131
132     bool checkHValid() const;
133     bool checkVValid() const;
134     bool checkHAnchorValid(QQuickAnchorLine anchor) const;
135     bool checkVAnchorValid(QQuickAnchorLine anchor) const;
136     bool calcStretch(const QQuickAnchorLine &edge1, const QQuickAnchorLine &edge2, qreal offset1, qreal offset2, QQuickAnchorLine::AnchorLine line, qreal &stretch);
137
138     bool isMirrored() const;
139     void updateHorizontalAnchors();
140     void updateVerticalAnchors();
141     void fillChanged();
142     void centerInChanged();
143
144     QQuickItem *item;
145     QQuickAnchors::Anchors usedAnchors;
146
147     QQuickItem *fill;
148     QQuickItem *centerIn;
149
150     QQuickAnchorLine left;
151     QQuickAnchorLine right;
152     QQuickAnchorLine top;
153     QQuickAnchorLine bottom;
154     QQuickAnchorLine vCenter;
155     QQuickAnchorLine hCenter;
156     QQuickAnchorLine baseline;
157
158     qreal leftMargin;
159     qreal rightMargin;
160     qreal topMargin;
161     qreal bottomMargin;
162     qreal margins;
163     qreal vCenterOffset;
164     qreal hCenterOffset;
165     qreal baselineOffset;
166
167     static inline QQuickAnchorsPrivate *get(QQuickAnchors *o) {
168         return static_cast<QQuickAnchorsPrivate *>(QObjectPrivate::get(o));
169     }
170 };
171
172 QT_END_NAMESPACE
173
174 Q_DECLARE_METATYPE(QQuickAnchorLine)
175
176 #endif