2010-10-12 21:51:57 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Marco Martin <mart@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "svgitem_p.h"
|
|
|
|
|
|
|
|
#include <QtGui/QPainter>
|
|
|
|
|
|
|
|
#include "kdebug.h"
|
|
|
|
#include "plasma/svg.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
SvgItem::SvgItem(QDeclarativeItem *parent)
|
|
|
|
: QDeclarativeItem(parent)
|
|
|
|
{
|
|
|
|
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
2010-12-06 19:42:31 +01:00
|
|
|
|
2010-10-12 21:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SvgItem::~SvgItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-05 21:22:47 +01:00
|
|
|
void SvgItem::setElementId(const QString &elementID)
|
2010-10-12 21:51:57 +02:00
|
|
|
{
|
2010-11-05 21:22:47 +01:00
|
|
|
m_elementID = elementID;
|
2010-10-12 21:51:57 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2010-11-05 21:22:47 +01:00
|
|
|
QString SvgItem::elementId() const
|
2010-10-12 21:51:57 +02:00
|
|
|
{
|
2010-11-05 21:22:47 +01:00
|
|
|
return m_elementID;
|
2010-10-12 21:51:57 +02:00
|
|
|
}
|
|
|
|
|
2010-11-05 21:22:47 +01:00
|
|
|
void SvgItem::setSvg(Plasma::Svg *svg)
|
2010-10-12 21:51:57 +02:00
|
|
|
{
|
2010-11-05 21:22:47 +01:00
|
|
|
if (m_svg) {
|
|
|
|
disconnect(m_svg.data(), 0, this, 0);
|
|
|
|
}
|
|
|
|
m_svg = svg;
|
|
|
|
connect(svg, SIGNAL(repaintNeeded()), this, SLOT(update()));
|
2010-10-12 21:51:57 +02:00
|
|
|
}
|
|
|
|
|
2010-11-05 21:22:47 +01:00
|
|
|
Plasma::Svg *SvgItem::svg() const
|
2010-10-12 21:51:57 +02:00
|
|
|
{
|
2010-11-05 21:22:47 +01:00
|
|
|
return m_svg.data();
|
2010-10-12 21:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(option);
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
|
2010-11-05 21:22:47 +01:00
|
|
|
if (!m_svg) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//setContainsMultipleImages has to be done there since m_frameSvg can be shared with somebody else
|
|
|
|
m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty());
|
|
|
|
m_svg.data()->paint(painter, boundingRect(), m_elementID);
|
2010-10-12 21:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "svgitem_p.moc"
|