• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Plasma

svgwidget.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "svgwidget.h"
00021 
00022 #include <QtGui/QPainter>
00023 #include <QtGui/QGraphicsSceneMouseEvent>
00024 
00025 #include "kdebug.h"
00026 #include "svg.h"
00027 
00028 namespace Plasma
00029 {
00030 
00031 class SvgWidgetPrivate
00032 {
00033 public:
00034     SvgWidgetPrivate(SvgWidget *widget, Svg *s, const QString &element)
00035         : q(widget), svg(s), elementID(element)
00036     {
00037     }
00038 
00039     void svgChanged()
00040     {
00041         q->update();
00042     }
00043 
00044     SvgWidget *q;
00045     Svg *svg;
00046     QString elementID;
00047 };
00048 
00049 SvgWidget::SvgWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
00050     : QGraphicsWidget(parent, wFlags),
00051       d(new SvgWidgetPrivate(this, 0, QString()))
00052 {
00053 }
00054 
00055 SvgWidget::SvgWidget(Svg *svg, const QString &elementID, QGraphicsItem *parent, Qt::WindowFlags wFlags)
00056     : QGraphicsWidget(parent, wFlags),
00057       d(new SvgWidgetPrivate(this, svg, elementID))
00058 {
00059 }
00060 
00061 SvgWidget::~SvgWidget()
00062 {
00063     delete d;
00064 }
00065 
00066 void SvgWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
00067 {
00068     // we check for receivers so that SvgWidgets that aren't being used for events remain "click
00069     // transparent"
00070     if (receivers(SIGNAL(clicked(Qt::MouseButton)))) {
00071         event->accept();
00072     } else {
00073         QGraphicsWidget::mousePressEvent(event);
00074     }
00075 }
00076 
00077 void SvgWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
00078 {
00079     if (boundingRect().contains(event->pos())) {
00080         emit clicked(event->button());
00081     }
00082 }
00083 
00084 void SvgWidget::setSvg(Svg *svg)
00085 {
00086     if (d->svg) {
00087         disconnect(d->svg);
00088     }
00089 
00090     d->svg = svg;
00091 
00092     if (svg) {
00093         connect(svg, SIGNAL(repaintNeeded()), this, SLOT(svgChanged()));
00094     }
00095     update();
00096 }
00097 
00098 Svg *SvgWidget::svg() const
00099 {
00100     return d->svg;
00101 }
00102 
00103 void SvgWidget::setElementID(const QString &elementID)
00104 {
00105     if (d->svg) {
00106         d->svg->setContainsMultipleImages(!elementID.isNull());
00107     }
00108     d->elementID = elementID;
00109     update();
00110 }
00111 
00112 QString SvgWidget::elementID() const
00113 {
00114     return d->elementID;
00115 }
00116 
00117 void SvgWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00118 {
00119     Q_UNUSED(option);
00120     Q_UNUSED(widget);
00121 
00122     if (d->svg){
00123         d->svg->paint(painter, boundingRect(), d->elementID);
00124     }
00125 }
00126 
00127 QSizeF SvgWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
00128 {
00129     if (d->svg && which == Qt::PreferredSize) {
00130         if (d->elementID.isNull()) {
00131             return d->svg->size();
00132         } else {
00133             return d->svg->elementSize(d->elementID);
00134         }
00135     } else {
00136         return QGraphicsWidget::sizeHint(which, constraint);
00137     }
00138 }
00139 
00140 } // Plasma namespace
00141 
00142 #include "svgwidget.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal