OSDN Git Service

f26cf1d57f949dafb37239814075d3437c0c4ebb
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / propertyeditor / qmlanchorbindingproxy.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 QmlAnchorBindingProxy_h
35 #define QmlAnchorBindingProxy_h
36
37 #include <QObject>
38 #include <modelnode.h>
39 #include <nodeinstanceview.h>
40 #include <QRectF>
41 #include <qmlitemnode.h>
42
43 namespace QmlDesigner {
44
45 class NodeInstanceView;
46
47 namespace Internal {
48
49 class QmlAnchorBindingProxy : public QObject
50 {
51     Q_OBJECT
52
53     Q_PROPERTY(bool topAnchored READ topAnchored WRITE setTopAnchor NOTIFY topAnchorChanged)
54     Q_PROPERTY(bool bottomAnchored READ bottomAnchored WRITE setBottomAnchor NOTIFY bottomAnchorChanged)
55     Q_PROPERTY(bool leftAnchored READ leftAnchored WRITE setLeftAnchor NOTIFY leftAnchorChanged)
56     Q_PROPERTY(bool rightAnchored READ rightAnchored WRITE setRightAnchor NOTIFY rightAnchorChanged)
57     Q_PROPERTY(bool hasParent READ hasParent NOTIFY parentChanged)
58
59     Q_PROPERTY(QVariant topTarget READ topTarget WRITE setTopTarget NOTIFY topTargetChanged)
60     Q_PROPERTY(QVariant bottomTarget READ bottomTarget WRITE setBottomTarget NOTIFY bottomTargetChanged)
61     Q_PROPERTY(QVariant leftTarget READ leftTarget WRITE setLeftTarget NOTIFY leftTargetChanged)
62     Q_PROPERTY(QVariant rightTarget READ rightTarget WRITE setRightTarget NOTIFY rightTargetChanged)
63
64     Q_PROPERTY(QVariant verticalTarget READ verticalTarget WRITE setVerticalTarget NOTIFY verticalTargetChanged)
65     Q_PROPERTY(QVariant horizontalTarget READ horizontalTarget WRITE setHorizontalTarget NOTIFY horizontalTargetChanged)
66
67     Q_PROPERTY(bool hasAnchors READ hasAnchors NOTIFY anchorsChanged)
68     Q_PROPERTY(bool isFilled READ isFilled NOTIFY anchorsChanged)
69
70     Q_PROPERTY(bool horizontalCentered READ horizontalCentered WRITE setHorizontalCentered NOTIFY centeredHChanged)
71     Q_PROPERTY(bool verticalCentered READ verticalCentered WRITE setVerticalCentered NOTIFY centeredVChanged)
72     Q_PROPERTY(QVariant itemNode READ itemNode NOTIFY itemNodeChanged)
73
74 public:
75     //only enable if node has parent
76
77     QmlAnchorBindingProxy(QObject *parent = 0);
78     ~QmlAnchorBindingProxy();
79
80     void setup(const QmlItemNode &itemNode);
81     void invalidate(const QmlItemNode &itemNode);
82
83     bool topAnchored();
84     bool bottomAnchored();
85     bool leftAnchored();
86     bool rightAnchored();
87
88     bool hasParent();
89     bool isFilled();
90
91     void removeTopAnchor();
92     void removeBottomAnchor();
93     void removeLeftAnchor();
94     void removeRightAnchor();
95     bool hasAnchors();
96
97     bool horizontalCentered();
98     bool verticalCentered();
99     QVariant itemNode() const { return QVariant::fromValue(m_fxItemNode.modelNode()); }
100
101     QVariant topTarget() const { return QVariant::fromValue(m_topTarget.modelNode()); }
102     QVariant bottomTarget() const { return QVariant::fromValue(m_bottomTarget.modelNode()); }
103     QVariant leftTarget() const { return QVariant::fromValue(m_leftTarget.modelNode()); }
104     QVariant rightTarget() const { return QVariant::fromValue(m_rightTarget.modelNode()); }
105
106     QVariant verticalTarget() const { return QVariant::fromValue(m_verticalTarget.modelNode()); }
107     QVariant horizontalTarget() const { return QVariant::fromValue(m_horizontalTarget.modelNode()); }
108
109 public:
110     void setTopTarget(const QVariant &target);
111     void setBottomTarget(const QVariant &target);
112     void setLeftTarget(const QVariant &target);
113     void setRightTarget(const QVariant &target);
114     void setVerticalTarget(const QVariant &target);
115     void setHorizontalTarget(const QVariant &target);
116
117
118 public slots:
119     void resetLayout();
120     void fill();
121     void setTopAnchor(bool anchor =true);
122     void setBottomAnchor(bool anchor = true);
123     void setLeftAnchor(bool anchor = true);
124     void setRightAnchor(bool anchor = true);
125
126     void setVerticalCentered(bool centered = true);
127     void setHorizontalCentered(bool centered = true);
128
129 signals:
130     void parentChanged();
131
132     void topAnchorChanged();
133     void bottomAnchorChanged();
134     void leftAnchorChanged();
135     void rightAnchorChanged();
136     void centeredVChanged();
137     void centeredHChanged();
138     void anchorsChanged();
139     void itemNodeChanged();
140
141     void topTargetChanged();
142     void bottomTargetChanged();
143     void leftTargetChanged();
144     void rightTargetChanged();
145
146     void verticalTargetChanged();
147     void horizontalTargetChanged();
148
149 private:
150
151     void calcTopMargin();
152     void calcBottomMargin();
153     void calcLeftMargin();
154     void calcRightMargin();
155
156     QmlItemNode m_fxItemNode;
157
158     QRectF parentBoundingBox();
159
160     QRectF boundingBox(QmlItemNode node);
161
162     QRectF transformedBoundingBox();
163
164     QmlItemNode m_topTarget;
165     QmlItemNode m_bottomTarget;
166     QmlItemNode m_leftTarget;
167     QmlItemNode m_rightTarget;
168
169     QmlItemNode m_verticalTarget;
170     QmlItemNode m_horizontalTarget;
171
172     bool m_locked;
173 };
174
175 } // namespace Internal
176 } // namespace QmlDesigner
177
178
179 #endif //QmlAnchorBindingProxy
180