~ubuntu-branches/ubuntu/quantal/kde-runtime/quantal

« back to all changes in this revision

Viewing changes to plasma/scriptengines/javascript/declarative/declarativeitemcontainer.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-06-03 21:50:00 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120603215000-vn7oarsq0ynrydj5
Tags: upstream-4.8.80
Import upstream version 4.8.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright 2011 Marco Martin <mart@kde.org>                            *
 
3
 *                                                                         *
 
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.                                   *
 
8
 *                                                                         *
 
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.                          *
 
13
 *                                                                         *
 
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
 ***************************************************************************/
 
19
 
 
20
#include "declarativeitemcontainer_p.h"
 
21
 
 
22
#include <KDebug>
 
23
 
 
24
DeclarativeItemContainer::DeclarativeItemContainer(QGraphicsItem *parent)
 
25
    : QGraphicsWidget(parent)
 
26
{
 
27
}
 
28
 
 
29
DeclarativeItemContainer::~DeclarativeItemContainer()
 
30
{
 
31
}
 
32
 
 
33
void DeclarativeItemContainer::setDeclarativeItem(QDeclarativeItem *item, bool reparent)
 
34
{
 
35
    if (m_declarativeItem) {
 
36
        disconnect(m_declarativeItem.data(), 0, this, 0);
 
37
    }
 
38
    m_declarativeItem = item;
 
39
    if (reparent) {
 
40
        static_cast<QGraphicsItem *>(item)->setParentItem(this);
 
41
    }
 
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()));
 
47
}
 
48
 
 
49
QDeclarativeItem *DeclarativeItemContainer::declarativeItem() const
 
50
{
 
51
    return m_declarativeItem.data();
 
52
}
 
53
 
 
54
void DeclarativeItemContainer::resizeEvent(QGraphicsSceneResizeEvent *event)
 
55
{
 
56
    if (m_declarativeItem) {
 
57
        m_declarativeItem.data()->setProperty("width", event->newSize().width());
 
58
        m_declarativeItem.data()->setProperty("height", event->newSize().height());
 
59
    }
 
60
}
 
61
 
 
62
void DeclarativeItemContainer::mousePressEvent(QGraphicsSceneMouseEvent *event)
 
63
{
 
64
    event->ignore();
 
65
}
 
66
 
 
67
void DeclarativeItemContainer::widthChanged()
 
68
{
 
69
    if (!m_declarativeItem) {
 
70
        return;
 
71
    }
 
72
 
 
73
    QSizeF newSize(size());
 
74
    newSize.setWidth(m_declarativeItem.data()->width());
 
75
    resize(newSize);
 
76
}
 
77
 
 
78
void DeclarativeItemContainer::heightChanged()
 
79
{
 
80
    if (!m_declarativeItem) {
 
81
        return;
 
82
    }
 
83
 
 
84
    QSizeF newSize(size());
 
85
    newSize.setHeight(m_declarativeItem.data()->height());
 
86
    resize(newSize);
 
87
}
 
88
 
 
89
#include "declarativeitemcontainer_p.moc"