1
/***************************************************************************
2
* Copyright 2011 Marco Martin <mart@kde.org> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18
***************************************************************************/
20
#include "declarativeitemcontainer_p.h"
24
DeclarativeItemContainer::DeclarativeItemContainer(QGraphicsItem *parent)
25
: QGraphicsWidget(parent)
29
DeclarativeItemContainer::~DeclarativeItemContainer()
33
void DeclarativeItemContainer::setDeclarativeItem(QDeclarativeItem *item, bool reparent)
35
if (m_declarativeItem) {
36
disconnect(m_declarativeItem.data(), 0, this, 0);
38
m_declarativeItem = item;
40
static_cast<QGraphicsItem *>(item)->setParentItem(this);
42
setMinimumWidth(item->implicitWidth());
43
setMinimumHeight(item->implicitHeight());
44
resize(item->width(), item->height());
45
connect(m_declarativeItem.data(), SIGNAL(widthChanged()), this, SLOT(widthChanged()));
46
connect(m_declarativeItem.data(), SIGNAL(heightChanged()), this, SLOT(heightChanged()));
49
QDeclarativeItem *DeclarativeItemContainer::declarativeItem() const
51
return m_declarativeItem.data();
54
void DeclarativeItemContainer::resizeEvent(QGraphicsSceneResizeEvent *event)
56
if (m_declarativeItem) {
57
m_declarativeItem.data()->setProperty("width", event->newSize().width());
58
m_declarativeItem.data()->setProperty("height", event->newSize().height());
62
void DeclarativeItemContainer::mousePressEvent(QGraphicsSceneMouseEvent *event)
67
void DeclarativeItemContainer::widthChanged()
69
if (!m_declarativeItem) {
73
QSizeF newSize(size());
74
newSize.setWidth(m_declarativeItem.data()->width());
78
void DeclarativeItemContainer::heightChanged()
80
if (!m_declarativeItem) {
84
QSizeF newSize(size());
85
newSize.setHeight(m_declarativeItem.data()->height());
89
#include "declarativeitemcontainer_p.moc"