2 Copyright 2007 Aurélien Gâteau
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (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 Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "svgpart.moc"
22 #include <QGraphicsScene>
23 #include <QGraphicsSvgItem>
24 #include <QGraphicsView>
27 #include <kaboutdata.h>
28 #include <kactioncollection.h>
29 #include <kgenericfactory.h>
30 #include <kstandardaction.h>
31 #include <ksvgrenderer.h>
35 static KAboutData
createAboutData()
37 KAboutData
aboutData( "svgpart", 0, ki18n("SVG Part"),
38 "1.0", ki18n("A KPart to display SVG images"),
39 KAboutData::License_GPL
,
40 ki18n("Copyright 2007, Aurélien Gâteau <aurelien.gateau@free.fr>"));
45 K_PLUGIN_FACTORY( SvgPartFactory
, registerPlugin
< SvgPart
>(); )
46 K_EXPORT_PLUGIN( SvgPartFactory( createAboutData() ) )
49 SvgPart::SvgPart(QWidget
* parentWidget
, QObject
* parent
, const QVariantList
&)
50 : KParts::ReadOnlyPart(parent
)
52 mRenderer
= new KSvgRenderer(this);
53 mScene
= new QGraphicsScene(this);
54 mView
= new QGraphicsView(mScene
, parentWidget
);
55 mView
->setFrameStyle(QFrame::NoFrame
);
56 mView
->setDragMode(QGraphicsView::ScrollHandDrag
);
60 KStandardAction::actualSize(this, SLOT(zoomActualSize()), actionCollection());
61 KStandardAction::zoomIn(this, SLOT(zoomIn()), actionCollection());
62 KStandardAction::zoomOut(this, SLOT(zoomOut()), actionCollection());
63 setXMLFile("svgpart/svgpart.rc");
67 bool SvgPart::openFile() {
68 if (!mRenderer
->load(localFilePath())) {
71 mItem
= new QGraphicsSvgItem();
72 mItem
->setSharedRenderer(mRenderer
);
73 mScene
->addItem(mItem
);
78 bool SvgPart::closeUrl() {
81 return KParts::ReadOnlyPart::closeUrl();
85 void SvgPart::zoomIn() {
90 void SvgPart::zoomOut() {
95 void SvgPart::zoomActualSize() {
100 qreal
SvgPart::zoom() const {
101 return mView
->matrix().m11();
105 void SvgPart::setZoom(qreal value
) {
107 matrix
.scale(value
, value
);
108 mView
->setMatrix(matrix
);