c6417455778d096db7f07a8e947686ad6b673bd7
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickanchors_p_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKANCHORS_P_P_H
43 #define QQUICKANCHORS_P_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 "qquickanchors_p.h"
57 #include "qquickitemchangelistener_p.h"
58 #include <private/qobject_p.h>
59
60 QT_BEGIN_NAMESPACE
61
62 class QQuickAnchorLine
63 {
64 public:
65     enum AnchorLine {
66         Invalid = 0x0,
67         Left = 0x01,
68         Right = 0x02,
69         Top = 0x04,
70         Bottom = 0x08,
71         HCenter = 0x10,
72         VCenter = 0x20,
73         Baseline = 0x40,
74         Horizontal_Mask = Left | Right | HCenter,
75         Vertical_Mask = Top | Bottom | VCenter | Baseline
76     };
77
78     QQuickAnchorLine() : item(0), anchorLine(Invalid) {}
79     QQuickAnchorLine(QQuickItem *i, AnchorLine l) : item(i), anchorLine(l) {}
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), centerAligned(true),
96         leftMarginExplicit(false), rightMarginExplicit(false), topMarginExplicit(false),
97         bottomMarginExplicit(false), updatingHorizontalAnchor(0),
98         updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0),
99         centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
100         margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)
101
102     {
103     }
104
105     void clearItem(QQuickItem *);
106
107     int calculateDependency(QQuickItem *);
108     void addDepend(QQuickItem *);
109     void remDepend(QQuickItem *);
110     bool isItemComplete() const;
111
112     bool componentComplete:1;
113     bool updatingMe:1;
114     bool inDestructor:1;
115     bool centerAligned:1;
116     bool leftMarginExplicit : 1;
117     bool rightMarginExplicit : 1;
118     bool topMarginExplicit : 1;
119     bool bottomMarginExplicit : 1;
120     uint updatingHorizontalAnchor:2;
121     uint updatingVerticalAnchor:2;
122     uint updatingFill:2;
123     uint updatingCenterIn:2;
124
125     void setItemHeight(qreal);
126     void setItemWidth(qreal);
127     void setItemX(qreal);
128     void setItemY(qreal);
129     void setItemPos(const QPointF &);
130     void setItemSize(const QSizeF &);
131
132     void update();
133     void updateOnComplete();
134     void updateMe();
135
136     // QQuickItemGeometryListener interface
137     void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
138     QQuickAnchorsPrivate *anchorPrivate() { return this; }
139
140     bool checkHValid() const;
141     bool checkVValid() const;
142     bool checkHAnchorValid(QQuickAnchorLine anchor) const;
143     bool checkVAnchorValid(QQuickAnchorLine anchor) const;
144     bool calcStretch(const QQuickAnchorLine &edge1, const QQuickAnchorLine &edge2, qreal offset1, qreal offset2, QQuickAnchorLine::AnchorLine line, qreal &stretch);
145
146     bool isMirrored() const;
147     void updateHorizontalAnchors();
148     void updateVerticalAnchors();
149     void fillChanged();
150     void centerInChanged();
151
152     QQuickItem *item;
153     QQuickAnchors::Anchors usedAnchors;
154
155     QQuickItem *fill;
156     QQuickItem *centerIn;
157
158     QQuickAnchorLine left;
159     QQuickAnchorLine right;
160     QQuickAnchorLine top;
161     QQuickAnchorLine bottom;
162     QQuickAnchorLine vCenter;
163     QQuickAnchorLine hCenter;
164     QQuickAnchorLine baseline;
165
166     qreal leftMargin;
167     qreal rightMargin;
168     qreal topMargin;
169     qreal bottomMargin;
170     qreal margins;
171     qreal vCenterOffset;
172     qreal hCenterOffset;
173     qreal baselineOffset;
174
175
176     static inline QQuickAnchorsPrivate *get(QQuickAnchors *o) {
177         return static_cast<QQuickAnchorsPrivate *>(QObjectPrivate::get(o));
178     }
179 };
180
181 QT_END_NAMESPACE
182
183 Q_DECLARE_METATYPE(QQuickAnchorLine)
184
185 #endif