OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / propertyeditor / basiclayouts.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 (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 #ifndef BASICLAYOUTS_H
34 #define BASICLAYOUTS_H
35
36 #include <qlayoutobject.h>
37 #include <QHBoxLayout>
38
39
40 QT_BEGIN_HEADER
41
42 QT_BEGIN_NAMESPACE
43
44 QT_MODULE(Declarative)
45 class QBoxLayoutObject : public QLayoutObject
46 {
47     Q_OBJECT
48
49     Q_PROPERTY(QDeclarativeListProperty<QWidget> children READ children)
50
51     Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin)
52     Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin)
53     Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin)
54     Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin)
55     Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
56
57     Q_CLASSINFO("DefaultProperty", "children")
58 public:
59     QBoxLayoutObject(QObject *parent=0);
60     explicit QBoxLayoutObject(QBoxLayout *, QObject *parent=0);
61     virtual QLayout *layout() const;
62
63     QDeclarativeListProperty<QWidget> children() {
64         return QDeclarativeListProperty<QWidget>(this, 0, children_append, 0, 0, children_clear);
65     }
66
67 private:
68     friend class WidgetList;
69     void addWidget(QWidget *);
70     void clearWidget();
71
72     static void children_append(QDeclarativeListProperty<QWidget> *property, QWidget *widget) {
73         static_cast<QBoxLayoutObject*>(property->object)->addWidget(widget);
74     }
75
76     static void children_clear(QDeclarativeListProperty<QWidget> *property) {
77         static_cast<QBoxLayoutObject*>(property->object)->clearWidget();
78     }
79
80     void getMargins()
81     {
82         _layout->getContentsMargins(&mLeft, &mTop, &mRight, &mBottom);
83     }
84
85     void setMargins()
86     {
87         _layout->setContentsMargins(mLeft, mTop, mRight, mBottom);
88     }
89
90     int topMargin()
91     {
92         getMargins();
93         return mTop;
94     }
95
96     void setTopMargin(int margin)
97     {
98         getMargins();
99         mTop = margin;
100         setMargins();
101     }
102
103     int bottomMargin()
104     {
105         getMargins();
106         return mBottom;
107     }
108
109     void setBottomMargin(int margin)
110     {
111         getMargins();
112         mBottom = margin;
113         setMargins();
114     }
115
116     int leftMargin()
117     {
118         getMargins();
119         return mLeft;
120     }
121
122     void setLeftMargin(int margin)
123     {
124         getMargins();
125         mLeft = margin;
126         setMargins();
127     }
128
129     int rightMargin()
130     {
131         getMargins();
132         return mRight;
133     }
134
135     void setRightMargin(int margin)
136     {
137         getMargins();
138         mRight = margin;
139         setMargins();
140     }
141
142     int spacing() const
143     {
144         return _layout->spacing();
145     }
146
147     void setSpacing(int spacing)
148     {
149         _layout->setSpacing(spacing);
150     }
151
152     QBoxLayout *_layout;
153
154     int mTop, mLeft, mBottom, mRight;
155
156 };
157
158 class QHBoxLayoutObject : public QBoxLayoutObject
159 {
160 Q_OBJECT
161 public:
162     QHBoxLayoutObject(QObject *parent=0);
163 };
164
165 class QVBoxLayoutObject : public QBoxLayoutObject
166 {
167 Q_OBJECT
168 public:
169     QVBoxLayoutObject(QObject *parent=0);
170 };
171
172 QT_END_NAMESPACE
173
174 QML_DECLARE_TYPE(QBoxLayoutObject)
175 QML_DECLARE_TYPE(QHBoxLayoutObject)
176 QML_DECLARE_TYPE(QVBoxLayoutObject)
177
178
179 class BasicLayouts {
180 public:
181     static void registerDeclarativeTypes();
182 };
183
184 QT_END_HEADER
185
186 #endif // BASICLAYOUTS_H