From a2b701f0835b58e5eddb0ff06dc9a8e45e99e35a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 10 Apr 2023 12:20:18 +0300 Subject: [PATCH] Show/hide grainline when export. Closes #163 --- ChangeLog.txt | 1 + .../puzzle/dialogs/dialogsavemanuallayout.cpp | 85 ++++++++++-- .../puzzle/dialogs/dialogsavemanuallayout.h | 3 + .../puzzle/dialogs/dialogsavemanuallayout.ui | 40 +++--- src/app/puzzle/scene/vpgraphicspiece.cpp | 71 +++++----- src/app/puzzle/scene/vpgraphicspiece.h | 5 +- src/app/puzzle/vpmainwindow.cpp | 41 +++--- src/app/puzzle/vpmainwindow.h | 2 +- src/app/puzzle/vpsettings.cpp | 13 ++ src/app/puzzle/vpsettings.h | 3 + .../valentina/dialogs/dialogsavelayout.cpp | 127 ++++++++++++++++-- src/app/valentina/dialogs/dialogsavelayout.h | 3 + src/app/valentina/dialogs/dialogsavelayout.ui | 17 ++- src/app/valentina/mainwindow.cpp | 2 +- src/app/valentina/mainwindowsnogui.cpp | 13 +- src/libs/vlayout/vgraphicsfillitem.cpp | 13 +- src/libs/vlayout/vgraphicsfillitem.h | 20 +++ src/libs/vlayout/vlayoutexporter.cpp | 94 +++++++++++-- src/libs/vlayout/vlayoutexporter.h | 21 +-- src/libs/vmisc/def.h | 6 + src/libs/vmisc/vvalentinasettings.cpp | 13 ++ src/libs/vmisc/vvalentinasettings.h | 3 + 22 files changed, 474 insertions(+), 122 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 293ac5215..27a922630 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -22,6 +22,7 @@ - Fix seam allowance. Loose requirements to case with prong. - Fix list of dimension popup list. Make sure it will always has enough space for values. - New grainline type: Four way. +- [smart-pattern/valentina#163] Show/hide grainline when export. # Valentina 0.7.52 September 12, 2022 - Fix crash when default locale is ru. diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp index 0ec51c6f6..4a7343609 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp @@ -250,6 +250,62 @@ auto DialogSaveManualLayout::IsBinaryDXFFormat() const -> bool } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSaveManualLayout::SetShowGrainline(bool show) +{ + switch(Format()) + { + case LayoutExportFormats::SVG: + case LayoutExportFormats::PDF: + case LayoutExportFormats::PNG: + case LayoutExportFormats::PS: + case LayoutExportFormats::EPS: + case LayoutExportFormats::PDFTiled: + case LayoutExportFormats::TIF: + 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: + ui->checkBoxShowGrainline->setChecked(show); + break; + default: + ui->checkBoxShowGrainline->setChecked(true); + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogSaveManualLayout::IsShowGrainline() const +{ + switch(Format()) + { + case LayoutExportFormats::SVG: + case LayoutExportFormats::PDF: + case LayoutExportFormats::PNG: + case LayoutExportFormats::PS: + case LayoutExportFormats::EPS: + case LayoutExportFormats::PDFTiled: + case LayoutExportFormats::TIF: + 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: + return ui->checkBoxShowGrainline->isChecked(); + default: + return true; + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSaveManualLayout::SetDestinationPath(const QString &cmdDestinationPath) { @@ -444,18 +500,10 @@ void DialogSaveManualLayout::ShowExample() ui->checkBoxTextAsPaths->setEnabled(true); ui->checkBoxExportUnified->setEnabled(false); ui->checkBoxTilesScheme->setEnabled(false); + ui->checkBoxShowGrainline->setEnabled(true); switch(currentFormat) { - 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: @@ -475,9 +523,11 @@ void DialogSaveManualLayout::ShowExample() case LayoutExportFormats::DXF_AC1024_ASTM: case LayoutExportFormats::DXF_AC1027_ASTM: ui->checkBoxBinaryDXF->setEnabled(true); + ui->checkBoxShowGrainline->setEnabled(false); break; case LayoutExportFormats::RLD: ui->checkBoxTextAsPaths->setEnabled(false); + ui->checkBoxShowGrainline->setEnabled(false); break; case LayoutExportFormats::PDFTiled: ui->checkBoxTilesScheme->setEnabled(true); @@ -488,10 +538,21 @@ void DialogSaveManualLayout::ShowExample() case LayoutExportFormats::EPS: ui->checkBoxExportUnified->setEnabled(true); break; + case LayoutExportFormats::NC: + case LayoutExportFormats::OBJ: + ui->checkBoxShowGrainline->setEnabled(false); + break; + 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::SVG: case LayoutExportFormats::PNG: - case LayoutExportFormats::OBJ: - case LayoutExportFormats::NC: case LayoutExportFormats::TIF: default: break; @@ -580,6 +641,7 @@ void DialogSaveManualLayout::ReadSettings() { VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); SelectFormat(static_cast(settings->GetLayoutExportFormat())); + SetShowGrainline(settings->GetShowGrainline()); } //--------------------------------------------------------------------------------------------------------------------- @@ -592,4 +654,5 @@ void DialogSaveManualLayout::WriteSettings() const VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); settings->SetLayoutExportFormat(static_cast(Format())); + settings->SetShowGrainline(IsShowGrainline()); } diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.h b/src/app/puzzle/dialogs/dialogsavemanuallayout.h index 116100a4f..ed57ed45d 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.h +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.h @@ -54,6 +54,9 @@ public: void SetBinaryDXFFormat(bool binary); auto IsBinaryDXFFormat() const -> bool; + void SetShowGrainline(bool show); + auto IsShowGrainline() const -> bool; + void SetDestinationPath(const QString& cmdDestinationPath); auto IsTextAsPaths() const -> bool; diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.ui b/src/app/puzzle/dialogs/dialogsavemanuallayout.ui index d912c7a6a..cc88ed70c 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.ui +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.ui @@ -7,7 +7,7 @@ 0 0 413 - 310 + 293 @@ -111,8 +111,8 @@ Options - - + + false @@ -122,17 +122,7 @@ - - - - true - - - Text as paths - - - - + false @@ -145,7 +135,27 @@ - + + + + Show grainline + + + true + + + + + + + true + + + Text as paths + + + + false diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index bace17670..3cc8105a3 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -43,6 +43,7 @@ #include "../layout/vplayout.h" #include "../layout/vpsheet.h" #include "../vlayout/vtextmanager.h" +#include "../vlayout/vgraphicsfillitem.h" #include "../vpapplication.h" @@ -167,6 +168,7 @@ VPGraphicsPiece::VPGraphicsPiece(const VPPiecePtr &piece, QGraphicsItem *parent) PaintPiece(); InitLabels(); + InitGrainlineItem(); } //--------------------------------------------------------------------------------------------------------------------- @@ -181,7 +183,6 @@ auto VPGraphicsPiece::boundingRect() const -> QRectF QPainterPath shape; shape.addPath(m_seamLine); shape.addPath(m_cuttingLine); - shape.addPath(m_grainline); shape.addPath(m_internalPaths); shape.addPath(m_passmarks); shape.addPath(m_placeLabels); @@ -451,12 +452,45 @@ void VPGraphicsPiece::InitPieceLabel(const QVector &labelShape, const V } } +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsPiece::InitGrainlineItem() +{ + delete m_grainlineItem; + + VPPiecePtr piece = m_piece.toStrongRef(); + if (piece.isNull()) + { + return; + } + + if(piece->IsGrainlineEnabled()) + { + QPainterPath grainline; + QVector grainLinepoints = piece->GetMappedGrainline(); + if(!grainLinepoints.isEmpty()) + { + grainline.moveTo(ConstFirst(grainLinepoints)); + for (int i = 1; i < grainLinepoints.size(); i++) + { + grainline.lineTo(grainLinepoints.at(i)); + } + } + + m_grainlineItem = new VGraphicsFillItem(this); + m_grainlineItem->setPath(grainline); + + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + QPen pen(PieceColor(), settings->GetLayoutLineWidth(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + m_grainlineItem->SetCustomPen(true); + m_grainlineItem->setPen(pen); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsPiece::PaintPiece(QPainter *painter) { m_seamLine = QPainterPath(); m_cuttingLine = QPainterPath(); - m_grainline = QPainterPath(); m_internalPaths = QPainterPath(); m_passmarks = QPainterPath(); m_placeLabels = QPainterPath(); @@ -474,9 +508,6 @@ void VPGraphicsPiece::PaintPiece(QPainter *painter) // initiliases the cutting line PaintCuttingLine(painter, piece); - // initialises the grainline - PaintGrainline(painter, piece); - // initialises the internal paths PaintInternalPaths(painter, piece); @@ -539,35 +570,6 @@ void VPGraphicsPiece::PaintCuttingLine(QPainter *painter, const VPPiecePtr &piec } } -//--------------------------------------------------------------------------------------------------------------------- -void VPGraphicsPiece::PaintGrainline(QPainter *painter, const VPPiecePtr &piece) -{ - if(piece->IsGrainlineEnabled()) - { - QVector grainLinepoints = piece->GetMappedGrainline(); - if(!grainLinepoints.isEmpty()) - { - m_grainline.moveTo(ConstFirst(grainLinepoints)); - for (int i = 1; i < grainLinepoints.size(); i++) - { - m_grainline.lineTo(grainLinepoints.at(i)); - } - - if (painter != nullptr) - { - painter->save(); - // here to fill the grainlines arrow. Not wanted for mvp - // later maybe if it's configurable - // painter->setBrush(blackBrush); - - painter->setBrush(NoBrush()); - painter->drawPath(m_grainline); - painter->restore(); - } - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsPiece::PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece) { @@ -790,6 +792,7 @@ void VPGraphicsPiece::on_RefreshPiece(const VPPiecePtr &piece) prepareGeometryChange(); PaintPiece(); // refresh shapes InitLabels(); + InitGrainlineItem(); emit PieceTransformationChanged(); } } diff --git a/src/app/puzzle/scene/vpgraphicspiece.h b/src/app/puzzle/scene/vpgraphicspiece.h index fca20b39a..6c650808b 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.h +++ b/src/app/puzzle/scene/vpgraphicspiece.h @@ -40,6 +40,7 @@ #endif // QT_VERSION < QT_VERSION_CHECK(5, 13, 0) class VTextManager; +class VGraphicsFillItem; class VPGraphicsPiece : public QGraphicsObject { @@ -92,7 +93,6 @@ private: QPainterPath m_cuttingLine{}; QPainterPath m_seamLine{}; - QPainterPath m_grainline{}; QPainterPath m_internalPaths{}; QPainterPath m_passmarks{}; QPainterPath m_placeLabels{}; @@ -113,15 +113,16 @@ private: bool m_hoverMode{false}; + VGraphicsFillItem *m_grainlineItem{nullptr}; QVector m_labelPathItems{}; QVector m_labelTextItems{}; void InitLabels(); void InitPieceLabel(const QVector &labelShape, const VTextManager &tm); + void InitGrainlineItem(); void PaintPiece(QPainter *painter=nullptr); void PaintSeamLine(QPainter *painter, const VPPiecePtr &piece); void PaintCuttingLine(QPainter *painter, const VPPiecePtr &piece); - void PaintGrainline(QPainter *painter, const VPPiecePtr &piece); void PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece); void PaintPassmarks(QPainter *painter, const VPPiecePtr &piece); void PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece); diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 159cc9d1d..356ce41d3 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -293,6 +293,7 @@ struct VPExportData bool textAsPaths{false}; bool exportUnified{true}; bool showTilesScheme{false}; + bool showGrainline{true}; }; //--------------------------------------------------------------------------------------------------------------------- @@ -2376,6 +2377,7 @@ void VPMainWindow::ExportScene(const VPExportData &data) exporter.SetYScale(data.yScale); exporter.SetDescription(m_layout->LayoutSettings().GetDescription()); exporter.SetBinaryDxfFormat(data.isBinaryDXF); + exporter.SetShowGrainline(data.showGrainline); QList sheets = data.sheets; @@ -2413,17 +2415,17 @@ void VPMainWindow::ExportScene(const VPExportData &data) case LayoutExportFormats::SVG: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToSVG(sheet->SceneData()->Scene()); + exporter.ExportToSVG(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems()); break; case LayoutExportFormats::PDF: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToPDF(sheet->SceneData()->Scene()); + exporter.ExportToPDF(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems()); break; case LayoutExportFormats::PNG: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToPNG(sheet->SceneData()->Scene()); + exporter.ExportToPNG(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems()); break; case LayoutExportFormats::OBJ: exporter.ExportToOBJ(sheet->SceneData()->Scene()); @@ -2431,12 +2433,12 @@ void VPMainWindow::ExportScene(const VPExportData &data) case LayoutExportFormats::PS: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToPS(sheet->SceneData()->Scene()); + exporter.ExportToPS(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems()); break; case LayoutExportFormats::EPS: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToEPS(sheet->SceneData()->Scene()); + exporter.ExportToEPS(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems()); break; case LayoutExportFormats::DXF_AC1006_Flat: exporter.SetDxfVersion(DRW::AC1006); @@ -2477,7 +2479,7 @@ void VPMainWindow::ExportScene(const VPExportData &data) case LayoutExportFormats::TIF: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToTIF(sheet->SceneData()->Scene()); + exporter.ExportToTIF(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems()); break; default: qDebug() << "Can't recognize file type." << Q_FUNC_INFO; @@ -2565,11 +2567,12 @@ void VPMainWindow::GenerateUnifiedPdfFile(const VPExportData &data, const QStrin } } - sheet->SceneData()->PrepareForExport(); + sheet->SceneData()->PrepareForExport(); // Go first because recreates pieces + VLayoutExporter::PrepareGrainlineForExport(sheet->SceneData()->GraphicsPiecesAsItems(), data.showGrainline); QRectF imageRect = sheet->GetMarginsRect(); sheet->SceneData()->Scene()->render(&painter, VPrintLayout::SceneTargetRect(printer.data(), imageRect), imageRect, Qt::IgnoreAspectRatio); - sheet->SceneData()->CleanAfterExport(); + sheet->SceneData()->CleanAfterExport(); // Will restore the grainlines automatically firstPage = false; } @@ -2602,7 +2605,7 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data) bool firstPage = true; for (const auto& sheet : data.sheets) { - if (not GeneratePdfTiledFile(sheet, data.showTilesScheme, &painter, printer, firstPage)) + if (not GeneratePdfTiledFile(sheet, data.showTilesScheme, data.showGrainline, &painter, printer, firstPage)) { break; } @@ -2620,7 +2623,8 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data) QPainter painter; bool firstPage = true; - if (not GeneratePdfTiledFile(data.sheets.at(i), data.showTilesScheme, &painter, printer, firstPage)) + if (not GeneratePdfTiledFile(data.sheets.at(i), data.showTilesScheme, data.showGrainline, &painter, printer, + firstPage)) { break; } @@ -2629,18 +2633,25 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data) } //--------------------------------------------------------------------------------------------------------------------- -auto VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, QPainter *painter, - const QSharedPointer &printer, bool &firstPage) -> bool +auto VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, bool showGrainline, + QPainter *painter, const QSharedPointer &printer, + bool &firstPage) -> bool { SCASSERT(not sheet.isNull()) SCASSERT(painter != nullptr) SCASSERT(not printer.isNull()) - sheet->SceneData()->PrepareForExport(); + sheet->SceneData()->PrepareForExport(); // Go first because recreates pieces + VLayoutExporter::PrepareGrainlineForExport(sheet->SceneData()->GraphicsPiecesAsItems(), showGrainline); m_layout->TileFactory()->RefreshTileInfos(); m_layout->TileFactory()->RefreshWatermarkData(); sheet->SceneData()->SetTextAsPaths(false); + auto Clean = qScopeGuard([sheet]() + { + sheet->SceneData()->CleanAfterExport(); // Will restore the grainlines automatically + }); + if (showTilesScheme) { SetPrinterTiledPageSettings(printer, m_layout, sheet, sheet->GetSheetOrientation(), true); @@ -2695,8 +2706,6 @@ auto VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesS } } - sheet->SceneData()->CleanAfterExport(); - return true; } @@ -4144,6 +4153,7 @@ void VPMainWindow::on_ExportLayout() data.textAsPaths = dialog.IsTextAsPaths(); data.exportUnified = dialog.IsExportUnified(); data.showTilesScheme = dialog.IsTilesScheme(); + data.showGrainline = dialog.IsShowGrainline(); ExportData(data); } @@ -4194,6 +4204,7 @@ void VPMainWindow::on_ExportSheet() data.textAsPaths = dialog.IsTextAsPaths(); data.exportUnified = dialog.IsExportUnified(); data.showTilesScheme = dialog.IsTilesScheme(); + data.showGrainline = dialog.IsShowGrainline(); ExportData(data); } diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index b41ad5d79..6cfec2ae5 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -479,7 +479,7 @@ private: static void ExportUnifiedPdfFile(const VPExportData &data); static void GenerateUnifiedPdfFile(const VPExportData &data, const QString &name); void ExportPdfTiledFile(const VPExportData &data); - auto GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, QPainter *painter, + auto GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, bool showGrainline, QPainter *painter, const QSharedPointer &printer, bool &firstPage) -> bool; void UpdateScaleConnection() const; diff --git a/src/app/puzzle/vpsettings.cpp b/src/app/puzzle/vpsettings.cpp index ee5023ada..296346272 100644 --- a/src/app/puzzle/vpsettings.cpp +++ b/src/app/puzzle/vpsettings.cpp @@ -54,6 +54,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutFollowGrainline, (QLatin1S Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPieceGap, (QLatin1String("layout/pieceGap"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutExportFormat, (QLatin1String("layout/exportFormat"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutLineWidth, (QLatin1String("layout/lineWidth"))) // NOLINT +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutShowGrainline, (QLatin1String("layout/showGrainline"))) // NOLINT int cachedLineWidth = -1; } // namespace @@ -340,3 +341,15 @@ void VPSettings::SetLayoutLineWidth(int width) cachedLineWidth = qBound(1, width, 10); setValue(*settingLayoutLineWidth, cachedLineWidth); } + +//--------------------------------------------------------------------------------------------------------------------- +bool VPSettings::GetShowGrainline() const +{ + return value(*settingLayoutShowGrainline, true).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSettings::SetShowGrainline(bool value) +{ + setValue(*settingLayoutShowGrainline, value); +} diff --git a/src/app/puzzle/vpsettings.h b/src/app/puzzle/vpsettings.h index 873f786e0..3ebb40b1a 100644 --- a/src/app/puzzle/vpsettings.h +++ b/src/app/puzzle/vpsettings.h @@ -103,6 +103,9 @@ public: auto GetLayoutLineWidth() const -> int; void SetLayoutLineWidth(int width); + bool GetShowGrainline() const; + void SetShowGrainline(bool value); + private: Q_DISABLE_COPY_MOVE(VPSettings) // NOLINT }; diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index c6cc22678..9173a7622 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -277,6 +277,104 @@ auto DialogSaveLayout::IsBinaryDXFFormat() const -> bool } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSaveLayout::SetShowGrainline(bool show) +{ + switch(Format()) + { + 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::SVG: + case LayoutExportFormats::PDF: + case LayoutExportFormats::PDFTiled: + case LayoutExportFormats::PNG: + case LayoutExportFormats::PS: + case LayoutExportFormats::EPS: + case LayoutExportFormats::TIF: + ui->checkBoxShowGrainline->setChecked(show); + break; + 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: + case LayoutExportFormats::RLD: + case LayoutExportFormats::NC: + case LayoutExportFormats::OBJ: + default: + ui->checkBoxShowGrainline->setChecked(true); + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +auto DialogSaveLayout::IsShowGrainline() const -> bool +{ + switch(Format()) + { + 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::SVG: + case LayoutExportFormats::PDF: + case LayoutExportFormats::PDFTiled: + case LayoutExportFormats::PNG: + case LayoutExportFormats::PS: + case LayoutExportFormats::EPS: + case LayoutExportFormats::TIF: + return ui->checkBoxShowGrainline->isChecked(); + 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: + case LayoutExportFormats::RLD: + case LayoutExportFormats::NC: + case LayoutExportFormats::OBJ: + default: + return true; + } +} + //--------------------------------------------------------------------------------------------------------------------- auto DialogSaveLayout::MakeHelpFormatList() -> QString { @@ -414,18 +512,10 @@ void DialogSaveLayout::ShowExample() ui->groupBoxPaperFormat->setEnabled(false); ui->groupBoxMargins->setEnabled(false); ui->checkBoxTextAsPaths->setEnabled(true); + ui->checkBoxShowGrainline->setEnabled(m_mode == Draw::Layout); switch(currentFormat) { - 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: @@ -445,6 +535,7 @@ void DialogSaveLayout::ShowExample() case LayoutExportFormats::DXF_AC1024_ASTM: case LayoutExportFormats::DXF_AC1027_ASTM: ui->checkBoxBinaryDXF->setEnabled(true); + ui->checkBoxShowGrainline->setEnabled(false); break; case LayoutExportFormats::PDFTiled: ui->groupBoxPaperFormat->setEnabled(true); @@ -452,14 +543,26 @@ void DialogSaveLayout::ShowExample() break; case LayoutExportFormats::RLD: ui->checkBoxTextAsPaths->setEnabled(false); + ui->checkBoxShowGrainline->setEnabled(false); break; + case LayoutExportFormats::NC: + case LayoutExportFormats::OBJ: + ui->checkBoxShowGrainline->setEnabled(false); + break; + 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::SVG: case LayoutExportFormats::PDF: case LayoutExportFormats::PNG: - case LayoutExportFormats::OBJ: case LayoutExportFormats::PS: case LayoutExportFormats::EPS: - case LayoutExportFormats::NC: case LayoutExportFormats::TIF: default: break; @@ -768,6 +871,7 @@ void DialogSaveLayout::ReadSettings() else { SelectFormat(static_cast(settings->GetLayoutExportFormat())); + SetShowGrainline(settings->GetShowGrainline()); } } @@ -819,6 +923,7 @@ void DialogSaveLayout::WriteSettings() const else { settings->SetLayoutExportFormat(static_cast(Format())); + settings->SetShowGrainline(IsShowGrainline()); } } diff --git a/src/app/valentina/dialogs/dialogsavelayout.h b/src/app/valentina/dialogs/dialogsavelayout.h index ee196f8bb..21b5e1d4d 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.h +++ b/src/app/valentina/dialogs/dialogsavelayout.h @@ -56,6 +56,9 @@ public: void SetBinaryDXFFormat(bool binary); auto IsBinaryDXFFormat() const -> bool; + void SetShowGrainline(bool show); + auto IsShowGrainline() const -> bool; + static auto MakeHelpFormatList() -> QString; void SetDestinationPath(const QString& cmdDestinationPath); diff --git a/src/app/valentina/dialogs/dialogsavelayout.ui b/src/app/valentina/dialogs/dialogsavelayout.ui index 7d648eee7..0301226c0 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.ui +++ b/src/app/valentina/dialogs/dialogsavelayout.ui @@ -6,8 +6,8 @@ 0 0 - 493 - 391 + 544 + 401 @@ -129,6 +129,19 @@ + + + + true + + + Show grainline + + + true + + + diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index bae7a8329..7bdab8f8a 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -2523,7 +2523,7 @@ void MainWindow::ExportDraw(const QString &fileName) exporter.SetImageRect(rect); exporter.SetOffset(rect.topLeft()); // Correct positions to fit SVG view rect - exporter.ExportToSVG(m_sceneDraw); + exporter.ExportToSVG(m_sceneDraw, QList()); m_sceneDraw->SetOriginsVisible(true); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 89b2613f4..56707b7fe 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -1116,6 +1116,7 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, exporter.SetDescription(doc->GetDescription().toHtmlEscaped()); exporter.SetIgnorePrinterMargins(ignorePrinterFields); exporter.SetBinaryDxfFormat(m_dialogSaveLayout->IsBinaryDXFFormat()); + exporter.SetShowGrainline(m_dialogSaveLayout->IsShowGrainline()); for (int i=0; i < scenes.size(); ++i) { @@ -1141,18 +1142,18 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, paper->setVisible(false); exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToSVG(scene); + exporter.ExportToSVG(scene, details.at(i)); paper->setVisible(true); break; case LayoutExportFormats::PDF: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToPDF(scene); + exporter.ExportToPDF(scene, details.at(i)); break; case LayoutExportFormats::PNG: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToPNG(scene); + exporter.ExportToPNG(scene, details.at(i)); break; case LayoutExportFormats::OBJ: paper->setVisible(false); @@ -1162,12 +1163,12 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, case LayoutExportFormats::PS: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToPS(scene); + exporter.ExportToPS(scene, details.at(i)); break; case LayoutExportFormats::EPS: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToEPS(scene); + exporter.ExportToEPS(scene, details.at(i)); break; case LayoutExportFormats::DXF_AC1006_Flat: paper->setVisible(false); @@ -1226,7 +1227,7 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, case LayoutExportFormats::TIF: exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - exporter.ExportToTIF(scene); + exporter.ExportToTIF(scene, details.at(i)); break; default: qDebug() << "Can't recognize file type." << Q_FUNC_INFO; diff --git a/src/libs/vlayout/vgraphicsfillitem.cpp b/src/libs/vlayout/vgraphicsfillitem.cpp index 7fb676f36..8520c2a1f 100644 --- a/src/libs/vlayout/vgraphicsfillitem.cpp +++ b/src/libs/vlayout/vgraphicsfillitem.cpp @@ -44,8 +44,17 @@ void VGraphicsFillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* Q_UNUSED(widget) painter->save(); - QPen pen = painter->pen(); - pen.setWidthF(width); + QPen pen; + + if (m_customPen) + { + pen = this->pen(); + } + else + { + pen = painter->pen(); + pen.setWidthF(width); + } painter->setPen(pen); painter->setBrush(painter->pen().color()); diff --git a/src/libs/vlayout/vgraphicsfillitem.h b/src/libs/vlayout/vgraphicsfillitem.h index 60aee1a37..06b43c605 100644 --- a/src/libs/vlayout/vgraphicsfillitem.h +++ b/src/libs/vlayout/vgraphicsfillitem.h @@ -32,6 +32,8 @@ #include #include +#include "../vmisc/def.h" + class VGraphicsFillItem : public QGraphicsPathItem { public: @@ -51,11 +53,18 @@ public: */ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + int type() const override {return Type;} + enum { Type = UserType + static_cast(Layout::GrainlineItem)}; + auto GetWidth() const -> qreal; void SetWidth(const qreal &value); + auto CustomPen() const -> bool; + void SetCustomPen(bool newCustomPen); + private: qreal width{1}; + bool m_customPen{false}; }; //--------------------------------------------------------------------------------------------------------------------- @@ -70,4 +79,15 @@ inline void VGraphicsFillItem::SetWidth(const qreal &value) width = value; } +//--------------------------------------------------------------------------------------------------------------------- +inline auto VGraphicsFillItem::CustomPen() const -> bool +{ + return m_customPen; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VGraphicsFillItem::SetCustomPen(bool newCustomPen) +{ + m_customPen = newCustomPen; +} #endif // VGRAPHICSFILLITEM_H diff --git a/src/libs/vlayout/vlayoutexporter.cpp b/src/libs/vlayout/vlayoutexporter.cpp index e7fed9a8d..5cfeced80 100644 --- a/src/libs/vlayout/vlayoutexporter.cpp +++ b/src/libs/vlayout/vlayoutexporter.cpp @@ -49,6 +49,7 @@ #include "../vmisc/vabstractvalapplication.h" #include "../ifc/exception/vexception.h" #include "vprintlayout.h" +#include "vgraphicsfillitem.h" namespace { @@ -67,7 +68,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, PDFTOPS, (QLatin1String("pdftops"))) // * * @param placeholder placeholder that will be appended to each QGraphicsSimpleTextItem item's text string. */ -void PrepareTextForDXF(const QString &placeholder, const QList &paperItems) +void PrepareDetailsForDXF(const QString &placeholder, const QList &paperItems) { for (auto *item : paperItems) { @@ -94,7 +95,7 @@ void PrepareTextForDXF(const QString &placeholder, const QList * * @param placeholder placeholder that will be removed from each QGraphicsSimpleTextItem item's text string. */ -void RestoreTextAfterDXF(const QString &placeholder, const QList &paperItems) +void RestoreDetailsAfterDXF(const QString &placeholder, const QList &paperItems) { for (auto *item : paperItems) { @@ -116,8 +117,22 @@ void RestoreTextAfterDXF(const QString &placeholder, const QList bool { + return m_showGrainline; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::SetShowGrainline(bool show) +{ + m_showGrainline = show; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToSVG(QGraphicsScene *scene, const QList &details) const +{ + PrepareGrainlineForExport(details, m_showGrainline); + QSvgGenerator generator; generator.setFileName(m_fileName); @@ -145,11 +160,15 @@ void VLayoutExporter::ExportToSVG(QGraphicsScene *scene) const painter.scale(m_xScale, m_yScale); scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); painter.end(); + + RestoreGrainlineAfterExport(details); } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutExporter::ExportToPNG(QGraphicsScene *scene) const +void VLayoutExporter::ExportToPNG(QGraphicsScene *scene, const QList &details) const { + PrepareGrainlineForExport(details, m_showGrainline); + // Create the image with the exact size of the shrunk scene QSize drawingSize; drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right())); @@ -167,11 +186,15 @@ void VLayoutExporter::ExportToPNG(QGraphicsScene *scene) const scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); image.save(m_fileName); + + RestoreGrainlineAfterExport(details); } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutExporter::ExportToTIF(QGraphicsScene *scene) const +void VLayoutExporter::ExportToTIF(QGraphicsScene *scene, const QList &details) const { + PrepareGrainlineForExport(details, m_showGrainline); + // Create the image with the exact size of the shrunk scene QSize drawingSize; drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right())); @@ -197,14 +220,17 @@ void VLayoutExporter::ExportToTIF(QGraphicsScene *scene) const if (not writer.write(image)) { // failed to save file qCritical() << qUtf8Printable(tr("Can't save file '%1'. Error: %2.").arg(m_fileName, writer.errorString())); + RestoreGrainlineAfterExport(details); return; } + + RestoreGrainlineAfterExport(details); } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutExporter::ExportToPDF(QGraphicsScene *scene) const +void VLayoutExporter::ExportToPDF(QGraphicsScene *scene, const QList &details) const { - ExportToPDF(scene, m_fileName); + ExportToPDF(scene, details, m_fileName); } //--------------------------------------------------------------------------------------------------------------------- @@ -222,25 +248,25 @@ void VLayoutExporter::ExportToOBJ(QGraphicsScene *scene) const } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutExporter::ExportToPS(QGraphicsScene *scene) const +void VLayoutExporter::ExportToPS(QGraphicsScene *scene, const QList &details) const { QTemporaryFile tmp; if (tmp.open()) { const QString fileName = m_fileName; - ExportToPDF(scene, tmp.fileName()); + ExportToPDF(scene, details, tmp.fileName()); PdfToPs(QStringList{tmp.fileName(), fileName}); } } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutExporter::ExportToEPS(QGraphicsScene *scene) const +void VLayoutExporter::ExportToEPS(QGraphicsScene *scene, const QList &details) const { QTemporaryFile tmp; if (tmp.open()) { const QString fileName = m_fileName; - ExportToPDF(scene, tmp.fileName()); + ExportToPDF(scene, details, tmp.fileName()); PdfToPs(QStringList{QStringLiteral("-eps"), tmp.fileName(), fileName}); } } @@ -248,7 +274,8 @@ void VLayoutExporter::ExportToEPS(QGraphicsScene *scene) const //--------------------------------------------------------------------------------------------------------------------- void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList &details) const { - PrepareTextForDXF(endStringPlaceholder, details); + PrepareDetailsForDXF(endStringPlaceholder, details); + PrepareGrainlineForExport(details, m_showGrainline); VDxfPaintDevice generator; generator.SetFileName(m_fileName); @@ -270,7 +297,8 @@ void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList &details, + const QString &filename) const { + PrepareGrainlineForExport(details, m_showGrainline); + QPrinter printer; printer.setCreator(QGuiApplication::applicationDisplayName() + QChar(QChar::Space) + QCoreApplication::applicationVersion()); @@ -453,6 +484,7 @@ void VLayoutExporter::ExportToPDF(QGraphicsScene *scene, const QString &filename if (not painter.begin(&printer)) { // failed to open file qCritical() << qUtf8Printable(tr("Can't open file '%1'").arg(m_fileName)); + RestoreGrainlineAfterExport(details); return; } painter.setRenderHint(QPainter::Antialiasing, true); @@ -461,6 +493,8 @@ void VLayoutExporter::ExportToPDF(QGraphicsScene *scene, const QString &filename painter.scale(m_xScale, m_yScale); scene->render(&painter, VPrintLayout::SceneTargetRect(&printer, m_imageRect), m_imageRect, Qt::IgnoreAspectRatio); painter.end(); + + RestoreGrainlineAfterExport(details); } //--------------------------------------------------------------------------------------------------------------------- @@ -607,3 +641,35 @@ QString VLayoutExporter::ExportFormatSuffix(LayoutExportFormats format) return QString(); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::PrepareGrainlineForExport(const QList &items, bool showGrainline) +{ + for (auto *item : items) + { + QList pieceChildren = item->childItems(); + for (auto *child : qAsConst(pieceChildren)) + { + if (child->type() == VGraphicsFillItem::Type) + { + child->setVisible(showGrainline); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::RestoreGrainlineAfterExport(const QList &items) +{ + for (auto *item : items) + { + QList pieceChildren = item->childItems(); + for (auto *child : qAsConst(pieceChildren)) + { + if (child->type() == VGraphicsFillItem::Type) + { + child->setVisible(true); + } + } + } +} diff --git a/src/libs/vlayout/vlayoutexporter.h b/src/libs/vlayout/vlayoutexporter.h index e5348a37a..f0fc78c85 100644 --- a/src/libs/vlayout/vlayoutexporter.h +++ b/src/libs/vlayout/vlayoutexporter.h @@ -76,16 +76,19 @@ public: auto BinaryDxfFormat() const -> bool; void SetBinaryDxfFormat(bool binaryFormat); + auto IsShowGrainline() const -> bool; + void SetShowGrainline(bool show); + auto DxfVersion() const -> int; void SetDxfVersion(int dxfVersion); - void ExportToSVG(QGraphicsScene *scene) const; - void ExportToPNG(QGraphicsScene *scene) const; - void ExportToTIF(QGraphicsScene *scene) const; - void ExportToPDF(QGraphicsScene *scene) const; + void ExportToSVG(QGraphicsScene *scene, const QList &details) const; + void ExportToPNG(QGraphicsScene *scene, const QList &details) const; + void ExportToTIF(QGraphicsScene *scene, const QList &details) const; + void ExportToPDF(QGraphicsScene *scene, const QList &details) const; void ExportToOBJ(QGraphicsScene *scene) const; - void ExportToPS(QGraphicsScene *scene) const; - void ExportToEPS(QGraphicsScene *scene) const; + void ExportToPS(QGraphicsScene *scene, const QList &details) const; + void ExportToEPS(QGraphicsScene *scene, const QList &details) const; void ExportToFlatDXF(QGraphicsScene *scene, const QList &details) const; void ExportToAAMADXF(const QVector &details) const; void ExportToASTMDXF(const QVector &details) const; @@ -93,10 +96,11 @@ public: static auto SupportPDFConversion() -> bool; - static QString ExportFormatDescription(LayoutExportFormats format); static QString ExportFormatSuffix(LayoutExportFormats format); static void PdfToPs(const QStringList ¶ms); + static void PrepareGrainlineForExport(const QList &items, bool showGrainline); + static void RestoreGrainlineAfterExport(const QList &items); auto offset() const -> QPointF; void SetOffset(const QPointF &newOffset); @@ -112,10 +116,11 @@ private: QPen m_pen{}; bool m_ignorePrinterMargins{false}; bool m_binaryDxfFormat{false}; + bool m_showGrainline{true}; int m_dxfVersion{0}; QPointF m_offset{}; - void ExportToPDF(QGraphicsScene *scene, const QString &filename) const; + void ExportToPDF(QGraphicsScene *scene, const QList &details, const QString &filename) const; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index f60e21ac1..22e57f9f4 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -274,6 +274,12 @@ enum class Vis : ToolVisHolderType LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; +enum class Layout : ToolVisHolderType +{ + GrainlineItem = static_cast(Vis::LAST_ONE_DO_NOT_USE), + LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used +}; + enum class VarType : qint8 { Measurement, MeasurementSeparator, Increment, IncrementSeparator, LineLength, CurveLength, CurveCLength, LineAngle, CurveAngle, ArcRadius, PieceExternalArea, PieceSeamLineArea, Unknown }; diff --git a/src/libs/vmisc/vvalentinasettings.cpp b/src/libs/vmisc/vvalentinasettings.cpp index 7806290f1..53f7223f3 100644 --- a/src/libs/vmisc/vvalentinasettings.cpp +++ b/src/libs/vmisc/vvalentinasettings.cpp @@ -77,6 +77,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSaveLength, (QLatin1String Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPreferOneSheetSolution, // NOLINT (QLatin1String("layout/preferOneSheetSolution"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutUnitePages, (QLatin1String("layout/unitePages"))) // NOLINT +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutShowGrainline, (QLatin1String("layout/showGrainline"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFields, (QLatin1String("layout/fields"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingIgnoreFields, (QLatin1String("layout/ignoreFields"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingStripOptimization, (QLatin1String("layout/stripOptimization"))) // NOLINT @@ -971,6 +972,18 @@ void VValentinaSettings::SetBackgroundImageDefOpacity(int value) setValue(*settingPatternBackgroundImageDefOpacity, qBound(0, value, 100)); } +//--------------------------------------------------------------------------------------------------------------------- +bool VValentinaSettings::GetShowGrainline() const +{ + return value(*settingLayoutShowGrainline, true).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetShowGrainline(bool value) +{ + setValue(*settingLayoutShowGrainline, value); +} + //--------------------------------------------------------------------------------------------------------------------- template T VValentinaSettings::GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const diff --git a/src/libs/vmisc/vvalentinasettings.h b/src/libs/vmisc/vvalentinasettings.h index c8c830c18..c27ccd4b9 100644 --- a/src/libs/vmisc/vvalentinasettings.h +++ b/src/libs/vmisc/vvalentinasettings.h @@ -235,6 +235,9 @@ public: auto GetBackgroundImageDefOpacity() const -> int; void SetBackgroundImageDefOpacity(int value); + bool GetShowGrainline() const; + void SetShowGrainline(bool value); + private: Q_DISABLE_COPY_MOVE(VValentinaSettings) // NOLINT