[kgraphviewer-devel] [kgraphviewer] src/part: Add the possibility to export to svg and other pixmap formats
Gaël de Chalendar
kleag at free.fr
Thu Sep 15 22:06:46 UTC 2011
Git commit 73861f2443eb2f1f5434f82ead3f714b22bd8328 by Gaël de Chalendar.
Committed on 16/09/2011 at 00:08.
Pushed by kleag into branch 'master'.
Add the possibility to export to svg and other pixmap formats
M +24 -6 src/part/dotgraphview.cpp
http://commits.kde.org/kgraphviewer/73861f2443eb2f1f5434f82ead3f714b22bd8328
diff --git a/src/part/dotgraphview.cpp b/src/part/dotgraphview.cpp
index 68a23a9..4b3ca03 100644
--- a/src/part/dotgraphview.cpp
+++ b/src/part/dotgraphview.cpp
@@ -67,6 +67,7 @@
#include <QGraphicsSimpleTextItem>
#include <QScrollBar>
#include <QUuid>
+#include <QSvgGenerator>
#include <kdebug.h>
#include <klocale.h>
@@ -487,7 +488,7 @@ void DotGraphViewPrivate::setupPopup()
m_popup->addAction(file_exportMenu);
KAction* exportToImageAction = new KAction(i18n("As Image..."),q);
- exportToImageAction->setWhatsThis(i18n("Export the graph to an image file (currently PNG only.)"));
+ exportToImageAction->setWhatsThis(i18n("Export the graph to an image file."));
actionCollection()->addAction("export_image", exportToImageAction);
QObject::connect(exportToImageAction,SIGNAL(triggered(bool)), q, SLOT(slotExportImage()));
@@ -579,15 +580,32 @@ void DotGraphViewPrivate::exportToImage()
// write current content of canvas as image to file
if (!m_canvas) return;
- QString fn = KFileDialog::getSaveFileName(KUrl(":"),QString("*.png"),0,QString(""));
+ QString fn = KFileDialog::getSaveFileName(KUrl(":"),QString("*.svg *.bmp *.gif *.jpg *.jpeg *.png *.pbm *.pgm *.ppm *.xbm *.xpm"),0,QString(""));
if (!fn.isEmpty())
{
- QPixmap pix(m_canvas->sceneRect().size().toSize());
- QPainter p(&pix);
- m_canvas->render( &p );
- pix.save(fn,"PNG");
+ if (fn.toLower().endsWith(".svg"))
+ {
+ QSvgGenerator generator;
+ generator.setFileName(fn);
+ generator.setSize(m_canvas->sceneRect().size().toSize());
+// generator.setViewBox();
+ generator.setTitle(i18n("Graph SVG Generated by KGraphViewer"));
+ generator.setDescription(i18n("Graph SVG Generated by KGraphViewer."));
+ QPainter painter;
+ painter.begin(&generator);
+ m_canvas->render( &painter );
+ painter.end();
+ }
+ else
+ {
+ QPixmap pix(m_canvas->sceneRect().size().toSize());
+ QPainter p(&pix);
+ m_canvas->render( &p );
+ pix.save(fn, 0, 100);
+ }
}
+
}
More information about the kgraphviewer-devel
mailing list