Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsganchors_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 QSGANCHORS_P_P_H
44 #define QSGANCHORS_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 "qsganchors_p.h"
58 #include "qsgitemchangelistener_p.h"
59 #include <private/qobject_p.h>
60
61 QT_BEGIN_NAMESPACE
62
63 class QSGAnchorLine
64 {
65 public:
66     QSGAnchorLine() : 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     QSGItem *item;
82     AnchorLine anchorLine;
83 };
84
85 inline bool operator==(const QSGAnchorLine& a, const QSGAnchorLine& b)
86 {
87     return a.item == b.item && a.anchorLine == b.anchorLine;
88 }
89
90 class QSGAnchorsPrivate : public QObjectPrivate, public QSGItemChangeListener
91 {
92     Q_DECLARE_PUBLIC(QSGAnchors)
93 public:
94     QSGAnchorsPrivate(QSGItem *i)
95       : componentComplete(true), updatingMe(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(QSGItem *);
103
104     void addDepend(QSGItem *);
105     void remDepend(QSGItem *);
106     bool isItemComplete() const;
107
108     bool componentComplete:1;
109     bool updatingMe:1;
110     uint updatingHorizontalAnchor:2;
111     uint updatingVerticalAnchor:2;
112     uint updatingFill:2;
113     uint updatingCenterIn:2;
114
115     void setItemHeight(qreal);
116     void setItemWidth(qreal);
117     void setItemX(qreal);
118     void setItemY(qreal);
119     void setItemPos(const QPointF &);
120     void setItemSize(const QSizeF &);
121
122     void updateOnComplete();
123     void updateMe();
124
125     // QSGItemGeometryListener interface
126     void itemGeometryChanged(QSGItem *, const QRectF &, const QRectF &);
127     QSGAnchorsPrivate *anchorPrivate() { return this; }
128
129     bool checkHValid() const;
130     bool checkVValid() const;
131     bool checkHAnchorValid(QSGAnchorLine anchor) const;
132     bool checkVAnchorValid(QSGAnchorLine anchor) const;
133     bool calcStretch(const QSGAnchorLine &edge1, const QSGAnchorLine &edge2, qreal offset1, qreal offset2, QSGAnchorLine::AnchorLine line, qreal &stretch);
134
135     bool isMirrored() const;
136     void updateHorizontalAnchors();
137     void updateVerticalAnchors();
138     void fillChanged();
139     void centerInChanged();
140
141     QSGItem *item;
142     QSGAnchors::Anchors usedAnchors;
143
144     QSGItem *fill;
145     QSGItem *centerIn;
146
147     QSGAnchorLine left;
148     QSGAnchorLine right;
149     QSGAnchorLine top;
150     QSGAnchorLine bottom;
151     QSGAnchorLine vCenter;
152     QSGAnchorLine hCenter;
153     QSGAnchorLine baseline;
154
155     qreal leftMargin;
156     qreal rightMargin;
157     qreal topMargin;
158     qreal bottomMargin;
159     qreal margins;
160     qreal vCenterOffset;
161     qreal hCenterOffset;
162     qreal baselineOffset;
163
164     static inline QSGAnchorsPrivate *get(QSGAnchors *o) {
165         return static_cast<QSGAnchorsPrivate *>(QObjectPrivate::get(o));
166     }
167 };
168
169 QT_END_NAMESPACE
170
171 Q_DECLARE_METATYPE(QSGAnchorLine)
172
173 #endif