summaryrefslogtreecommitdiff
path: root/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mainwindow.cpp')
-rw-r--r--mainwindow.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 62983c8..c6cd1b8 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -22,6 +22,8 @@
#include <QFileDialog>
#include <QIcon>
#include <QImage>
+#include <QSvgGenerator>
+#include <QMessageBox>
#include <QDebug>
#include "mainwindow.h"
#include "databasetable.h"
@@ -234,18 +236,35 @@ MainWindow::saveAs()
void
MainWindow::exportPNG()
{
- QString fileName = QFileDialog::getSaveFileName(this, QString(), QString(), "Portable Network Graphics (*.png)");
+ QStringList filters;
+ filters << "Portable Network Graphics (*.png)";
+ filters << "Scalable Vector Graphics (*.svg)";
+ QString fileName = QFileDialog::getSaveFileName(this, QString(), QString(), filters.join(";;"));
if (!fileName.isNull()) {
QRectF boundingRect = m_model->itemsBoundingRect().adjusted(-2, -2, 2, 2);
- QImage image(int(ceil(boundingRect.width())), int(ceil(boundingRect.height())), QImage::Format_RGB32);
- QPainter painter(&image);
- painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing);
- painter.fillRect(image.rect(), Qt::white);
- m_model->render(&painter, image.rect(), boundingRect);
- if (true)
- image.convertToFormat(QImage::Format_Indexed8).save(fileName, "PNG");
- else
- image.save(fileName, "PNG");
+ QSize size(int(ceil(boundingRect.width())), int(ceil(boundingRect.height())));
+ if (fileName.endsWith(".svg", Qt::CaseInsensitive)) {
+ QSvgGenerator generator;
+ generator.setSize(size);
+ generator.setFileName(fileName);
+ QPainter painter(&generator);
+ painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing);
+ m_model->render(&painter, QRectF(), boundingRect);
+ }
+ else if (fileName.endsWith(".png", Qt::CaseInsensitive)) {
+ QImage image(size, QImage::Format_RGB32);
+ QPainter painter(&image);
+ painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing);
+ painter.fillRect(image.rect(), Qt::white);
+ m_model->render(&painter, image.rect(), boundingRect);
+ if (true)
+ image.convertToFormat(QImage::Format_Indexed8).save(fileName, "PNG");
+ else
+ image.save(fileName, "PNG");
+ }
+ else {
+ QMessageBox::critical(this, tr("Error"), tr("Unknown format."));
+ }
}
}