OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / include / qmlanchors.h
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 #ifndef QmlAnchors_H
35 #define QmlAnchors_H
36
37 #include <corelib_global.h>
38 #include <qmlitemnode.h>
39
40
41 namespace QmlDesigner {
42
43 class CORESHARED_EXPORT AnchorLine
44 {
45 public:
46     enum Type {
47         Invalid = 0x0,
48         NoAnchor = Invalid,
49         Left = 0x01,
50         Right = 0x02,
51         Top = 0x04,
52         Bottom = 0x08,
53         HorizontalCenter = 0x10,
54         VerticalCenter = 0x20,
55         Baseline = 0x40,
56
57         Fill =  Left | Right | Top | Bottom,
58         Center = VerticalCenter | HorizontalCenter,
59         HorizontalMask = Left | Right | HorizontalCenter,
60         VerticalMask = Top | Bottom | VerticalCenter | Baseline,
61         AllMask = VerticalMask | HorizontalMask
62     };
63
64     AnchorLine() : m_qmlItemNode(QmlItemNode()), m_type(Invalid) {}
65     AnchorLine(const QmlItemNode &fxItemNode, Type type) : m_qmlItemNode(fxItemNode), m_type(type) {}
66     Type type() const { return m_type; }
67     bool isValid() const { return m_type != Invalid && m_qmlItemNode.isValid(); }
68
69     static bool isHorizontalAnchorLine(Type anchorline);
70     static bool isVerticalAnchorLine(Type anchorline);
71
72     QmlItemNode qmlItemNode() const;
73
74 private:
75     QmlItemNode m_qmlItemNode;
76     Type m_type;
77 };
78
79
80 class CORESHARED_EXPORT QmlAnchors
81 {
82 public:
83     QmlAnchors(const QmlItemNode &fxItemNode);
84
85     bool isValid() const;
86
87     void setAnchor(AnchorLine::Type sourceAnchorLineType,
88                    const QmlItemNode &targetModelNode,
89                    AnchorLine::Type targetAnchorLineType);
90     bool canAnchor(const QmlItemNode &targetModelNode) const;
91     AnchorLine::Type possibleAnchorLines(AnchorLine::Type sourceAnchorLineType,
92                                          const QmlItemNode &targetModelNode) const;
93     AnchorLine instanceAnchor(AnchorLine::Type sourceAnchorLineType) const;
94
95     void removeAnchor(AnchorLine::Type sourceAnchorLineType);
96     void removeAnchors();
97     bool instanceHasAnchor(AnchorLine::Type sourceAnchorLineType) const;
98     bool instanceHasAnchors() const;
99     void setMargin(AnchorLine::Type sourceAnchorLineType, double margin) const;
100     bool instanceHasMargin(AnchorLine::Type sourceAnchorLineType) const;
101     double instanceMargin(AnchorLine::Type sourceAnchorLineType) const;
102     void removeMargin(AnchorLine::Type sourceAnchorLineType);
103     void removeMargins();
104
105     void fill();
106     void centerIn();
107
108 protected:
109     QmlItemNode qmlItemNode() const;
110     void beautify();
111
112 private:
113     QmlItemNode m_qmlItemNode;
114 };
115
116 } //QmlDesigner
117
118 #endif // QmlAnchors_H