OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / propertyeditor / qproxylayoutitem.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 "qproxylayoutitem.h"
34 #include <QGraphicsWidget>
35
36 QT_BEGIN_NAMESPACE
37
38 QProxyLayoutItem::QProxyLayoutItem(QGraphicsLayoutItem *i)
39 : enabled(true), other(i)
40 {
41 }
42
43 void QProxyLayoutItem::setGeometry(const QRectF &r)
44 {
45     geometry = r;
46     if (enabled && other)
47         other->setGeometry(r);
48 }
49
50 QGraphicsLayoutItem *QProxyLayoutItem::item() const
51 {
52     return other;
53 }
54
55 void QProxyLayoutItem::setItem(QGraphicsLayoutItem *o)
56 {
57     if (other == o)
58         return;
59     other = o;
60     if (enabled && other)
61         other->setGeometry(geometry);
62
63     updateGeometry();
64     if (parentLayoutItem())
65         parentLayoutItem()->updateGeometry();
66 }
67
68 void QProxyLayoutItem::setEnabled(bool e)
69 {
70     if (e == enabled)
71         return;
72
73     enabled = e;
74     if (e && other)
75         other->setGeometry(geometry);
76 }
77
78 QSizeF QProxyLayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &c) const
79 {
80     struct Accessor : public QGraphicsLayoutItem
81     {
82         QSizeF getSizeHint(Qt::SizeHint which, const QSizeF &c) const
83         {
84             return sizeHint(which, c);
85         }
86     };
87
88     QSizeF rv;
89     if (other)
90         rv = static_cast<Accessor *>(other)->getSizeHint(which, c);
91     return rv;
92 }
93
94 QProxyLayout::QProxyLayout(QObject *parent)
95 : QObject(parent), proxy(0)
96 {
97 }
98
99 void QProxyLayout::setLayout(QGraphicsLayout *l)
100 {
101     proxy = l;
102     updateGeometry();
103     if (parentLayoutItem())
104         parentLayoutItem()->updateGeometry();
105 }
106
107 QGraphicsLayout *QProxyLayout::layout() const
108 {
109     return proxy;
110 }
111
112 void QProxyLayout::updateGeometry()
113 {
114     QGraphicsLayout::updateGeometry();
115 }
116
117 void QProxyLayout::setGeometry(const QRectF &g)
118 {
119     geometry = g;
120     if (proxy)
121         proxy->setGeometry(g);
122
123 }
124
125 int QProxyLayout::count() const
126 {
127     if (proxy)
128         return proxy->count();
129     else
130         return 0;
131 }
132
133 QGraphicsLayoutItem *QProxyLayout::itemAt(int idx) const
134 {
135     if (proxy)
136         return proxy->itemAt(idx);
137     else
138         return 0;
139 }
140
141 void QProxyLayout::removeAt(int idx)
142 {
143     if (proxy)
144         proxy->removeAt(idx);
145 }
146
147 QSizeF QProxyLayout::sizeHint(Qt::SizeHint which,
148                               const QSizeF &constraint) const
149 {
150     struct Accessor : public QGraphicsLayout
151     {
152         QSizeF getSizeHint(Qt::SizeHint which, const QSizeF &c) const
153         {
154             return sizeHint(which, c);
155         }
156     };
157
158     if (proxy)
159         return static_cast<Accessor *>(proxy)->getSizeHint(which, constraint);
160     else
161         return QSizeF();
162 }
163
164 void QProxyLayoutItem::registerDeclarativeTypes()
165 {
166     qmlRegisterType<QProxyLayoutItem>("Bauhaus",1,0,"LayoutItem");
167     qmlRegisterType<QProxyLayout>("Bauhaus",1,0,"ProxyLayout");
168 }
169
170 QT_END_NAMESPACE