1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 //#include "nodeanchors.h"
36 //#include <modelnode.h>
38 //#include "internalnode_p.h"
39 //#include "internalnodeanchors.h"
40 //#include "internalnodestate.h"
41 //#include "invalidargumentexception.h"
43 //using namespace QmlDesigner::Internal;
45 //namespace QmlDesigner {
48 //\class QmlDesigner::NodeAnchors
50 //\brief NodeAnchors is a value holder for an anchor
53 //NodeAnchors::NodeAnchors(const NodeState &nodeState):
54 // m_internalNode(nodeState.m_internalNode),
55 // m_internalNodeState(nodeState.m_internalNodeState),
56 // m_model(nodeState.m_model)
60 //NodeAnchors::~NodeAnchors()
64 //NodeAnchors::NodeAnchors(const NodeAnchors &other)
65 // :m_internalNode(other.m_internalNode),
66 // m_model(other.m_model)
71 //NodeAnchors::NodeAnchors(const Internal::InternalNodeStatePointer &internalNodeState, Model *model):
72 // m_internalNode(internalNodeState->modelNode()),
73 // m_internalNodeState(internalNodeState),
78 //NodeAnchors &NodeAnchors::operator=(const NodeAnchors &other)
80 // m_internalNode = other.m_internalNode;
81 // m_internalNodeState = other.m_internalNodeState;
82 // m_model = other.m_model;
87 //ModelNode NodeAnchors::modelNode() const
89 // return ModelNode(m_internalNode, m_model.data());
92 //bool NodeAnchors::isValid() const
94 // return m_internalNode->isValid()
95 // && m_internalNodeState->isValid() &&
99 //NodeState NodeAnchors::nodeState() const
101 // return NodeState(m_internalNodeState, m_internalNode, m_model.data());
104 //void NodeAnchors::setAnchor(AnchorLine::Type sourceAnchorLineType,
105 // const ModelNode &targetModelNode,
106 // AnchorLine::Type targetAnchorLineType)
108 // Q_ASSERT(m_internalNode->isValid());
109 // Q_ASSERT(m_internalNodeState->isValid());
110 // Q_ASSERT(modelNode().isValid());
112 // m_model->setAnchor(AnchorLine(nodeState(), sourceAnchorLineType),
113 // AnchorLine(targetModelNode.baseNodeState(), targetAnchorLineType));
116 //bool NodeAnchors::canAnchor(AnchorLine::Type sourceAnchorLineType,
117 // const ModelNode & targetModelNode,
118 // AnchorLine::Type targetAnchorLineType) const
120 // if (modelNode() == targetModelNode)
123 // return InternalNodeAnchors(m_internalNodeState).canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), targetAnchorLineType);
126 //bool NodeAnchors::canAnchor(const ModelNode & targetModelNode) const
128 // if (modelNode() == targetModelNode)
131 // if (possibleAnchorLines(AnchorLine::Left, targetModelNode) != AnchorLine::NoAnchor)
133 // else if (possibleAnchorLines(AnchorLine::Top, targetModelNode) != AnchorLine::NoAnchor)
135 // else if (possibleAnchorLines(AnchorLine::Right, targetModelNode) != AnchorLine::NoAnchor)
137 // else if (possibleAnchorLines(AnchorLine::Bottom, targetModelNode) != AnchorLine::NoAnchor)
139 // else if (possibleAnchorLines(AnchorLine::HorizontalCenter, targetModelNode) != AnchorLine::NoAnchor)
142 // return possibleAnchorLines(AnchorLine::VerticalCenter, targetModelNode) != AnchorLine::NoAnchor;
145 //AnchorLine::Type NodeAnchors::possibleAnchorLines(AnchorLine::Type sourceAnchorLineType,
146 // const ModelNode & targetModelNode) const
148 // if (modelNode() == targetModelNode)
149 // return AnchorLine::NoAnchor;
151 // int anchorTypes = AnchorLine::NoAnchor;
152 // const InternalNodeAnchors anchors(m_internalNodeState);
154 // if (sourceAnchorLineType & AnchorLine::HorizontalMask) {
155 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::Left))
156 // anchorTypes |= AnchorLine::Left;
157 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::Right))
158 // anchorTypes |= AnchorLine::Right;
159 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::HorizontalCenter))
160 // anchorTypes |= AnchorLine::HorizontalCenter;
161 // } else if (sourceAnchorLineType & AnchorLine::VerticalMask) {
162 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::Top))
163 // anchorTypes |= AnchorLine::Top;
164 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::Bottom))
165 // anchorTypes |= AnchorLine::Bottom;
166 // if (anchors.canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), AnchorLine::VerticalCenter))
167 // anchorTypes |= AnchorLine::VerticalCenter;
170 // return (AnchorLine::Type) anchorTypes;
173 //AnchorLine NodeAnchors::localAnchor(AnchorLine::Type anchorLineType) const
175 // return InternalNodeAnchors(m_internalNodeState).anchor(anchorLineType);
178 //AnchorLine NodeAnchors::anchor(AnchorLine::Type anchorLineType) const
180 // Internal::InternalNodeState::Pointer statePointer(m_internalNodeState);
181 // AnchorLine anchorLine = InternalNodeAnchors(statePointer).anchor(anchorLineType);
183 // while (!anchorLine.isValid() && statePointer->hasParentState()) {
184 // statePointer = statePointer->parentState();
185 // anchorLine = InternalNodeAnchors(statePointer).anchor(anchorLineType);
188 // return anchorLine;
191 //bool NodeAnchors::hasAnchor(AnchorLine::Type sourceAnchorLineType) const
193 // Internal::InternalNodeState::Pointer statePointer(m_internalNodeState);
194 // InternalNodeAnchors internalNodeAnchors(statePointer);
195 // while (!internalNodeAnchors.hasAnchor(sourceAnchorLineType) &&
196 // statePointer->hasParentState()) {
197 // statePointer = statePointer->parentState();
198 // internalNodeAnchors = InternalNodeAnchors(statePointer);
201 // return internalNodeAnchors.hasAnchor(sourceAnchorLineType);
204 //void NodeAnchors::removeAnchor(AnchorLine::Type sourceAnchorLineType)
206 // if (hasLocalAnchor(sourceAnchorLineType))
207 // m_model->removeAnchor(AnchorLine(nodeState(), sourceAnchorLineType));
210 //void NodeAnchors::removeMargins()
212 // removeMargin(AnchorLine::Left);
213 // removeMargin(AnchorLine::Right);
214 // removeMargin(AnchorLine::Top);
215 // removeMargin(AnchorLine::Bottom);
216 // removeMargin(AnchorLine::HorizontalCenter);
217 // removeMargin(AnchorLine::VerticalCenter);
218 // removeMargin(AnchorLine::Baseline);
221 //void NodeAnchors::removeAnchors()
223 // removeAnchor(AnchorLine::Left);
224 // removeAnchor(AnchorLine::Right);
225 // removeAnchor(AnchorLine::Top);
226 // removeAnchor(AnchorLine::Bottom);
227 // removeAnchor(AnchorLine::HorizontalCenter);
228 // removeAnchor(AnchorLine::VerticalCenter);
229 // removeAnchor(AnchorLine::Baseline);
232 //bool NodeAnchors::hasLocalAnchor(AnchorLine::Type sourceAnchorLineType) const
234 // return InternalNodeAnchors(m_internalNodeState).hasAnchor(sourceAnchorLineType);
237 //bool NodeAnchors::hasLocalAnchors() const
239 // return hasLocalAnchor(AnchorLine::Top) ||
240 // hasLocalAnchor(AnchorLine::Bottom) ||
241 // hasLocalAnchor(AnchorLine::Left) ||
242 // hasLocalAnchor(AnchorLine::Right) ||
243 // hasLocalAnchor(AnchorLine::VerticalCenter) ||
244 // hasLocalAnchor(AnchorLine::HorizontalCenter) ||
245 // hasLocalAnchor(AnchorLine::Baseline);
248 //bool NodeAnchors::hasAnchors() const
250 // return hasAnchor(AnchorLine::Top) ||
251 // hasAnchor(AnchorLine::Bottom) ||
252 // hasAnchor(AnchorLine::Left) ||
253 // hasAnchor(AnchorLine::Right) ||
254 // hasAnchor(AnchorLine::VerticalCenter) ||
255 // hasAnchor(AnchorLine::HorizontalCenter) ||
256 // hasAnchor(AnchorLine::Baseline);
259 //void NodeAnchors::setMargin(AnchorLine::Type sourceAnchorLineType, double margin) const
261 // m_model->setAnchorMargin(AnchorLine(nodeState(), sourceAnchorLineType), margin);
264 //bool NodeAnchors::hasMargin(AnchorLine::Type sourceAnchorLineType) const
266 // return InternalNodeAnchors(m_internalNodeState).hasMargin(sourceAnchorLineType);
269 //double NodeAnchors::localMargin(AnchorLine::Type sourceAnchorLineType) const
271 // return InternalNodeAnchors(m_internalNodeState).margin(sourceAnchorLineType);
274 //double NodeAnchors::margin(AnchorLine::Type sourceAnchorLineType) const
276 // Internal::InternalNodeState::Pointer statePointer(m_internalNodeState);
277 // InternalNodeAnchors internalNodeAnchors(statePointer);
278 // while (!internalNodeAnchors.hasMargin(sourceAnchorLineType) &&
279 // statePointer->hasParentState()) {
280 // statePointer = statePointer->parentState();
281 // internalNodeAnchors = InternalNodeAnchors(statePointer);
284 // return internalNodeAnchors.margin(sourceAnchorLineType);
287 //void NodeAnchors::removeMargin(AnchorLine::Type sourceAnchorLineType)
289 // m_model->removeAnchorMargin(AnchorLine(nodeState(), sourceAnchorLineType));
293 //QDebug operator<<(QDebug debug, const NodeAnchors &anchors)
295 // debug.nospace() << "NodeAnchors(";
296 // if (anchors.isValid()) {
297 // if (anchors.hasAnchor(AnchorLine::Top))
299 // if (anchors.hasMargin(AnchorLine::Top))
300 // debug.nospace() << "(" << anchors.margin(AnchorLine::Top) << ")";
301 // if (anchors.hasAnchor(AnchorLine::Bottom))
302 // debug << "bottom";
303 // if (anchors.hasMargin(AnchorLine::Bottom))
304 // debug.nospace() << "(" << anchors.margin(AnchorLine::Bottom) << ")";
305 // if (anchors.hasAnchor(AnchorLine::Left))
307 // if (anchors.hasMargin(AnchorLine::Left))
308 // debug.nospace() << "(" << anchors.margin(AnchorLine::Left) << ")";
309 // if (anchors.hasAnchor(AnchorLine::Right))
311 // if (anchors.hasMargin(AnchorLine::Right))
312 // debug.nospace() << "(" << anchors.margin(AnchorLine::Right) << ")";
313 // if (anchors.hasAnchor(AnchorLine::VerticalCenter))
314 // debug << "verticalCenter";
315 // if (anchors.hasMargin(AnchorLine::VerticalCenter))
316 // debug.nospace() << "(" << anchors.margin(AnchorLine::VerticalCenter) << ")";
317 // if (anchors.hasAnchor(AnchorLine::HorizontalCenter))
318 // debug << "horizontalCenter";
319 // if (anchors.hasMargin(AnchorLine::HorizontalCenter))
320 // debug.nospace() << "(" << anchors.margin(AnchorLine::HorizontalCenter) << ")";
321 // if (anchors.hasAnchor(AnchorLine::Baseline))
322 // debug << "baseline";
323 // if (anchors.hasMargin(AnchorLine::Baseline))
324 // debug.nospace() << "(" << anchors.margin(AnchorLine::Baseline) << ")";
326 // debug.nospace() << "invalid";
329 // debug.nospace() << ")";
331 // return debug.space();
334 //QTextStream& operator<<(QTextStream &stream, const NodeAnchors &anchors)
336 // stream << "NodeAnchors(";
337 // if (anchors.isValid()) {
338 // if (anchors.hasAnchor(AnchorLine::Top))
340 // if (anchors.hasMargin(AnchorLine::Top))
341 // stream << "(" << anchors.margin(AnchorLine::Top) << ")";
342 // if (anchors.hasAnchor(AnchorLine::Bottom))
343 // stream << "bottom";
344 // if (anchors.hasMargin(AnchorLine::Bottom))
345 // stream << "(" << anchors.margin(AnchorLine::Bottom) << ")";
346 // if (anchors.hasAnchor(AnchorLine::Left))
348 // if (anchors.hasMargin(AnchorLine::Left))
349 // stream << "(" << anchors.margin(AnchorLine::Left) << ")";
350 // if (anchors.hasAnchor(AnchorLine::Right))
351 // stream << "right";
352 // if (anchors.hasMargin(AnchorLine::Right))
353 // stream << "(" << anchors.margin(AnchorLine::Right) << ")";
354 // if (anchors.hasAnchor(AnchorLine::VerticalCenter))
355 // stream << "verticalCenter";
356 // if (anchors.hasMargin(AnchorLine::VerticalCenter))
357 // stream << "(" << anchors.margin(AnchorLine::VerticalCenter) << ")";
358 // if (anchors.hasAnchor(AnchorLine::HorizontalCenter))
359 // stream << "horizontalCenter";
360 // if (anchors.hasMargin(AnchorLine::HorizontalCenter))
361 // stream << "(" << anchors.margin(AnchorLine::HorizontalCenter) << ")";
362 // if (anchors.hasAnchor(AnchorLine::Baseline))
363 // stream << "baseline";
364 // if (anchors.hasMargin(AnchorLine::Baseline))
365 // stream << "(" << anchors.margin(AnchorLine::Baseline) << ")";
367 // stream << "invalid";
376 //} // namespace QmlDesigner