From 588232a44280489b549b32ffa5aaa8879edff5ab Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 15 May 2021 15:28:17 +0200 Subject: [PATCH] new class VPExporter --- src/app/puzzle/puzzle.pri | 2 + src/app/puzzle/vpexporter.cpp | 404 ++++++++++++++++++++++++++++++++ src/app/puzzle/vpexporter.h | 69 ++++++ src/app/puzzle/vpmainwindow.cpp | 55 +---- src/app/puzzle/vpmainwindow.h | 2 + 5 files changed, 489 insertions(+), 43 deletions(-) create mode 100644 src/app/puzzle/vpexporter.cpp create mode 100644 src/app/puzzle/vpexporter.h diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index fe479e253..209521fe3 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -10,6 +10,7 @@ SOURCES += \ $$PWD/vpcarrouselpiecelist.cpp \ $$PWD/vpcommandline.cpp \ $$PWD/vpcommands.cpp \ + $$PWD/vpexporter.cpp \ $$PWD/vpgraphicspiece.cpp \ $$PWD/vpgraphicssheet.cpp \ $$PWD/vpgraphicstilegrid.cpp \ @@ -37,6 +38,7 @@ HEADERS += \ $$PWD/vpcarrouselpiecelist.h \ $$PWD/vpcommandline.h \ $$PWD/vpcommands.h \ + $$PWD/vpexporter.h \ $$PWD/vpgraphicspiece.h \ $$PWD/vpgraphicssheet.h \ $$PWD/vpgraphicstilegrid.h \ diff --git a/src/app/puzzle/vpexporter.cpp b/src/app/puzzle/vpexporter.cpp new file mode 100644 index 000000000..bef34b011 --- /dev/null +++ b/src/app/puzzle/vpexporter.cpp @@ -0,0 +1,404 @@ +#include "vpexporter.h" + +#include +#include +#include + +#include "../vwidgets/vmaingraphicsscene.h" +#include "vpsheet.h" +#include "vpmaingraphicsview.h" + + +//--------------------------------------------------------------------------------------------------------------------- +VPExporter::VPExporter(VPLayout* layout, VCommonSettings *commonSettings): + m_layout(layout), + m_commonSettings(commonSettings) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +VPExporter::~VPExporter() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPExporter::Export(LayoutExportFormats format, VPMainGraphicsView *mainGraphicsView) +{ + QString dir = QDir::homePath(); + QString filters(ExportFormatDescription(format)); + + // is it ok to have a null ptr hier as a parent? + QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Save as"), + dir + QLatin1String("/") + m_layout->GetFocusedSheet()->GetName() + ExportFormatSuffix(format), + filters, nullptr +#ifdef Q_OS_LINUX + , QFileDialog::DontUseNativeDialog +#endif + ); + + if(not fileName.isEmpty()) + { + mainGraphicsView->PrepareForExport(); + + switch(format) + { + case LayoutExportFormats::SVG: + ExportToSVG(fileName, mainGraphicsView); + break; + + case LayoutExportFormats::PDF: + ExportToPDF(fileName, mainGraphicsView); + break; + + case LayoutExportFormats::PNG: + ExportToPNG(fileName, mainGraphicsView); + break; + + case LayoutExportFormats::TIF: + ExportToTIF(fileName, mainGraphicsView); + break; + + default: + // do nothing + break; + } + mainGraphicsView->CleanAfterExport(); + } +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPExporter::ExportToSVG(QString fileName, VPMainGraphicsView *mainGraphicsView) +{ + QSizeF size = QSizeF(m_layout->GetFocusedSheet()->GetSheetSize()); + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Landscape) + { + size.transpose(); + } + const QRectF rect = QRectF(0, 0, size.width(), size.height()); + + QSvgGenerator generator; + generator.setFileName(fileName); + generator.setResolution(static_cast(PrintDPI)); + generator.setSize(QSize(qRound(size.width()),qRound(size.height()))); + generator.setViewBox(rect); + generator.setTitle(m_layout->GetFocusedSheet()->GetName()); + generator.setDescription(m_layout->GetDescription().toHtmlEscaped()); + + QPainter painter; + painter.begin(&generator); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, m_commonSettings->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + mainGraphicsView->GetScene()->render(&painter, rect, rect, Qt::IgnoreAspectRatio); + painter.end(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPExporter::ExportToPDF(QString fileName, VPMainGraphicsView *mainGraphicsView) +{ + QSizeF size = QSizeF(m_layout->GetFocusedSheet()->GetSheetSize()); + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Landscape) + { + size.transpose(); + } + const QRectF rect = QRectF(0, 0, size.width(), size.height()); + + QPrinter printer; + printer.setCreator(QGuiApplication::applicationDisplayName() + QChar(QChar::Space) + + QCoreApplication::applicationVersion()); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(fileName); + printer.setDocName(QFileInfo(fileName).fileName()); + printer.setResolution(static_cast(PrintDPI)); + printer.setPageOrientation(QPageLayout::Portrait); + printer.setFullPage(true); + + qreal width = FromPixel(size.width(), Unit::Mm); + qreal height = FromPixel(size.height(), Unit::Mm); + + if (not printer.setPageSize(QPageSize(QSizeF(width, height), QPageSize::Millimeter))) + { + qWarning() << tr("Cannot set printer page size"); + } + + QPainter painter; + if (not painter.begin(&printer)) + { // failed to open file + qCritical() << qUtf8Printable(tr("Can't open file '%1'").arg(fileName)); + return; + } + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, m_commonSettings->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + mainGraphicsView->GetScene()->render(&painter, rect, rect, Qt::IgnoreAspectRatio); + painter.end(); +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPExporter::ExportToPNG(QString filename, VPMainGraphicsView *mainGraphicsView) +{ + QSizeF size = QSizeF(m_layout->GetFocusedSheet()->GetSheetSize()); + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Landscape) + { + size.transpose(); + } + const QRectF rect = QRectF(0, 0, size.width(), size.height()); + + QImage image(QSize(qFloor(size.width()), qFloor((size.height()))), QImage::Format_ARGB32); + image.fill(Qt::white); + + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, m_commonSettings->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush(QBrush(Qt::NoBrush)); + + mainGraphicsView->GetScene()->render(&painter, rect, rect, Qt::IgnoreAspectRatio); + image.save(filename); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPExporter::ExportToTIF(QString filename, VPMainGraphicsView *mainGraphicsView) +{ + QSizeF size = QSizeF(m_layout->GetFocusedSheet()->GetSheetSize()); + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Landscape) + { + size.transpose(); + } + const QRectF rect = QRectF(0, 0, size.width(), size.height()); + + QImage image(QSize(qFloor(size.width()), qFloor((size.height()))), QImage::Format_ARGB32); + image.fill(Qt::white); + + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, m_commonSettings->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush(QBrush(Qt::NoBrush)); + + mainGraphicsView->GetScene()->render(&painter, rect, rect, Qt::IgnoreAspectRatio); + + + // FIXME, not working in ubuntu 21.04 of rlt "format not supported" + + QImageWriter writer; + writer.setFormat("tiff"); + writer.setCompression(1); // LZW-compression + writer.setFileName(filename); + + if (not writer.write(image)) + { // failed to save file + qCritical() << qUtf8Printable(tr("Can't save file '%1'. Error: %2.").arg(filename, writer.errorString())); + return; + } +} + + + +// FIXME Bad copy paste from DialogSaveLayout, because I didn't know how to call this function from here +// to be removed as soon as I know how to call the central function from valentina +//--------------------------------------------------------------------------------------------------------------------- +QString VPExporter::ExportFormatDescription(LayoutExportFormats format) +{ + const QString dxfSuffix = QStringLiteral("(*.dxf)"); + const QString dxfFlatFilesStr = tr("(flat) files"); + const QString filesStr = tr("files"); + + switch(format) + { + case LayoutExportFormats::SVG: + return QStringLiteral("Svg %1 (*.svg)").arg(filesStr); + case LayoutExportFormats::PDF: + return QStringLiteral("PDF %1 (*.pdf)").arg(filesStr); + case LayoutExportFormats::PNG: + return tr("Image files") + QStringLiteral(" (*.png)"); + case LayoutExportFormats::OBJ: + return QStringLiteral("Wavefront OBJ (*.obj)"); + case LayoutExportFormats::PS: + return QStringLiteral("PS %1 (*.ps)").arg(filesStr); + case LayoutExportFormats::EPS: + return QStringLiteral("EPS %1 (*.eps)").arg(filesStr); + case LayoutExportFormats::DXF_AC1006_Flat: + return QStringLiteral("AutoCAD DXF R10 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1009_Flat: + return QStringLiteral("AutoCAD DXF R11/12 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1012_Flat: + return QStringLiteral("AutoCAD DXF R13 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1014_Flat: + return QStringLiteral("AutoCAD DXF R14 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1015_Flat: + return QStringLiteral("AutoCAD DXF 2000 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1018_Flat: + return QStringLiteral("AutoCAD DXF 2004 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1021_Flat: + return QStringLiteral("AutoCAD DXF 2007 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1024_Flat: + return QStringLiteral("AutoCAD DXF 2010 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1027_Flat: + return QStringLiteral("AutoCAD DXF 2013 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1006_AAMA: + return QStringLiteral("AutoCAD DXF R10 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1009_AAMA: + return QStringLiteral("AutoCAD DXF R11/12 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1012_AAMA: + return QStringLiteral("AutoCAD DXF R13 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1014_AAMA: + return QStringLiteral("AutoCAD DXF R14 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1015_AAMA: + return QStringLiteral("AutoCAD DXF 2000 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1018_AAMA: + return QStringLiteral("AutoCAD DXF 2004 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1021_AAMA: + return QStringLiteral("AutoCAD DXF 2007 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1024_AAMA: + return QStringLiteral("AutoCAD DXF 2010 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1027_AAMA: + return QStringLiteral("AutoCAD DXF 2013 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1006_ASTM: + return QStringLiteral("AutoCAD DXF R10 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1009_ASTM: + return QStringLiteral("AutoCAD DXF R11/12 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1012_ASTM: + return QStringLiteral("AutoCAD DXF R13 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1014_ASTM: + return QStringLiteral("AutoCAD DXF R14 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1015_ASTM: + return QStringLiteral("AutoCAD DXF 2000 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1018_ASTM: + return QStringLiteral("AutoCAD DXF 2004 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1021_ASTM: + return QStringLiteral("AutoCAD DXF 2007 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1024_ASTM: + return QStringLiteral("AutoCAD DXF 2010 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1027_ASTM: + return QStringLiteral("AutoCAD DXF 2013 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::PDFTiled: + return QStringLiteral("PDF %1 %2 (*.pdf)").arg(tr("tiled"), filesStr); + case LayoutExportFormats::NC: + return QStringLiteral("%1 %2 (*.nc)").arg(tr("Numerical control"), filesStr); + case LayoutExportFormats::RLD: + return QStringLiteral("%1 %2 (*.rld)").arg(tr("Raw Layout Data"), filesStr); + case LayoutExportFormats::TIF: + return QStringLiteral("TIFF %1 (*.tif)").arg(filesStr); + default: + return QString(); + } +} + +// FIXME Bad copy paste from DialogSaveLayout, because I didn't know how to call this function from here +// to be removed as soon as I know how to call the central function from valentina +//--------------------------------------------------------------------------------------------------------------------- +QString VPExporter::ExportFormatSuffix(LayoutExportFormats format) +{ + switch(format) + { + case LayoutExportFormats::SVG: + return QStringLiteral(".svg"); + case LayoutExportFormats::PDF: + case LayoutExportFormats::PDFTiled: + return QStringLiteral(".pdf"); + case LayoutExportFormats::PNG: + return QStringLiteral(".png"); + case LayoutExportFormats::OBJ: + return QStringLiteral(".obj"); + case LayoutExportFormats::PS: + return QStringLiteral(".ps"); + case LayoutExportFormats::EPS: + return QStringLiteral(".eps"); + case LayoutExportFormats::DXF_AC1006_Flat: + case LayoutExportFormats::DXF_AC1009_Flat: + case LayoutExportFormats::DXF_AC1012_Flat: + case LayoutExportFormats::DXF_AC1014_Flat: + case LayoutExportFormats::DXF_AC1015_Flat: + case LayoutExportFormats::DXF_AC1018_Flat: + case LayoutExportFormats::DXF_AC1021_Flat: + case LayoutExportFormats::DXF_AC1024_Flat: + case LayoutExportFormats::DXF_AC1027_Flat: + case LayoutExportFormats::DXF_AC1006_AAMA: + case LayoutExportFormats::DXF_AC1009_AAMA: + case LayoutExportFormats::DXF_AC1012_AAMA: + case LayoutExportFormats::DXF_AC1014_AAMA: + case LayoutExportFormats::DXF_AC1015_AAMA: + case LayoutExportFormats::DXF_AC1018_AAMA: + case LayoutExportFormats::DXF_AC1021_AAMA: + case LayoutExportFormats::DXF_AC1024_AAMA: + case LayoutExportFormats::DXF_AC1027_AAMA: + case LayoutExportFormats::DXF_AC1006_ASTM: + case LayoutExportFormats::DXF_AC1009_ASTM: + case LayoutExportFormats::DXF_AC1012_ASTM: + case LayoutExportFormats::DXF_AC1014_ASTM: + case LayoutExportFormats::DXF_AC1015_ASTM: + case LayoutExportFormats::DXF_AC1018_ASTM: + case LayoutExportFormats::DXF_AC1021_ASTM: + case LayoutExportFormats::DXF_AC1024_ASTM: + case LayoutExportFormats::DXF_AC1027_ASTM: + return QStringLiteral(".dxf"); + case LayoutExportFormats::NC: + return QStringLiteral(".nc"); + case LayoutExportFormats::RLD: + return QStringLiteral(".rld"); + case LayoutExportFormats::TIF: + return QStringLiteral(".tif"); + default: + return QString(); + } +} + + +// FIXME Bad copy paste from DialogSaveLayout, because I didn't know how to call this function from here +// to be removed as soon as I know how to call the central function from valentina +//--------------------------------------------------------------------------------------------------------------------- +QVector > VPExporter::InitFormats() +{ + QVector> list; + + auto InitFormat = [&list](LayoutExportFormats format) + { + list.append(std::make_pair(ExportFormatDescription(format), format)); + }; + + InitFormat(LayoutExportFormats::SVG); + InitFormat(LayoutExportFormats::PDF); + InitFormat(LayoutExportFormats::PNG); + +// InitFormat(LayoutExportFormats::OBJ); + +// InitFormat(LayoutExportFormats::PS); +// InitFormat(LayoutExportFormats::EPS); + +// InitFormat(LayoutExportFormats::DXF_AC1006_Flat); +// InitFormat(LayoutExportFormats::DXF_AC1009_Flat); +// InitFormat(LayoutExportFormats::DXF_AC1012_Flat); +// InitFormat(LayoutExportFormats::DXF_AC1014_Flat); +// InitFormat(LayoutExportFormats::DXF_AC1015_Flat); +// InitFormat(LayoutExportFormats::DXF_AC1018_Flat); +// InitFormat(LayoutExportFormats::DXF_AC1021_Flat); +// InitFormat(LayoutExportFormats::DXF_AC1024_Flat); +// InitFormat(LayoutExportFormats::DXF_AC1027_Flat); +// InitFormat(LayoutExportFormats::DXF_AC1006_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1009_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1012_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1014_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1015_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1018_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1021_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1024_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1027_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1006_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1009_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1012_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1014_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1015_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1018_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1021_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1024_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1027_ASTM); +// InitFormat(LayoutExportFormats::PDFTiled); +// InitFormat(LayoutExportFormats::NC); +// InitFormat(LayoutExportFormats::RLD); + InitFormat(LayoutExportFormats::TIF); + + return list; +} diff --git a/src/app/puzzle/vpexporter.h b/src/app/puzzle/vpexporter.h new file mode 100644 index 000000000..46627c088 --- /dev/null +++ b/src/app/puzzle/vpexporter.h @@ -0,0 +1,69 @@ +#ifndef VPEXPORTER_H +#define VPEXPORTER_H + +#include + +#include "vplayout.h" +#include "../vmisc/def.h" +#include "vcommonsettings.h" +#include "../vlayout/vlayoutdef.h" + +//#include "../dialogs/dialogsavelayout.h" + +class VPMainGraphicsView; + +class VPExporter : QObject +{ + Q_OBJECT + +public: + VPExporter(VPLayout* layout, VCommonSettings *commonSettings); + ~VPExporter(); + + void Export(LayoutExportFormats format, VPMainGraphicsView *mainGraphicsView); + + + // FIXME Bad copy paste from DialogSaveLayout, because I didn't know how to call this function from here + // to be removed as soon as I know how to call the central function from valentina + QVector > InitFormats(); + +private: + Q_DISABLE_COPY(VPExporter) + + VPLayout *m_layout{nullptr}; + VCommonSettings *m_commonSettings{nullptr}; + + /** + * @brief ExportSVG exports the current maingraphicViews to an svg file + * @param fileName the file name of the export + */ + void ExportToSVG(QString fileName, VPMainGraphicsView *mainGraphicsView); + + /** + * @brief ExportSVG exports the current maingraphicViews to a pdf file + * @param fileName the file name of the export + */ + void ExportToPDF(QString filename, VPMainGraphicsView *mainGraphicsView); + + /** + * @brief ExportSVG exports the current maingraphicViews to a png file + * @param fileName the file name of the export + */ + void ExportToPNG(QString filename, VPMainGraphicsView *mainGraphicsView); + + /** + * @brief ExportSVG exports the current maingraphicViews to a TIF file + * @param fileName the file name of the export + */ + void ExportToTIF(QString filename, VPMainGraphicsView *mainGraphicsView); + + + // FIXME Bad copy paste from DialogSaveLayout, because I didn't know how to call this function from here + // to be removed as soon as I know how to call the central function from valentina + static QString ExportFormatDescription(LayoutExportFormats format); + static QString ExportFormatSuffix(LayoutExportFormats format); + + +}; + +#endif // VPEXPORTER_H diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index f6fed5329..17d467911 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -92,6 +92,9 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : m_tileFactory = new VPTileFactory(m_layout, qApp->Settings()); m_tileFactory->refreshTileInfos(); + // init the export tool + m_exporter = new VPExporter(m_layout, qApp->Settings()); + InitMenuBar(); InitProperties(); InitCarrousel(); @@ -104,7 +107,6 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : ReadSettings(); - } //--------------------------------------------------------------------------------------------------------------------- @@ -341,6 +343,13 @@ void VPMainWindow::InitPropertyTabCurrentSheet() ui->comboBoxSheetTemplate->blockSignals(false); ui->comboBoxSheetTemplate->setCurrentIndex(0); + + // ---------------------- export format -------------------------- + + for (auto &v : m_exporter->InitFormats()) + { + ui->comboBoxSheetExportFormat->addItem(v.first, QVariant(static_cast(v.second))); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -1274,8 +1283,6 @@ void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_pushButtonTilesExport_clicked() { - // svg export to do some test for the first test - QString dir = QDir::homePath(); QString filters(tr("PDF Files") + QLatin1String("(*.pdf)")); QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), @@ -1344,47 +1351,9 @@ void VPMainWindow::on_checkBoxSheetStickyEdges_toggled(bool checked) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_pushButtonSheetExport_clicked() { - // svg export to do some test for the first test + LayoutExportFormats format = static_cast(ui->comboBoxSheetExportFormat->currentData().toInt()); - QString dir = QDir::homePath(); - QString filters(tr("SVG Files") + QLatin1String("(*.svg)")); - QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), - dir + QLatin1String("/") + m_layout->GetFocusedSheet()->GetName() + QLatin1String(".svg"), - filters, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); - - if(not fileName.isEmpty()) - { - m_graphicsView->PrepareForExport(); - - QSizeF size = QSizeF(m_layout->GetFocusedSheet()->GetSheetSize()); - if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Landscape) - { - size.transpose(); - } - const QRectF rect = QRectF(0, 0, size.width(), size.height()); - - QSvgGenerator generator; - generator.setFileName(fileName); - generator.setSize(QSize(qFloor(size.width()),qFloor(size.height()))); - generator.setViewBox(rect); - generator.setTitle(m_layout->GetFocusedSheet()->GetName()); - generator.setDescription(m_layout->GetDescription().toHtmlEscaped()); - generator.setResolution(static_cast(PrintDPI)); - - QPainter painter; - painter.begin(&generator); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - m_graphicsView->GetScene()->render(&painter, rect, rect, Qt::IgnoreAspectRatio); - painter.end(); - - m_graphicsView->CleanAfterExport(); - } + m_exporter->Export(format, m_graphicsView); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 1862bc126..5085a675b 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -40,6 +40,7 @@ #include "vppiece.h" #include "../vlayout/vlayoutpiece.h" #include "vptilefactory.h" +#include "vpexporter.h" #include "vpcommandline.h" #include "../vlayout/vlayoutdef.h" @@ -107,6 +108,7 @@ private: QListm_selectedPieces{QList()}; VPTileFactory *m_tileFactory{nullptr}; + VPExporter *m_exporter{nullptr}; /** * @brief spin box with the scale factor of the graphic view