moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / filters / svgexporter.cc
blob4b5aa4424c699fddb5bb095e7f291c8900193ab8
1 // Copyright (C) 2004 Pino Toscano <toscano.pino@tiscali.it>
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16 // 02111-1307, USA.
18 #include "svgexporter.h"
20 #include "exporttosvgdialog.h"
22 #include "../kig/kig_document.h"
23 #include "../kig/kig_part.h"
24 #include "../kig/kig_view.h"
25 #include "../misc/common.h"
26 #include "../misc/kigpainter.h"
28 #include <qfile.h>
29 #include <qpicture.h>
30 #include <qrect.h>
32 #include <klocale.h>
33 #include <kmessagebox.h>
35 #include <map>
37 SVGExporter::~SVGExporter()
41 QString SVGExporter::exportToStatement() const
43 return i18n( "&Export to SVG..." );
46 QString SVGExporter::menuEntryName() const
48 return i18n( "&SVG..." );
51 QString SVGExporter::menuIcon() const
53 // TODO
54 return "vectorgfx";
57 void SVGExporter::run( const KigPart& part, KigWidget& w )
59 ExportToSVGDialog* d = new ExportToSVGDialog( &w, &part );
60 if ( !d->exec() )
61 return;
63 QString file_name = d->fileName();
64 bool showgrid = d->showGrid();
65 bool showaxes = d->showAxes();
67 delete d;
69 QFile file( file_name );
70 if ( ! file.open( IO_WriteOnly ) )
72 KMessageBox::sorry( &w, i18n( "The file \"%1\" could not be opened. Please "
73 "check if the file permissions are set correctly." )
74 .arg( file_name ) );
75 return;
78 QRect viewrect( w.screenInfo().viewRect() );
79 QRect r( 0, 0, viewrect.width(), viewrect.height() );
81 QPicture pic;
82 pic.setBoundingRect( r );
83 KigPainter* p = new KigPainter( ScreenInfo( w.screenInfo().shownRect(), viewrect ),
84 &pic, part.document() );
85 // p->setWholeWinOverlay();
86 // p->setBrushColor( Qt::white );
87 // p->setBrushStyle( Qt::SolidPattern );
88 // p->drawRect( r );
89 // p->setBrushStyle( Qt::NoBrush );
90 // p->setWholeWinOverlay();
91 p->drawGrid( part.document().coordinateSystem(), showgrid, showaxes );
92 p->drawObjects( part.document().objects(), false );
94 delete p;
96 if ( !pic.save( file_name, "SVG" ) )
98 KMessageBox::error( &w, i18n( "Sorry, something went wrong while saving to SVG file \"%1\"" ).arg( file_name ) );