OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / model / nodeanchors.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 //#include "nodeanchors.h"
34 //
35 //#include <model.h>
36 //#include <modelnode.h>
37 //
38 //#include "internalnode_p.h"
39 //#include "internalnodeanchors.h"
40 //#include "internalnodestate.h"
41 //#include "invalidargumentexception.h"
42 //
43 //using namespace QmlDesigner::Internal;
44 //
45 //namespace QmlDesigner {
46 //
47 ///*!
48 //\class QmlDesigner::NodeAnchors
49 //\ingroup CoreModel
50 //\brief NodeAnchors is a value holder for an anchor
51 //*/
52 //
53 //NodeAnchors::NodeAnchors(const NodeState &nodeState):
54 //        m_internalNode(nodeState.m_internalNode),
55 //        m_internalNodeState(nodeState.m_internalNodeState),
56 //        m_model(nodeState.m_model)
57 //{
58 //}
59 //
60 //NodeAnchors::~NodeAnchors()
61 //{
62 //}
63 //
64 //NodeAnchors::NodeAnchors(const NodeAnchors &other)
65 //    :m_internalNode(other.m_internalNode),
66 //    m_model(other.m_model)
67 //{
68 //
69 //}
70 //
71 //NodeAnchors::NodeAnchors(const Internal::InternalNodeStatePointer &internalNodeState, Model *model):
72 //        m_internalNode(internalNodeState->modelNode()),
73 //        m_internalNodeState(internalNodeState),
74 //        m_model(model)
75 //{
76 //}
77 //
78 //NodeAnchors &NodeAnchors::operator=(const NodeAnchors &other)
79 //{
80 //    m_internalNode = other.m_internalNode;
81 //    m_internalNodeState = other.m_internalNodeState;
82 //    m_model = other.m_model;
83 //
84 //    return *this;
85 //}
86 //
87 //ModelNode NodeAnchors::modelNode() const
88 //{
89 //    return ModelNode(m_internalNode, m_model.data());
90 //}
91 //
92 //bool NodeAnchors::isValid() const
93 //{
94 //    return m_internalNode->isValid()
95 //            && m_internalNodeState->isValid() &&
96 //            m_model;
97 //}
98 //
99 //NodeState NodeAnchors::nodeState() const
100 //{
101 //    return NodeState(m_internalNodeState, m_internalNode, m_model.data());
102 //}
103 //
104 //void NodeAnchors::setAnchor(AnchorLine::Type sourceAnchorLineType,
105 //                const ModelNode &targetModelNode,
106 //                AnchorLine::Type targetAnchorLineType)
107 //{
108 //    Q_ASSERT(m_internalNode->isValid());
109 //    Q_ASSERT(m_internalNodeState->isValid());
110 //    Q_ASSERT(modelNode().isValid());
111 //
112 //    m_model->setAnchor(AnchorLine(nodeState(), sourceAnchorLineType),
113 //                       AnchorLine(targetModelNode.baseNodeState(), targetAnchorLineType));
114 //}
115 //
116 //bool NodeAnchors::canAnchor(AnchorLine::Type sourceAnchorLineType,
117 //                            const ModelNode & targetModelNode,
118 //                            AnchorLine::Type targetAnchorLineType) const
119 //{
120 //    if (modelNode() == targetModelNode)
121 //        return false;
122 //
123 //    return InternalNodeAnchors(m_internalNodeState).canAnchor(sourceAnchorLineType, targetModelNode.baseNodeState().internalNodeState(), targetAnchorLineType);
124 //}
125 //
126 //bool NodeAnchors::canAnchor(const ModelNode & targetModelNode) const
127 //{
128 //    if (modelNode() == targetModelNode)
129 //        return false;
130 //
131 //    if (possibleAnchorLines(AnchorLine::Left, targetModelNode) != AnchorLine::NoAnchor)
132 //        return true;
133 //    else if (possibleAnchorLines(AnchorLine::Top, targetModelNode) != AnchorLine::NoAnchor)
134 //        return true;
135 //    else if (possibleAnchorLines(AnchorLine::Right, targetModelNode) != AnchorLine::NoAnchor)
136 //        return true;
137 //    else if (possibleAnchorLines(AnchorLine::Bottom, targetModelNode) != AnchorLine::NoAnchor)
138 //        return true;
139 //    else if (possibleAnchorLines(AnchorLine::HorizontalCenter, targetModelNode) != AnchorLine::NoAnchor)
140 //        return true;
141 //    else
142 //        return possibleAnchorLines(AnchorLine::VerticalCenter, targetModelNode) != AnchorLine::NoAnchor;
143 //}
144 //
145 //AnchorLine::Type NodeAnchors::possibleAnchorLines(AnchorLine::Type sourceAnchorLineType,
146 //                                                  const ModelNode & targetModelNode) const
147 //{
148 //    if (modelNode() == targetModelNode)
149 //        return AnchorLine::NoAnchor;
150 //
151 //    int anchorTypes = AnchorLine::NoAnchor;
152 //    const InternalNodeAnchors anchors(m_internalNodeState);
153 //
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;
168 //    }
169 //
170 //    return (AnchorLine::Type) anchorTypes;
171 //}
172 //
173 //AnchorLine NodeAnchors::localAnchor(AnchorLine::Type anchorLineType) const
174 //{
175 //    return InternalNodeAnchors(m_internalNodeState).anchor(anchorLineType);
176 //}
177 //
178 //AnchorLine NodeAnchors::anchor(AnchorLine::Type anchorLineType) const
179 //{
180 //    Internal::InternalNodeState::Pointer statePointer(m_internalNodeState);
181 //    AnchorLine anchorLine = InternalNodeAnchors(statePointer).anchor(anchorLineType);
182 //
183 //    while (!anchorLine.isValid() && statePointer->hasParentState()) {
184 //        statePointer = statePointer->parentState();
185 //        anchorLine = InternalNodeAnchors(statePointer).anchor(anchorLineType);
186 //    }
187 //
188 //    return anchorLine;
189 //}
190 //
191 //bool NodeAnchors::hasAnchor(AnchorLine::Type sourceAnchorLineType) const
192 //{
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);
199 //    }
200 //
201 //    return internalNodeAnchors.hasAnchor(sourceAnchorLineType);
202 //}
203 //
204 //void NodeAnchors::removeAnchor(AnchorLine::Type sourceAnchorLineType)
205 //{
206 //    if (hasLocalAnchor(sourceAnchorLineType))
207 //        m_model->removeAnchor(AnchorLine(nodeState(), sourceAnchorLineType));
208 //}
209 //
210 //void NodeAnchors::removeMargins()
211 //{
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);
219 //}
220 //
221 //void NodeAnchors::removeAnchors()
222 //{
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);
230 //}
231 //
232 //bool NodeAnchors::hasLocalAnchor(AnchorLine::Type sourceAnchorLineType) const
233 //{
234 //    return InternalNodeAnchors(m_internalNodeState).hasAnchor(sourceAnchorLineType);
235 //}
236 //
237 //bool NodeAnchors::hasLocalAnchors() const
238 //{
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);
246 //}
247 //
248 //bool NodeAnchors::hasAnchors() const
249 //{
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);
257 //}
258 //
259 //void NodeAnchors::setMargin(AnchorLine::Type sourceAnchorLineType, double margin) const
260 //{
261 //    m_model->setAnchorMargin(AnchorLine(nodeState(), sourceAnchorLineType), margin);
262 //}
263 //
264 //bool NodeAnchors::hasMargin(AnchorLine::Type sourceAnchorLineType) const
265 //{
266 //    return InternalNodeAnchors(m_internalNodeState).hasMargin(sourceAnchorLineType);
267 //}
268 //
269 //double NodeAnchors::localMargin(AnchorLine::Type sourceAnchorLineType) const
270 //{
271 //    return InternalNodeAnchors(m_internalNodeState).margin(sourceAnchorLineType);
272 //}
273 //
274 //double NodeAnchors::margin(AnchorLine::Type sourceAnchorLineType) const
275 //{
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);
282 //    }
283 //
284 //    return internalNodeAnchors.margin(sourceAnchorLineType);
285 //}
286 //
287 //void NodeAnchors::removeMargin(AnchorLine::Type sourceAnchorLineType)
288 //{
289 //    m_model->removeAnchorMargin(AnchorLine(nodeState(), sourceAnchorLineType));
290 //
291 //}
292 //
293 //QDebug operator<<(QDebug debug, const NodeAnchors &anchors)
294 //{
295 //    debug.nospace() << "NodeAnchors(";
296 //    if (anchors.isValid()) {
297 //        if (anchors.hasAnchor(AnchorLine::Top))
298 //            debug << "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))
306 //            debug << "left";
307 //        if (anchors.hasMargin(AnchorLine::Left))
308 //            debug.nospace() << "(" << anchors.margin(AnchorLine::Left) << ")";
309 //        if (anchors.hasAnchor(AnchorLine::Right))
310 //            debug << "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) << ")";
325 //    } else {
326 //        debug.nospace() << "invalid";
327 //    }
328 //
329 //    debug.nospace() << ")";
330 //
331 //    return debug.space();
332 //}
333 //
334 //QTextStream& operator<<(QTextStream &stream, const NodeAnchors &anchors)
335 //{
336 //    stream << "NodeAnchors(";
337 //    if (anchors.isValid()) {
338 //        if (anchors.hasAnchor(AnchorLine::Top))
339 //            stream << "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))
347 //            stream << "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) << ")";
366 //    } else {
367 //        stream << "invalid";
368 //    }
369 //
370 //    stream << ")";
371 //
372 //    return stream;
373 //}
374 //
375 //
376 //} // namespace QmlDesigner