1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKANCHORS_P_P_H
43 #define QQUICKANCHORS_P_P_H
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.
56 #include "qquickanchors_p.h"
57 #include "qquickitemchangelistener_p.h"
58 #include <private/qobject_p.h>
62 class QQuickAnchorLine
74 Horizontal_Mask = Left | Right | HCenter,
75 Vertical_Mask = Top | Bottom | VCenter | Baseline
78 QQuickAnchorLine() : item(0), anchorLine(Invalid) {}
79 QQuickAnchorLine(QQuickItem *i, AnchorLine l) : item(i), anchorLine(l) {}
82 AnchorLine anchorLine;
85 inline bool operator==(const QQuickAnchorLine& a, const QQuickAnchorLine& b)
87 return a.item == b.item && a.anchorLine == b.anchorLine;
90 class QQuickAnchorsPrivate : public QObjectPrivate, public QQuickItemChangeListener
92 Q_DECLARE_PUBLIC(QQuickAnchors)
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)
105 void clearItem(QQuickItem *);
107 int calculateDependency(QQuickItem *);
108 void addDepend(QQuickItem *);
109 void remDepend(QQuickItem *);
110 bool isItemComplete() const;
112 bool componentComplete: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;
123 uint updatingCenterIn:2;
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 &);
133 void updateOnComplete();
136 // QQuickItemGeometryListener interface
137 void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
138 QQuickAnchorsPrivate *anchorPrivate() { return this; }
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);
146 bool isMirrored() const;
147 void updateHorizontalAnchors();
148 void updateVerticalAnchors();
150 void centerInChanged();
153 QQuickAnchors::Anchors usedAnchors;
156 QQuickItem *centerIn;
158 QQuickAnchorLine left;
159 QQuickAnchorLine right;
160 QQuickAnchorLine top;
161 QQuickAnchorLine bottom;
162 QQuickAnchorLine vCenter;
163 QQuickAnchorLine hCenter;
164 QQuickAnchorLine baseline;
173 qreal baselineOffset;
176 static inline QQuickAnchorsPrivate *get(QQuickAnchors *o) {
177 return static_cast<QQuickAnchorsPrivate *>(QObjectPrivate::get(o));
183 Q_DECLARE_METATYPE(QQuickAnchorLine)