• 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
exporter.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
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 "exporter.h"
19 #include "exporter.moc"
20 
21 #include "imageexporteroptions.h"
22 #include "latexexporter.h"
23 #include "asyexporter.h"
24 #include "svgexporter.h"
25 #include "xfigexporter.h"
26 
27 #include "../kig/kig_document.h"
28 #include "../kig/kig_part.h"
29 #include "../kig/kig_view.h"
30 #include "../misc/common.h"
31 #include "../misc/kigfiledialog.h"
32 #include "../misc/kigpainter.h"
33 
34 #include <qfile.h>
35 
36 #include <kactionmenu.h>
37 #include <kactioncollection.h>
38 #include <kicon.h>
39 #include <kimageio.h>
40 #include <klocale.h>
41 #include <kmessagebox.h>
42 #include <kmimetype.h>
43 
44 ExporterAction::ExporterAction( const KigPart* doc, KigWidget* w,
45  KActionCollection* parent, KigExporter* exp )
46  : KAction( exp->menuEntryName(), parent),
47  mexp( exp ), mdoc( doc ), mw( w )
48 {
49  QString iconstr = exp->menuIcon();
50  if ( !iconstr.isEmpty() )
51  setIcon( KIcon( iconstr, const_cast<KigPart*>( doc )->iconLoader() ) );
52  connect( this, SIGNAL( triggered() ), this, SLOT( slotActivated() ) );
53  if(parent)
54  parent->addAction("action", this );
55 }
56 
57 void ExporterAction::slotActivated()
58 {
59  mexp->run( *mdoc, *mw );
60 }
61 
62 KigExporter::~KigExporter()
63 {
64 }
65 
66 ImageExporter::~ImageExporter()
67 {
68 }
69 
70 QString ImageExporter::exportToStatement() const
71 {
72  return i18n( "&Export to image" );
73 }
74 
75 QString ImageExporter::menuEntryName() const
76 {
77  return i18n( "&Image..." );
78 }
79 
80 QString ImageExporter::menuIcon() const
81 {
82  return "image-x-generic";
83 }
84 
85 void ImageExporter::run( const KigPart& doc, KigWidget& w )
86 {
87  KigFileDialog* kfd = new KigFileDialog(
88  QString(), KImageIO::pattern( KImageIO::Writing ),
89  i18n( "Export as Image" ), &w );
90  kfd->setOptionCaption( i18n( "Image Options" ) );
91  ImageExporterOptions* opts = new ImageExporterOptions( 0L );
92  kfd->setOptionsWidget( opts );
93  opts->setImageSize( w.size() );
94  opts->setGrid( doc.document().grid() );
95  opts->setAxes( doc.document().axes() );
96  if ( !kfd->exec() )
97  return;
98 
99  QString filename = kfd->selectedFile();
100  bool showgrid = opts->showGrid();
101  bool showaxes = opts->showAxes();
102  QSize imgsize = opts->imageSize();
103 
104  delete opts;
105  delete kfd;
106 
107  KMimeType::Ptr mimeType = KMimeType::findByPath( filename );
108  kDebug() << "mimetype: " << mimeType->name();
109  if ( !KImageIO::isSupported( mimeType->name(), KImageIO::Writing ) )
110  {
111  KMessageBox::sorry( &w, i18n( "Sorry, this file format is not supported." ) );
112  return;
113  };
114 
115  QFile file( filename );
116  if ( ! file.open( QIODevice::WriteOnly ) )
117  {
118  KMessageBox::sorry( &w,
119  i18n( "The file \"%1\" could not be opened. Please check if the file permissions are set correctly." ,
120  filename ) );
121  return;
122  };
123 
124  QPixmap img( imgsize );
125  img.fill( Qt::white );
126  KigPainter p( ScreenInfo( w.screenInfo().shownRect(), img.rect() ), &img, doc.document() );
127  p.setWholeWinOverlay();
128  p.drawGrid( doc.document().coordinateSystem(), showgrid, showaxes );
129  // FIXME: show the selections ?
130  p.drawObjects( doc.document().objects(), false );
131  QStringList types = KImageIO::typeForMime( mimeType->name() );
132  if ( types.isEmpty() ) return; // TODO error dialog?
133  if ( !img.save( filename, types.at(0).toLatin1() ) )
134  {
135  KMessageBox::error( &w, i18n( "Sorry, something went wrong while saving to image \"%1\"", filename ) );
136  }
137 
138 }
139 
140 KigExportManager::KigExportManager()
141 {
142  mexporters.push_back( new ImageExporter );
143  mexporters.push_back( new XFigExporter );
144  mexporters.push_back( new LatexExporter );
145  mexporters.push_back( new AsyExporter );
146  mexporters.push_back( new SVGExporter );
147 }
148 
149 KigExportManager::~KigExportManager()
150 {
151  for ( uint i = 0; i < mexporters.size(); ++i )
152  delete mexporters[i];
153 }
154 
155 void KigExportManager::addMenuAction( const KigPart* doc, KigWidget* w,
156  KActionCollection* coll )
157 {
158  KActionMenu* m = new KActionMenu( i18n( "&Export To" ), w );
159  m->setIcon( KIcon( "document-export", const_cast<KigPart*>( doc )->iconLoader() ) );
160  for ( uint i = 0; i < mexporters.size(); ++i )
161  m->addAction( new ExporterAction( doc, w, coll, mexporters[i] ) );
162  if(coll)
163  coll->addAction("file_export", m );
164 }
165 
166 KigExportManager* KigExportManager::instance()
167 {
168  static KigExportManager m;
169  return &m;
170 }
asyexporter.h
KigExporter::run
virtual void run(const KigPart &doc, KigWidget &w)=0
Do what you need to do.
latexexporter.h
KigPainter::setWholeWinOverlay
void setWholeWinOverlay()
this is called by some drawing functions that modify the 'entire' screen, i.e.
Definition: kigpainter.cpp:494
ImageExporterOptions::setAxes
void setAxes(bool axes)
Definition: imageexporteroptions.cc:71
ImageExporter::menuIcon
QString menuIcon() const
Returns a string with the name of the icon.
Definition: exporter.cc:80
KigExporter
Base class for a Kig exporter.
Definition: exporter.h:63
KigFileDialog
This file dialog is pretty like KFileDialog, but allow us to make an option widget popup to the user...
Definition: kigfiledialog.h:27
KigExporter::~KigExporter
virtual ~KigExporter()
Definition: exporter.cc:62
KigDocument::grid
bool grid() const
Definition: kig_document.cc:186
KigPart::document
const KigDocument & document() const
Definition: kig_part.cpp:989
SVGExporter
Export to Scalable Vector Graphics (SVG)
Definition: svgexporter.h:30
XFigExporter
Guess what this one does ;) It exports to the XFig file format, as documented in the file FORMAT3...
Definition: xfigexporter.h:28
ExporterAction::ExporterAction
ExporterAction(const KigPart *doc, KigWidget *w, KActionCollection *parent, KigExporter *exp)
Definition: exporter.cc:44
LatexExporter
Export to LaTex.
Definition: latexexporter.h:30
ImageExporterOptions::showAxes
bool showAxes() const
Definition: imageexporteroptions.cc:76
KigExportManager::instance
static KigExportManager * instance()
Definition: exporter.cc:166
ImageExporter
This exporter takes care of the "Export to Image" stuff.
Definition: exporter.h:92
ImageExporterOptions::setImageSize
void setImageSize(const QSize &size)
Definition: imageexporteroptions.cc:81
ScreenInfo
ScreenInfo is a simple utility class that maps a region of the document onto a region of the screen...
Definition: screeninfo.h:31
ImageExporterOptions::setGrid
void setGrid(bool grid)
Definition: imageexporteroptions.cc:61
KigWidget::screenInfo
const ScreenInfo & screenInfo() const
the part of the document we're currently showing i.e.
Definition: kig_view.cpp:272
ExporterAction
Definition: exporter.h:43
KigExporter::menuIcon
virtual QString menuIcon() const =0
Returns a string with the name of the icon.
KigPainter
KigPainter is an extended QPainter.
Definition: kigpainter.h:51
KigExportManager::addMenuAction
void addMenuAction(const KigPart *doc, KigWidget *w, KActionCollection *coll)
Definition: exporter.cc:155
exporter.h
svgexporter.h
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
ImageExporterOptions
Definition: imageexporteroptions.h:28
AsyExporter
Export to Asymptote.
Definition: asyexporter.h:30
ImageExporterOptions::imageSize
QSize imageSize() const
Definition: imageexporteroptions.cc:93
KigDocument::objects
const std::vector< ObjectHolder * > objects() const
Get a hold of the objects of this KigDocument.
Definition: kig_document.cc:46
imageexporteroptions.h
KigFileDialog::setOptionCaption
void setOptionCaption(const QString &caption)
Set the caption of the option dialog.
Definition: kigfiledialog.cc:75
ImageExporter::menuEntryName
QString menuEntryName() const
Returns a string like i18n( "Image..." )
Definition: exporter.cc:75
KigExportManager
Definition: exporter.h:32
xfigexporter.h
ImageExporter::exportToStatement
QString exportToStatement() const
Returns a statement like i18n( "Export to image" )
Definition: exporter.cc:70
KAction
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
ImageExporter::~ImageExporter
~ImageExporter()
Definition: exporter.cc:66
KigDocument::axes
bool axes() const
Definition: kig_document.cc:206
KigDocument::coordinateSystem
const CoordinateSystem & coordinateSystem() const
Definition: kig_document.cc:40
uint
unsigned int uint
Definition: object_imp.h:87
ImageExporterOptions::showGrid
bool showGrid() const
Definition: imageexporteroptions.cc:66
ImageExporter::run
void run(const KigPart &doc, KigWidget &w)
Do what you need to do.
Definition: exporter.cc:85
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 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