[Kst] branches/work/kst/portto4/kst/src/libkstapp
Barth Netterfield
netterfield at astro.utoronto.ca
Thu Apr 7 01:11:44 CEST 2011
SVN commit 1227253 by netterfield:
Add svg to graphics output formats.
Now kst can become the app of choice for wikipedia plots :-)
M +1 -0 exportgraphicsdialog.cpp
M +40 -9 mainwindow.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/exportgraphicsdialog.cpp #1227252:1227253
@@ -34,6 +34,7 @@
_autoSaveTimer = new QTimer(this);
QStringList formats;// = QPictureIO::outputFormats();
+ formats.append(QString("svg"));
foreach(QByteArray array, QImageWriter::supportedImageFormats()) {
formats.append(QString(array));
}
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #1227252:1227253
@@ -59,6 +59,7 @@
#include "dialoglauncher.h"
#include <QtGui>
+#include <QSvgGenerator>
namespace Kst {
@@ -446,9 +447,45 @@
size.setWidth((int)((double)height * (double)sizeWindow.width() / (double)sizeWindow.height()));
}
+
+ QString file = filename;
+ if (n_views != 1) {
+ QFileInfo QFI(filename);
+ file = QFI.completeBaseName() +
+ '_' +
+ QString::number(viewCount+1) + '.' +
+ QFI.suffix();
+ }
+
+ if (format == QString("svg")) {
+ QPainter painter;
+ QSvgGenerator generator;
+
+ QSize currentSize(view->size());
+ view->resize(size);
+ view->processResize(size);
+ view->setPrinting(true);
+
+ generator.setFileName(file);
+ generator.setResolution(100);
+ generator.setSize(view->size());
+ generator.setViewBox(view->rect());
+
+ painter.begin(&generator);
+ view->render(&painter);
+ painter.end();
+
+ view->setPrinting(false);
+ view->resize(currentSize);
+ view->processResize(currentSize);
+
+
+ } else {
+ QPainter painter;
QImage image(size, QImage::Format_ARGB32);
- QPainter painter(&image);
+ painter.begin(&image);
+
QSize currentSize(view->size());
view->resize(size);
view->processResize(size);
@@ -458,17 +495,11 @@
view->resize(currentSize);
view->processResize(currentSize);
- QString file = filename;
- if (n_views != 1) {
- QFileInfo QFI(filename);
- file = QFI.completeBaseName() +
- '_' +
- QString::number(viewCount+1) + '.' +
- QFI.suffix();
- }
+ painter.end();
QImageWriter imageWriter(file, format.toLatin1());
imageWriter.write(image);
+ }
viewCount++;
}
}
More information about the Kst
mailing list