From dd9445d8858bbe895bbc8598c304390b746c2083 Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Sat, 18 Oct 2008 21:30:02 +0000 Subject: [PATCH] Added svgwidget. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=873133 --- CMakeLists.txt | 3 ++ includes/SvgWidget | 1 + widgets/svgwidget.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++ widgets/svgwidget.h | 58 ++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 includes/SvgWidget create mode 100644 widgets/svgwidget.cpp create mode 100644 widgets/svgwidget.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1964f1672..eccfd6388 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ set(plasma_LIB_SRCS widgets/scrollbar.cpp widgets/signalplotter.cpp widgets/slider.cpp + widgets/svgwidget.cpp widgets/tabbar.cpp widgets/treeview.cpp widgets/textedit.cpp @@ -194,6 +195,7 @@ install(FILES widgets/scrollbar.h widgets/signalplotter.h widgets/slider.h + widgets/svgwidget.h widgets/tabbar.h widgets/treeview.h widgets/textedit.h @@ -255,6 +257,7 @@ includes/ServiceJob includes/SignalPlotter includes/Slider includes/Svg +includes/SvgWidget includes/TabBar includes/TextEdit includes/ToolTipManager diff --git a/includes/SvgWidget b/includes/SvgWidget new file mode 100644 index 000000000..1c0f47bee --- /dev/null +++ b/includes/SvgWidget @@ -0,0 +1 @@ +#include "../../plasma/widgets/svgwidget.h" diff --git a/widgets/svgwidget.cpp b/widgets/svgwidget.cpp new file mode 100644 index 000000000..62c769b22 --- /dev/null +++ b/widgets/svgwidget.cpp @@ -0,0 +1,89 @@ +/* + * Copyright 2008 by Davide Bettio + * + * 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 "svgwidget.h" + +#include + +#include + +namespace Plasma +{ + class SvgWidgetPrivate + { + public: + SvgWidgetPrivate(Svg *s, const QString &element) + : svg(s), elementID(element) + { + } + + Svg *svg; + QString elementID; + }; + + SvgWidget::SvgWidget( QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent, wFlags), + d(new SvgWidgetPrivate(0, QString())) + { + } + + SvgWidget::SvgWidget(Svg *svg, const QString &elementID, QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent, wFlags), + d(new SvgWidgetPrivate(svg, elementID)) + { + } + + SvgWidget::~SvgWidget() + { + delete d; + } + + void SvgWidget::setSvg(Svg *svg) + { + d->svg = svg; + } + + Svg *SvgWidget::svg() const + { + return d->svg; + } + + void SvgWidget::setElementID(const QString &elementID) + { + d->elementID = elementID; + } + + QString SvgWidget::elementID() const + { + return d->elementID; + } + + void SvgWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + Q_UNUSED(option); + Q_UNUSED(widget); + + if (d->svg){ + d->svg->paint(painter, boundingRect(), d->elementID); + } + } + +} // Plasma namespace + +#include "svgwidget.moc" diff --git a/widgets/svgwidget.h b/widgets/svgwidget.h new file mode 100644 index 000000000..191aab72a --- /dev/null +++ b/widgets/svgwidget.h @@ -0,0 +1,58 @@ +/* + * Copyright 2008 by Davide Bettio + * + * 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. + */ + +#ifndef PLASMA_GRAPHICSSVGITEM_H +#define PLASMA_GRAPHICSSVGITEM_H + +#include +#include + +#include + +#include + +namespace Plasma +{ + + class Svg; + class SvgWidgetPrivate; + + class PLASMA_EXPORT SvgWidget : public QGraphicsWidget +{ + public: + SvgWidget ( QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0 ); + SvgWidget ( Svg *svg, const QString & elementID = QString(), QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0 ); + virtual ~SvgWidget(); + + void setSvg(Svg *svg); + Svg *svg() const; + + void setElementID(const QString &elementID); + QString elementID() const; + + protected: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + + private: + SvgWidgetPrivate * const d; +}; + +} // Plasma namespace + +#endif // multiple inclusion guard