1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEANCHORS_P_H
43 #define QDECLARATIVEANCHORS_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 "private/qdeclarativeanchors_p.h"
57 #include "private/qdeclarativeitemchangelistener_p.h"
58 #include <private/qobject_p.h>
62 class QDeclarativeAnchorLine
65 QDeclarativeAnchorLine() : item(0), anchorLine(Invalid) {}
76 Horizontal_Mask = Left | Right | HCenter,
77 Vertical_Mask = Top | Bottom | VCenter | Baseline
80 QGraphicsObject *item;
81 AnchorLine anchorLine;
84 inline bool operator==(const QDeclarativeAnchorLine& a, const QDeclarativeAnchorLine& b)
86 return a.item == b.item && a.anchorLine == b.anchorLine;
89 class QDeclarativeAnchorsPrivate : public QObjectPrivate, public QDeclarativeItemChangeListener
91 Q_DECLARE_PUBLIC(QDeclarativeAnchors)
93 QDeclarativeAnchorsPrivate(QGraphicsObject *i)
94 : componentComplete(true), updatingMe(false), updatingHorizontalAnchor(0),
95 updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0),
96 centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
97 margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)
101 void clearItem(QGraphicsObject *);
103 void addDepend(QGraphicsObject *);
104 void remDepend(QGraphicsObject *);
105 bool isItemComplete() const;
107 bool componentComplete:1;
109 uint updatingHorizontalAnchor:2;
110 uint updatingVerticalAnchor:2;
112 uint updatingCenterIn:2;
114 void setItemHeight(qreal);
115 void setItemWidth(qreal);
116 void setItemX(qreal);
117 void setItemY(qreal);
118 void setItemPos(const QPointF &);
119 void setItemSize(const QSizeF &);
121 void updateOnComplete();
124 // QDeclarativeItemGeometryListener interface
125 void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &);
126 void _q_widgetDestroyed(QObject *);
127 void _q_widgetGeometryChanged();
128 QDeclarativeAnchorsPrivate *anchorPrivate() { return this; }
130 bool checkHValid() const;
131 bool checkVValid() const;
132 bool checkHAnchorValid(QDeclarativeAnchorLine anchor) const;
133 bool checkVAnchorValid(QDeclarativeAnchorLine anchor) const;
134 bool calcStretch(const QDeclarativeAnchorLine &edge1, const QDeclarativeAnchorLine &edge2, qreal offset1, qreal offset2, QDeclarativeAnchorLine::AnchorLine line, qreal &stretch);
136 bool isMirrored() const;
137 void updateHorizontalAnchors();
138 void updateVerticalAnchors();
140 void centerInChanged();
142 QGraphicsObject *item;
143 QDeclarativeAnchors::Anchors usedAnchors;
145 QGraphicsObject *fill;
146 QGraphicsObject *centerIn;
148 QDeclarativeAnchorLine left;
149 QDeclarativeAnchorLine right;
150 QDeclarativeAnchorLine top;
151 QDeclarativeAnchorLine bottom;
152 QDeclarativeAnchorLine vCenter;
153 QDeclarativeAnchorLine hCenter;
154 QDeclarativeAnchorLine baseline;
163 qreal baselineOffset;
168 Q_DECLARE_METATYPE(QDeclarativeAnchorLine)