OSDN Git Service

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