missing condition to write metadata
[kdegraphics.git] / svgpart / svgpart.cpp
blobf078dea28bab7b0ddff55fafd62fa0a357c54d11
1 /*
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"
21 // Qt
22 #include <QGraphicsScene>
23 #include <QGraphicsSvgItem>
24 #include <QGraphicsView>
26 // KDE
27 #include <kaboutdata.h>
28 #include <kactioncollection.h>
29 #include <kgenericfactory.h>
30 #include <kstandardaction.h>
31 #include <ksvgrenderer.h>
33 // Local
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>"));
41 return aboutData;
44 //Factory Code
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);
57 mItem = 0;
58 setWidget(mView);
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())) {
69 return false;
71 mItem = new QGraphicsSvgItem();
72 mItem->setSharedRenderer(mRenderer);
73 mScene->addItem(mItem);
74 return true;
78 bool SvgPart::closeUrl() {
79 delete mItem;
80 mItem = 0;
81 return KParts::ReadOnlyPart::closeUrl();
85 void SvgPart::zoomIn() {
86 setZoom(zoom() * 2);
90 void SvgPart::zoomOut() {
91 setZoom(zoom() / 2);
95 void SvgPart::zoomActualSize() {
96 setZoom(1.0);
100 qreal SvgPart::zoom() const {
101 return mView->matrix().m11();
105 void SvgPart::setZoom(qreal value) {
106 QMatrix matrix;
107 matrix.scale(value, value);
108 mView->setMatrix(matrix);