1 /* This file is part of the KDE project
2 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
20 #include "widgetrectitem.h"
21 #include <QtCore/QEvent>
22 #include <QtGui/QGraphicsProxyWidget>
25 //X WidgetRectItem::WidgetRectItem(QGraphicsItem *parent)
26 //X : QGraphicsRectItem(parent)
30 WidgetRectItem::WidgetRectItem(const QPointF
&pos
, const QColor
&brush
, const QString
&title
)
33 setFlag(QGraphicsItem::ItemIsMovable
);
38 WidgetRectItem::~WidgetRectItem()
42 void WidgetRectItem::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
, QWidget
*widget
)
45 QGraphicsProxyWidget
*proxy
= 0;
46 if (childItems().size() == 1) {
47 proxy
= qgraphicsitem_cast
<QGraphicsProxyWidget
*>(
48 childItems().first());
49 QWidget
*w
= proxy
->widget();
54 if (!size
.isValid()) {
55 size
= childrenBoundingRect().size();
57 setRect(0.0, 0.0, size
.width() + 32.0, size
.height() + 30.0);
58 QGraphicsRectItem::paint(painter
, option
, widget
);
59 painter
->drawText(rect(), Qt::AlignTop
| Qt::AlignHCenter
, m_title
);
61 if (size
!= m_lastSize
) {
66 foreach (PathItem
*p
, m_paths
) {
67 p
->endPointMoved(this);
71 //X const QPoint mapped = m_view->mapFromScene(pos());
72 //X const QRectF frameGeometry(mapped.x() + 18, mapped.y() + 17, size.width(), size.height());
73 //X if (childrenBoundingRect() != frameGeometry) {
74 //X PathItem *pathItem = qgraphicsitem_cast<PathItem *>(parentItem());
76 //X pathItem->updateChildrenPositions();
81 QVariant
WidgetRectItem::itemChange(GraphicsItemChange change
, const QVariant
&value
)
83 if (change
== ItemPositionHasChanged
) {
84 foreach (PathItem
*p
, m_paths
) {
85 p
->endPointMoved(this);
88 return QGraphicsItem::itemChange(change
, value
);
91 void WidgetRectItem::addPath(PathItem
*p
)
96 void WidgetRectItem::removePath(PathItem
*p
)