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

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • filters
svgexporter.cc
Go to the documentation of this file.
1 // Copyright (C) 2004 Pino Toscano <toscano.pino@tiscali.it>
2 
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.
7 
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.
12 
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., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "svgexporter.h"
19 
20 #include "svgexporteroptions.h"
21 
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/kigfiledialog.h"
27 #include "../misc/kigpainter.h"
28 
29 #include <qcheckbox.h>
30 #include <qfile.h>
31 #include <qrect.h>
32 #include <qsvggenerator.h>
33 
34 #include <klocale.h>
35 #include <kmessagebox.h>
36 
37 #include <map>
38 
39 SVGExporter::~SVGExporter()
40 {
41 }
42 
43 QString SVGExporter::exportToStatement() const
44 {
45  return i18n( "&Export to SVG..." );
46 }
47 
48 QString SVGExporter::menuEntryName() const
49 {
50  return i18n( "&SVG..." );
51 }
52 
53 QString SVGExporter::menuIcon() const
54 {
55  return "image-svg+xml";
56 }
57 
58 void SVGExporter::run( const KigPart& part, KigWidget& w )
59 {
60  KigFileDialog* kfd = new KigFileDialog(
61  QString(), i18n( "*.svg|Scalable Vector Graphics (*.svg)" ),
62  i18n( "Export as SVG" ), &w );
63  kfd->setOptionCaption( i18n( "SVG Options" ) );
64  SVGExporterOptions* opts = new SVGExporterOptions( 0L );
65  kfd->setOptionsWidget( opts );
66  opts->setGrid( part.document().grid() );
67  opts->setAxes( part.document().axes() );
68  if ( !kfd->exec() )
69  return;
70 
71  QString file_name = kfd->selectedFile();
72  bool showgrid = opts->showGrid();
73  bool showaxes = opts->showAxes();
74 
75  delete opts;
76  delete kfd;
77 
78  QFile file( file_name );
79  if ( ! file.open( QIODevice::WriteOnly ) )
80  {
81  KMessageBox::sorry( &w, i18n( "The file \"%1\" could not be opened. Please "
82  "check if the file permissions are set correctly." ,
83  file_name ) );
84  return;
85  };
86 
87  QRect viewrect( w.screenInfo().viewRect() );
88  QRect r( 0, 0, viewrect.width(), viewrect.height() );
89 
90  // workaround for QSvgGenerator bug not checking for already open device
91  file.close();
92  QSvgGenerator pic;
93  pic.setOutputDevice( &file );
94  pic.setSize( r.size() );
95  KigPainter* p = new KigPainter( ScreenInfo( w.screenInfo().shownRect(), viewrect ),
96  &pic, part.document() );
97 // p->setWholeWinOverlay();
98 // p->setBrushColor( Qt::white );
99 // p->setBrushStyle( Qt::SolidPattern );
100 // p->drawRect( r );
101 // p->setBrushStyle( Qt::NoBrush );
102 // p->setWholeWinOverlay();
103  p->drawGrid( part.document().coordinateSystem(), showgrid, showaxes );
104  p->drawObjects( part.document().objects(), false );
105 
106  delete p;
107 
108  if ( !file.flush() )
109  {
110  KMessageBox::error( &w, i18n( "Sorry, something went wrong while saving to SVG file \"%1\"", file_name ) );
111  }
112  file.close();
113 }
ScreenInfo::viewRect
const QRect viewRect() const
Definition: screeninfo.cc:78
SVGExporterOptions::showAxes
bool showAxes() const
Definition: svgexporteroptions.cc:55
SVGExporterOptions::setGrid
void setGrid(bool grid)
Definition: svgexporteroptions.cc:40
KigFileDialog
This file dialog is pretty like KFileDialog, but allow us to make an option widget popup to the user...
Definition: kigfiledialog.h:27
svgexporteroptions.h
KigDocument::grid
bool grid() const
Definition: kig_document.cc:186
KigPart::document
const KigDocument & document() const
Definition: kig_part.cpp:989
SVGExporter::~SVGExporter
~SVGExporter()
Definition: svgexporter.cc:39
SVGExporter::exportToStatement
QString exportToStatement() const
Returns a statement like i18n( "Export to image" )
Definition: svgexporter.cc:43
ScreenInfo
ScreenInfo is a simple utility class that maps a region of the document onto a region of the screen...
Definition: screeninfo.h:31
SVGExporter::menuIcon
QString menuIcon() const
Returns a string with the name of the icon.
Definition: svgexporter.cc:53
KigWidget::screenInfo
const ScreenInfo & screenInfo() const
the part of the document we're currently showing i.e.
Definition: kig_view.cpp:272
SVGExporterOptions::showGrid
bool showGrid() const
Definition: svgexporteroptions.cc:45
KigPainter
KigPainter is an extended QPainter.
Definition: kigpainter.h:51
svgexporter.h
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
KigDocument::objects
const std::vector< ObjectHolder * > objects() const
Get a hold of the objects of this KigDocument.
Definition: kig_document.cc:46
KigPainter::drawGrid
void drawGrid(const CoordinateSystem &c, bool showGrid=true, bool showAxes=true)
Definition: kigpainter.cpp:507
SVGExporter::run
void run(const KigPart &part, KigWidget &w)
Do what you need to do.
Definition: svgexporter.cc:58
KigFileDialog::setOptionCaption
void setOptionCaption(const QString &caption)
Set the caption of the option dialog.
Definition: kigfiledialog.cc:75
SVGExporterOptions
Definition: svgexporteroptions.h:25
SVGExporterOptions::setAxes
void setAxes(bool axes)
Definition: svgexporteroptions.cc:50
KigFileDialog::setOptionsWidget
void setOptionsWidget(QWidget *w)
Use this to set the widget containing the options of eg an export filter.
Definition: kigfiledialog.cc:37
KigPart
This is a "Part".
Definition: kig_part.h:68
ScreenInfo::shownRect
const Rect & shownRect() const
Definition: screeninfo.cc:68
KigDocument::axes
bool axes() const
Definition: kig_document.cc:206
KigDocument::coordinateSystem
const CoordinateSystem & coordinateSystem() const
Definition: kig_document.cc:40
KigPainter::drawObjects
void drawObjects(const std::vector< ObjectHolder * > &os, bool sel)
Definition: kigpainter.cpp:518
SVGExporter::menuEntryName
QString menuEntryName() const
Returns a string like i18n( "Image..." )
Definition: svgexporter.cc:48
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal