1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** 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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 //#include "nodeanchors.h"
37 //#include <modelnode.h>
39 //#include "internalnode_p.h"
40 //#include "internalnodeanchors.h"
41 //#include "internalnodestate.h"
42 //#include "invalidargumentexception.h"
44 //using namespace QmlDesigner::Internal;
46 //namespace QmlDesigner {
49 //\class QmlDesigner::NodeAnchors
51 //\brief NodeAnchors is a value holder for an anchor
54 //NodeAnchors::NodeAnchors(const NodeState &nodeState):
55 // m_internalNode(nodeState.m_internalNode),
56 // m_internalNodeState(nodeState.m_internalNodeState),
57 // m_model(nodeState.m_model)
61 //NodeAnchors::~NodeAnchors()
65 //NodeAnchors::NodeAnchors(const NodeAnchors &other)
66 // :m_internalNode(other.m_internalNode),
67 // m_model(other.m_model)
72 //NodeAnchors::NodeAnchors(const Internal::InternalNodeStatePointer &internalNodeState, Model *model):
73 // m_internalNode(internalNodeState->modelNode()),
74 // m_internalNodeState(internalNodeState),
79 //NodeAnchors &NodeAnchors::operator=(const NodeAnchors &other)
81 // m_internalNode = other.m_internalNode;
82 // m_internalNodeState = other.m_internalNodeState;
83 // m_model = other.m_model;
88 //ModelNode NodeAnchors::modelNode() const
90 // return ModelNode(m_internalNode, m_model.data());
93 //bool NodeAnchors::isValid() const
95 // return m_internalNode->isValid()
96 // && m_internalNodeState->isValid() &&
100 //NodeState NodeAnchors::nodeState() const
102 // return NodeState(m_internalNodeState, m_internalNode, m_model.data());
105 //void NodeAnchors::setAnchor(AnchorLine::Type sourceAnchorLineType,
106 // const ModelNode &targetModelNode,
107 // AnchorLine::Type targetAnchorLineType)
109 // Q_ASSERT(m_internalNode->isValid());
110 // Q_ASSERT(m_internalNodeState->isValid());
111 // Q_ASSERT(modelNode().isValid());
113 // m_model->setAnchor(AnchorLine(nodeState(), sourceAnchorLineType),
114 // AnchorLine(targetModelNode.baseNodeState(), targetAnchorLineType));
117 //bool NodeAnchors::canAnchor(AnchorLine::Type sourceAnchorLineType,
118 // const ModelNode & targetModelNode,
119 // AnchorLine::Type targetAnchorLineType) const
121 // if (modelNode() == targetModelNode)
124 // return InternalNodeAnchors(m_internalNodeState).canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), targetAnchorLineType);
127 //bool NodeAnchors::canAnchor(const ModelNode & targetModelNode) const
129 // if (modelNode() == targetModelNode)
132 // if (possibleAnchorLines(AnchorLine::Left, targetModelNode) != AnchorLine::NoAnchor)
134 // else if (possibleAnchorLines(AnchorLine::Top, targetModelNode) != AnchorLine::NoAnchor)
136 // else if (possibleAnchorLines(AnchorLine::Right, targetModelNode) != AnchorLine::NoAnchor)
138 // else if (possibleAnchorLines(AnchorLine::Bottom, targetModelNode) != AnchorLine::NoAnchor)
140 // else if (possibleAnchorLines(AnchorLine::HorizontalCenter, targetModelNode) != AnchorLine::NoAnchor)
143 // return possibleAnchorLines(AnchorLine::VerticalCenter, targetModelNode) != AnchorLine::NoAnchor;
146 //AnchorLine::Type NodeAnchors::possibleAnchorLines(AnchorLine::Type sourceAnchorLineType,
147 // const ModelNode & targetModelNode) const
149 // if (modelNode() == targetModelNode)
150 // return AnchorLine::NoAnchor;
152 // int anchorTypes = AnchorLine::NoAnchor;
153 // const InternalNodeAnchors anchors(m_internalNodeState);
155 // if (sourceAnchorLineType & AnchorLine::HorizontalMask) {
156 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::Left))
157 // anchorTypes |= AnchorLine::Left;
158 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::Right))
159 // anchorTypes |= AnchorLine::Right;
160 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::HorizontalCenter))
161 // anchorTypes |= AnchorLine::HorizontalCenter;
162 // } else if (sourceAnchorLineType & AnchorLine::VerticalMask) {
163 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::Top))
164 // anchorTypes |= AnchorLine::Top;
165 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::Bottom))
166 // anchorTypes |= AnchorLine::Bottom;
167 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::VerticalCenter))
168 // anchorTypes |= AnchorLine::VerticalCenter;
171 // return (AnchorLine::Type) anchorTypes;
174 //AnchorLine NodeAnchors::localAnchor(AnchorLine::Type anchorLineType) const
176 // return InternalNodeAnchors(m_internalNodeState).anchor(anchorLineType);
179 //AnchorLine NodeAnchors::anchor(AnchorLine::Type anchorLineType) const
181 // Internal::InternalNodeState::Pointer statePointer(m_internalNodeState);
182 // AnchorLine anchorLine = InternalNodeAnchors(statePointer).anchor(anchorLineType);
184 // while (!anchorLine.isValid() && statePointer->hasParentState()) {
185 // statePointer = statePointer->parentState();
186 // anchorLine = InternalNodeAnchors(statePointer).anchor(anchorLineType);
189 // return anchorLine;
192 //bool NodeAnchors::hasAnchor(AnchorLine::Type sourceAnchorLineType) const
194 // Internal::InternalNodeState::Pointer statePointer(m_internalNodeState);
195 // InternalNodeAnchors internalNodeAnchors(statePointer);
196 // while (!internalNodeAnchors.hasAnchor(sourceAnchorLineType) &&
197 // statePointer->hasParentState()) {
198 // statePointer = statePointer->parentState();
199 // internalNodeAnchors = InternalNodeAnchors(statePointer);
202 // return internalNodeAnchors.hasAnchor(sourceAnchorLineType);
205 //void NodeAnchors::removeAnchor(AnchorLine::Type sourceAnchorLineType)
207 // if (hasLocalAnchor(sourceAnchorLineType))
208 // m_model->removeAnchor(AnchorLine(nodeState(), sourceAnchorLineType));
211 //void NodeAnchors::removeMargins()
213 // removeMargin(AnchorLine::Left);
214 // removeMargin(AnchorLine::Right);
215 // removeMargin(AnchorLine::Top);
216 // removeMargin(AnchorLine::Bottom);
217 // removeMargin(AnchorLine::HorizontalCenter);
218 // removeMargin(AnchorLine::VerticalCenter);
219 // removeMargin(AnchorLine::Baseline);
222 //void NodeAnchors::removeAnchors()
224 // removeAnchor(AnchorLine::Left);
225 // removeAnchor(AnchorLine::Right);
226 // removeAnchor(AnchorLine::Top);
227 // removeAnchor(AnchorLine::Bottom);
228 // removeAnchor(AnchorLine::HorizontalCenter);
229 // removeAnchor(AnchorLine::VerticalCenter);
230 // removeAnchor(AnchorLine::Baseline);
233 //bool NodeAnchors::hasLocalAnchor(AnchorLine::Type sourceAnchorLineType) const
235 // return InternalNodeAnchors(m_internalNodeState).hasAnchor(sourceAnchorLineType);
238 //bool NodeAnchors::hasLocalAnchors() const
240 // return hasLocalAnchor(AnchorLine::Top) ||
241 // hasLocalAnchor(AnchorLine::Bottom) ||
242 // hasLocalAnchor(AnchorLine::Left) ||
243 // hasLocalAnchor(AnchorLine::Right) ||
244 // hasLocalAnchor(AnchorLine::VerticalCenter) ||
245 // hasLocalAnchor(AnchorLine::HorizontalCenter) ||
246 // hasLocalAnchor(AnchorLine::Baseline);
249 //bool NodeAnchors::hasAnchors() const
251 // return hasAnchor(AnchorLine::Top) ||
252 // hasAnchor(AnchorLine::Bottom) ||
253 // hasAnchor(AnchorLine::Left) ||
254 // hasAnchor(AnchorLine::Right) ||
255 // hasAnchor(AnchorLine::VerticalCenter) ||
256 // hasAnchor(AnchorLine::HorizontalCenter) ||
257 // hasAnchor(AnchorLine::Baseline);
260 //void NodeAnchors::setMargin(AnchorLine::Type sourceAnchorLineType, double margin) const
262 // m_model->setAnchorMargin(AnchorLine(nodeState(), sourceAnchorLineType), margin);
265 //bool NodeAnchors::hasMargin(AnchorLine::Type sourceAnchorLineType) const
267 // return InternalNodeAnchors(m_internalNodeState).hasMargin(sourceAnchorLineType);
270 //double NodeAnchors::localMargin(AnchorLine::Type sourceAnchorLineType) const
272 // return InternalNodeAnchors(m_internalNodeState).margin(sourceAnchorLineType);
275 //double NodeAnchors::margin(AnchorLine::Type sourceAnchorLineType) const
277 // Internal::InternalNodeState::Pointer statePointer(m_internalNodeState);
278 // InternalNodeAnchors internalNodeAnchors(statePointer);
279 // while (!internalNodeAnchors.hasMargin(sourceAnchorLineType) &&
280 // statePointer->hasParentState()) {
281 // statePointer = statePointer->parentState();
282 // internalNodeAnchors = InternalNodeAnchors(statePointer);
285 // return internalNodeAnchors.margin(sourceAnchorLineType);
288 //void NodeAnchors::removeMargin(AnchorLine::Type sourceAnchorLineType)
290 // m_model->removeAnchorMargin(AnchorLine(nodeState(), sourceAnchorLineType));
294 //QDebug operator<<(QDebug debug, const NodeAnchors &anchors)
296 // debug.nospace() << "NodeAnchors(";
297 // if (anchors.isValid()) {
298 // if (anchors.hasAnchor(AnchorLine::Top))
300 // if (anchors.hasMargin(AnchorLine::Top))
301 // debug.nospace() << "(" << anchors.margin(AnchorLine::Top) << ")";
302 // if (anchors.hasAnchor(AnchorLine::Bottom))
303 // debug << "bottom";
304 // if (anchors.hasMargin(AnchorLine::Bottom))
305 // debug.nospace() << "(" << anchors.margin(AnchorLine::Bottom) << ")";
306 // if (anchors.hasAnchor(AnchorLine::Left))
308 // if (anchors.hasMargin(AnchorLine::Left))
309 // debug.nospace() << "(" << anchors.margin(AnchorLine::Left) << ")";
310 // if (anchors.hasAnchor(AnchorLine::Right))
312 // if (anchors.hasMargin(AnchorLine::Right))
313 // debug.nospace() << "(" << anchors.margin(AnchorLine::Right) << ")";
314 // if (anchors.hasAnchor(AnchorLine::VerticalCenter))
315 // debug << "verticalCenter";
316 // if (anchors.hasMargin(AnchorLine::VerticalCenter))
317 // debug.nospace() << "(" << anchors.margin(AnchorLine::VerticalCenter) << ")";
318 // if (anchors.hasAnchor(AnchorLine::HorizontalCenter))
319 // debug << "horizontalCenter";
320 // if (anchors.hasMargin(AnchorLine::HorizontalCenter))
321 // debug.nospace() << "(" << anchors.margin(AnchorLine::HorizontalCenter) << ")";
322 // if (anchors.hasAnchor(AnchorLine::Baseline))
323 // debug << "baseline";
324 // if (anchors.hasMargin(AnchorLine::Baseline))
325 // debug.nospace() << "(" << anchors.margin(AnchorLine::Baseline) << ")";
327 // debug.nospace() << "invalid";
330 // debug.nospace() << ")";
332 // return debug.space();
335 //QTextStream& operator<<(QTextStream &stream, const NodeAnchors &anchors)
337 // stream << "NodeAnchors(";
338 // if (anchors.isValid()) {
339 // if (anchors.hasAnchor(AnchorLine::Top))
341 // if (anchors.hasMargin(AnchorLine::Top))
342 // stream << "(" << anchors.margin(AnchorLine::Top) << ")";
343 // if (anchors.hasAnchor(AnchorLine::Bottom))
344 // stream << "bottom";
345 // if (anchors.hasMargin(AnchorLine::Bottom))
346 // stream << "(" << anchors.margin(AnchorLine::Bottom) << ")";
347 // if (anchors.hasAnchor(AnchorLine::Left))
349 // if (anchors.hasMargin(AnchorLine::Left))
350 // stream << "(" << anchors.margin(AnchorLine::Left) << ")";
351 // if (anchors.hasAnchor(AnchorLine::Right))
352 // stream << "right";
353 // if (anchors.hasMargin(AnchorLine::Right))
354 // stream << "(" << anchors.margin(AnchorLine::Right) << ")";
355 // if (anchors.hasAnchor(AnchorLine::VerticalCenter))
356 // stream << "verticalCenter";
357 // if (anchors.hasMargin(AnchorLine::VerticalCenter))
358 // stream << "(" << anchors.margin(AnchorLine::VerticalCenter) << ")";
359 // if (anchors.hasAnchor(AnchorLine::HorizontalCenter))
360 // stream << "horizontalCenter";
361 // if (anchors.hasMargin(AnchorLine::HorizontalCenter))
362 // stream << "(" << anchors.margin(AnchorLine::HorizontalCenter) << ")";
363 // if (anchors.hasAnchor(AnchorLine::Baseline))
364 // stream << "baseline";
365 // if (anchors.hasMargin(AnchorLine::Baseline))
366 // stream << "(" << anchors.margin(AnchorLine::Baseline) << ")";
368 // stream << "invalid";
377 //} // namespace QmlDesigner