From f6e5f67159cdaa048facc92909c7bdac0c72589c Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 14 Nov 2020 12:37:43 +0100 Subject: [PATCH] Button export with test svg export --- src/app/puzzle/puzzle.pro | 2 +- src/app/puzzle/vpgraphicssheet.cpp | 26 ++++++++++++++--- src/app/puzzle/vpgraphicssheet.h | 16 +++++++++++ src/app/puzzle/vpmaingraphicsview.cpp | 18 ++++++++++++ src/app/puzzle/vpmaingraphicsview.h | 10 +++++++ src/app/puzzle/vpmainwindow.cpp | 41 +++++++++++++++++++++++---- src/app/puzzle/vpmainwindow.h | 2 ++ 7 files changed, 104 insertions(+), 11 deletions(-) diff --git a/src/app/puzzle/puzzle.pro b/src/app/puzzle/puzzle.pro index 462579124..4d1e2fbd8 100644 --- a/src/app/puzzle/puzzle.pro +++ b/src/app/puzzle/puzzle.pro @@ -7,7 +7,7 @@ # File with common stuff for whole project include(../../../common.pri) -QT += core gui widgets network xml xmlpatterns printsupport concurrent +QT += core gui widgets network xml svg xmlpatterns printsupport concurrent # Name of binary file TARGET = puzzle diff --git a/src/app/puzzle/vpgraphicssheet.cpp b/src/app/puzzle/vpgraphicssheet.cpp index 42ed505d1..cfee78a09 100644 --- a/src/app/puzzle/vpgraphicssheet.cpp +++ b/src/app/puzzle/vpgraphicssheet.cpp @@ -55,12 +55,18 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->setPen(pen); painter->setBrush(noBrush); - painter->drawRect(GetMarginsRect()); + if(m_showMargin) + { + painter->drawRect(GetMarginsRect()); + } - pen.setColor(Qt::black); + if(m_showBorder) + { + pen.setColor(Qt::black); - painter->setPen(pen); - painter->drawRect(GetSheetRect()); + painter->setPen(pen); + painter->drawRect(GetSheetRect()); + } m_boundingRect = GetSheetRect(); } @@ -96,6 +102,18 @@ QRectF VPGraphicsSheet::GetMarginsRect() const return rect; } +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsSheet::SetShowMargin(bool value) +{ + m_showMargin = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsSheet::SetShowBorder(bool value) +{ + m_showBorder = value; +} + //--------------------------------------------------------------------------------------------------------------------- QRectF VPGraphicsSheet::boundingRect() const diff --git a/src/app/puzzle/vpgraphicssheet.h b/src/app/puzzle/vpgraphicssheet.h index 4ee8b4329..0cbef3a41 100644 --- a/src/app/puzzle/vpgraphicssheet.h +++ b/src/app/puzzle/vpgraphicssheet.h @@ -47,12 +47,28 @@ public: QRectF GetSheetRect() const; QRectF GetMarginsRect() const; + /** + * @brief ShowMargin Sets Wether we see the margin + * @param value true to show the margin + */ + void SetShowMargin(bool value); + + /** + * @brief ShowBorder Sets whether we see the border of the sheet + * @param value true to show the border + */ + void SetShowBorder(bool value); + + private: Q_DISABLE_COPY(VPGraphicsSheet) VPSheet *m_sheet{nullptr}; QRectF m_boundingRect; + + bool m_showMargin{true}; + bool m_showBorder{true}; }; #endif // VPGRAPHICSSHEET_H diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 1db306030..4c838f9fd 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -80,6 +80,24 @@ VMainGraphicsScene* VPMainGraphicsView::GetScene() return m_scene; } + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainGraphicsView::PrepareForExport() +{ + m_graphicsSheet->SetShowBorder(false); + m_graphicsSheet->SetShowMargin(false); + RefreshLayout(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainGraphicsView::CleanAfterExport() +{ + m_graphicsSheet->SetShowBorder(true); + m_graphicsSheet->SetShowMargin(true); + RefreshLayout(); +} + + //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event) { diff --git a/src/app/puzzle/vpmaingraphicsview.h b/src/app/puzzle/vpmaingraphicsview.h index fdea4efb6..94d52e1b5 100644 --- a/src/app/puzzle/vpmaingraphicsview.h +++ b/src/app/puzzle/vpmaingraphicsview.h @@ -55,6 +55,16 @@ public: */ VMainGraphicsScene* GetScene(); + /** + * @brief PrepareForExport prepares the graphic for an export (i.e hide margin etc) + */ + void PrepareForExport(); + + /** + * @brief CleanAfterExport cleans the graphic for an export (i.e show margin etc) + */ + void CleanAfterExport(); + protected: void dragEnterEvent(QDragEnterEvent *event) override; diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 5633b3602..65a110319 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -45,6 +45,7 @@ #include "vpsheet.h" #include +#include QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") @@ -993,14 +994,42 @@ void VPMainWindow::on_checkBoxSheetStickyEdges_toggled(bool checked) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_pushButtonSheetExport_clicked() { - // just for test purpuses, to be removed: - QMessageBox msgBox; - msgBox.setText("TODO VPMainWindow::on_pushButtonSheetExport_clicked"); - int ret = msgBox.exec(); + m_graphicsView->PrepareForExport(); - Q_UNUSED(ret); + // svg export to do some test for the first test - // TODO + QString dir = QDir::homePath(); + QString filters(tr("SVG Files") + QLatin1String("(*.svg)")); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), + dir + QLatin1String("/") + tr("Layout") + QLatin1String(".svg"), + filters, nullptr +#ifdef Q_OS_LINUX + , QFileDialog::DontUseNativeDialog +#endif + ); + + + + const QSizeF s = m_layout->GetFocusedSheet()->GetSheetSize(); + const QRectF r = QRectF(0, 0, s.width(), s.height()); + + QSvgGenerator generator; + generator.setFileName(fileName); + generator.setSize(QSize(qFloor(s.width()),qFloor(s.height()))); + generator.setViewBox(r); + generator.setTitle(tr("Pattern")); + 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, r, r, Qt::IgnoreAspectRatio); + painter.end(); + + m_graphicsView->CleanAfterExport(); } diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index ce6d166bb..43a40f07a 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 "vpcommandline.h" +#include "../vlayout/vlayoutdef.h" namespace Ui { @@ -216,6 +217,7 @@ private: bool MaybeSave(); + private slots: /** * @brief on_actionOpen_triggered When the menu action File > Open is