From b71253738cc25c18ef499b1061e41617374e186a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 6 Sep 2021 16:56:56 +0300 Subject: [PATCH] Correct scale when export tiled PDF. --- .../puzzle/dialogs/dialogsavemanuallayout.cpp | 80 +------- .../puzzle/dialogs/dialogsavemanuallayout.h | 15 +- .../puzzle/dialogs/dialogsavemanuallayout.ui | 170 ++--------------- src/app/puzzle/layout/vplayoutsettings.cpp | 24 +++ src/app/puzzle/layout/vplayoutsettings.h | 9 + src/app/puzzle/scene/vpgraphicstilegrid.cpp | 34 ++-- src/app/puzzle/vpmainwindow.cpp | 94 +++++++++- src/app/puzzle/vpmainwindow.h | 4 + src/app/puzzle/vpmainwindow.ui | 177 +++++++++++++++++- src/app/puzzle/vptilefactory.cpp | 37 +++- src/app/puzzle/xml/vplayoutfilereader.cpp | 19 +- src/app/puzzle/xml/vplayoutfilereader.h | 1 + src/app/puzzle/xml/vplayoutfilewriter.cpp | 5 + src/app/puzzle/xml/vplayoutliterals.cpp | 3 + src/app/puzzle/xml/vplayoutliterals.h | 3 + src/libs/ifc/schema/layout/v0.1.0.xsd | 12 ++ 16 files changed, 414 insertions(+), 273 deletions(-) diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp index 53396e896..52a23e571 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp @@ -126,13 +126,6 @@ DialogSaveManualLayout::DialogSaveManualLayout(int count, bool consoleExport, co ui->lineEditPath->setText(VPApplication::VApp()->PuzzleSettings()->GetPathManualLayouts()); - connect(ui->toolButtonScaleConnected, &QToolButton::clicked, this, &DialogSaveManualLayout::ToggleScaleConnection); - - connect(ui->doubleSpinBoxHorizontalScale, QOverload::of(&QDoubleSpinBox::valueChanged), - this, &DialogSaveManualLayout::HorizontalScaleChanged); - connect(ui->doubleSpinBoxVerticalScale, QOverload::of(&QDoubleSpinBox::valueChanged), - this, &DialogSaveManualLayout::VerticalScaleChanged); - ReadSettings(); ShowExample();//Show example for current format. @@ -145,19 +138,19 @@ DialogSaveManualLayout::~DialogSaveManualLayout() } //--------------------------------------------------------------------------------------------------------------------- -QString DialogSaveManualLayout::Path() const +auto DialogSaveManualLayout::Path() const -> QString { return ui->lineEditPath->text(); } //--------------------------------------------------------------------------------------------------------------------- -QString DialogSaveManualLayout::FileName() const +auto DialogSaveManualLayout::FileName() const -> QString { return ui->lineEditFileName->text(); } //--------------------------------------------------------------------------------------------------------------------- -LayoutExportFormats DialogSaveManualLayout::Format() const +auto DialogSaveManualLayout::Format() const -> LayoutExportFormats { return static_cast(ui->comboBoxFormat->currentData().toInt()); } @@ -229,7 +222,7 @@ void DialogSaveManualLayout::SetBinaryDXFFormat(bool binary) } //--------------------------------------------------------------------------------------------------------------------- -bool DialogSaveManualLayout::IsBinaryDXFFormat() const +auto DialogSaveManualLayout::IsBinaryDXFFormat() const -> bool { switch(Format()) { @@ -303,7 +296,7 @@ void DialogSaveManualLayout::SetDestinationPath(const QString &cmdDestinationPat } //--------------------------------------------------------------------------------------------------------------------- -bool DialogSaveManualLayout::IsTextAsPaths() const +auto DialogSaveManualLayout::IsTextAsPaths() const -> bool { return ui->checkBoxTextAsPaths->isChecked(); } @@ -314,30 +307,6 @@ void DialogSaveManualLayout::SetTextAsPaths(bool textAsPaths) ui->checkBoxTextAsPaths->setChecked(textAsPaths); } -//--------------------------------------------------------------------------------------------------------------------- -void DialogSaveManualLayout::SetXScale(qreal scale) -{ - ui->doubleSpinBoxHorizontalScale->setValue(scale * 100.); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal DialogSaveManualLayout::GetXScale() const -{ - return ui->doubleSpinBoxHorizontalScale->value() / 100.; -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSaveManualLayout::SetYScale(qreal scale) -{ - ui->doubleSpinBoxVerticalScale->setValue(scale * 100.); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal DialogSaveManualLayout::GetYScale() const -{ - return ui->doubleSpinBoxVerticalScale->value() / 100.; -} - //--------------------------------------------------------------------------------------------------------------------- void DialogSaveManualLayout::SetExportUnified(bool value) { @@ -390,7 +359,7 @@ void DialogSaveManualLayout::SetExportUnified(bool value) } //--------------------------------------------------------------------------------------------------------------------- -bool DialogSaveManualLayout::IsExportUnified() const +auto DialogSaveManualLayout::IsExportUnified() const -> bool { switch(Format()) { @@ -586,40 +555,7 @@ void DialogSaveManualLayout::ShowExample() } //--------------------------------------------------------------------------------------------------------------------- -void DialogSaveManualLayout::ToggleScaleConnection() -{ - m_scaleConnected = not m_scaleConnected; - - QIcon icon; - icon.addFile(m_scaleConnected ? QStringLiteral(":/icon/32x32/link.png") - : QStringLiteral(":/icon/32x32/broken_link.png")); - ui->toolButtonScaleConnected->setIcon(icon); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSaveManualLayout::HorizontalScaleChanged(double d) -{ - if (m_scaleConnected) - { - ui->doubleSpinBoxVerticalScale->blockSignals(true); - ui->doubleSpinBoxVerticalScale->setValue(d); - ui->doubleSpinBoxVerticalScale->blockSignals(false); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSaveManualLayout::VerticalScaleChanged(double d) -{ - if (m_scaleConnected) - { - ui->doubleSpinBoxHorizontalScale->blockSignals(true); - ui->doubleSpinBoxHorizontalScale->setValue(d); - ui->doubleSpinBoxHorizontalScale->blockSignals(false); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -bool DialogSaveManualLayout::SupportPSTest() +auto DialogSaveManualLayout::SupportPSTest() -> bool { if (!tested) { @@ -630,7 +566,7 @@ bool DialogSaveManualLayout::SupportPSTest() } //--------------------------------------------------------------------------------------------------------------------- -QVector > DialogSaveManualLayout::InitFormats() +auto DialogSaveManualLayout::InitFormats() -> QVector > { QVector> list; diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.h b/src/app/puzzle/dialogs/dialogsavemanuallayout.h index ce2484b31..8fa47a3a3 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.h +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.h @@ -52,21 +52,15 @@ public: void SelectFormat(LayoutExportFormats format); void SetBinaryDXFFormat(bool binary); - bool IsBinaryDXFFormat() const; + auto IsBinaryDXFFormat() const -> bool; void SetDestinationPath(const QString& cmdDestinationPath); - bool IsTextAsPaths() const; + auto IsTextAsPaths() const -> bool; void SetTextAsPaths(bool textAsPaths); - void SetXScale(qreal scale); - qreal GetXScale() const; - - void SetYScale(qreal scale); - qreal GetYScale() const; - void SetExportUnified(bool value); - bool IsExportUnified() const; + auto IsExportUnified() const -> bool; protected: virtual void showEvent(QShowEvent *event) override; @@ -75,9 +69,6 @@ private slots: void Save(); void PathChanged(const QString &text); void ShowExample(); - void ToggleScaleConnection(); - void HorizontalScaleChanged(double d); - void VerticalScaleChanged(double d); private: Q_DISABLE_COPY(DialogSaveManualLayout) diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.ui b/src/app/puzzle/dialogs/dialogsavemanuallayout.ui index b53197f6e..c494d4685 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.ui +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.ui @@ -6,8 +6,8 @@ 0 0 - 503 - 383 + 413 + 290 @@ -144,155 +144,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Scale - - - - - - - - Horizontal: - - - - - - - Vertical: - - - - - - - - - - - % - - - 1 - - - 1.000000000000000 - - - 300.000000000000000 - - - 0.100000000000000 - - - 100.000000000000000 - - - - - - - % - - - 1 - - - 1.000000000000000 - - - 300.000000000000000 - - - 0.100000000000000 - - - 100.000000000000000 - - - - - - - - - 1 - - - 0 - - - 0 - - - - - - 10 - - - - <html><head/><body><p><span style=" font-size:16pt;">┐</span></p></body></html> - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - ... - - - - :/icon/32x32/link.png:/icon/32x32/link.png - - - - 32 - 32 - - - - QToolButton::DelayedPopup - - - - - - - <html><head/><body><p><span style=" font-size:16pt; font-weight:600;">┘</span></p></body></html> - - - - - - - - @@ -356,6 +207,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -368,9 +232,7 @@ - - - + buttonBox diff --git a/src/app/puzzle/layout/vplayoutsettings.cpp b/src/app/puzzle/layout/vplayoutsettings.cpp index 77bedb417..aaba53418 100644 --- a/src/app/puzzle/layout/vplayoutsettings.cpp +++ b/src/app/puzzle/layout/vplayoutsettings.cpp @@ -328,3 +328,27 @@ void VPLayoutSettings::SetIgnoreTilesMargins(bool newIgnoreTilesMargins) { m_ignoreTilesMargins = newIgnoreTilesMargins; } + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPLayoutSettings::HorizontalScale() const +{ + return m_horizontalScale; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetHorizontalScale(qreal newHorizontalScale) +{ + m_horizontalScale = newHorizontalScale; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPLayoutSettings::VerticalScale() const +{ + return m_verticalScale; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutSettings::SetVerticalScale(qreal newVerticalScale) +{ + m_verticalScale = newVerticalScale; +} diff --git a/src/app/puzzle/layout/vplayoutsettings.h b/src/app/puzzle/layout/vplayoutsettings.h index 6b877c658..0d7f58806 100644 --- a/src/app/puzzle/layout/vplayoutsettings.h +++ b/src/app/puzzle/layout/vplayoutsettings.h @@ -300,6 +300,12 @@ public: auto IgnoreTilesMargins() const -> bool; void SetIgnoreTilesMargins(bool newIgnoreTilesMargins); + auto HorizontalScale() const -> qreal; + void SetHorizontalScale(qreal newHorizontalScale); + + auto VerticalScale() const -> qreal; + void SetVerticalScale(qreal newVerticalScale); + private: Unit m_unit{Unit::Cm}; @@ -348,6 +354,9 @@ private: qreal m_gridRowHeight{0}; bool m_stickyEdges{false}; + + qreal m_horizontalScale{1.0}; + qreal m_verticalScale{1.0}; }; #endif // VPLAYOUTSETTINGS_H diff --git a/src/app/puzzle/scene/vpgraphicstilegrid.cpp b/src/app/puzzle/scene/vpgraphicstilegrid.cpp index eb2d05782..9014418fd 100644 --- a/src/app/puzzle/scene/vpgraphicstilegrid.cpp +++ b/src/app/puzzle/scene/vpgraphicstilegrid.cpp @@ -24,9 +24,12 @@ auto VPGraphicsTileGrid::boundingRect() const -> QRectF { VPSheetPtr sheet = layout->GetSheet(m_sheetUuid); + qreal xScale = layout->LayoutSettings().HorizontalScale(); + qreal yScale = layout->LayoutSettings().VerticalScale(); + QRectF rect(0, 0, - layout->TileFactory()->ColNb(sheet) * layout->TileFactory()->DrawingAreaWidth(), - layout->TileFactory()->RowNb(sheet) * layout->TileFactory()->DrawingAreaHeight() ); + layout->TileFactory()->ColNb(sheet) * (layout->TileFactory()->DrawingAreaWidth() / xScale), + layout->TileFactory()->RowNb(sheet) * (layout->TileFactory()->DrawingAreaHeight() / yScale)); constexpr qreal halfPenWidth = penWidth/2.; @@ -54,29 +57,22 @@ void VPGraphicsTileGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->setPen(pen); painter->setBrush(noBrush); + qreal xScale = layout->LayoutSettings().HorizontalScale(); + qreal yScale = layout->LayoutSettings().VerticalScale(); + + const qreal drawingAreaWidth = layout->TileFactory()->DrawingAreaWidth() / xScale; + const qreal drawingAreaHeight = layout->TileFactory()->DrawingAreaHeight() / yScale; + for(int i=0;i<=layout->TileFactory()->ColNb(sheet);i++) { - painter->drawLine(QPointF( - i*layout->TileFactory()->DrawingAreaWidth(), - 0), - QPointF( - i*layout->TileFactory()->DrawingAreaWidth(), - layout->TileFactory()->RowNb(sheet)*layout->TileFactory()->DrawingAreaHeight() - ) - ); + painter->drawLine(QPointF(i*drawingAreaWidth, 0), + QPointF(i*drawingAreaWidth, layout->TileFactory()->RowNb(sheet)*drawingAreaHeight)); } for(int j=0;j<=layout->TileFactory()->RowNb(sheet);j++) { - painter->drawLine(QPointF( - 0, - j*layout->TileFactory()->DrawingAreaHeight() - ), - QPointF( - layout->TileFactory()->ColNb(sheet)*layout->TileFactory()->DrawingAreaWidth(), - j*layout->TileFactory()->DrawingAreaHeight() - ) - ); + painter->drawLine(QPointF(0, j*drawingAreaHeight), + QPointF(layout->TileFactory()->ColNb(sheet)*drawingAreaWidth, j*drawingAreaHeight)); } } } diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 52b983740..e22340107 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -979,6 +979,65 @@ void VPMainWindow::InitPropertyTabLayout() } }); + connect(ui->toolButtonScaleConnected, &QToolButton::clicked, this, [this]() + { + m_scaleConnected = not m_scaleConnected; + + UpdateScaleConnection(); + }); + + connect(ui->doubleSpinBoxHorizontalScale, QOverload::of(&QDoubleSpinBox::valueChanged), + this, [this](double d) + { + if (m_layout.isNull()) + { + return; + } + + m_layout->LayoutSettings().SetHorizontalScale(d / 100.); + + if (m_scaleConnected) + { + ui->doubleSpinBoxVerticalScale->blockSignals(true); + ui->doubleSpinBoxVerticalScale->setValue(d); + ui->doubleSpinBoxVerticalScale->blockSignals(false); + + m_layout->LayoutSettings().SetVerticalScale(d / 100.); + } + + LayoutWasSaved(false); + m_layout->TileFactory()->refreshTileInfos(); + m_graphicsView->RefreshLayout(); + + VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView); + }); + + connect(ui->doubleSpinBoxVerticalScale, QOverload::of(&QDoubleSpinBox::valueChanged), + [this](double d) + { + if (m_layout.isNull()) + { + return; + } + + m_layout->LayoutSettings().SetVerticalScale(d / 100.); + + if (m_scaleConnected) + { + ui->doubleSpinBoxHorizontalScale->blockSignals(true); + ui->doubleSpinBoxHorizontalScale->setValue(d); + ui->doubleSpinBoxHorizontalScale->blockSignals(false); + + m_layout->LayoutSettings().SetHorizontalScale(d / 100.); + } + + LayoutWasSaved(false); + m_layout->TileFactory()->refreshTileInfos(); + m_graphicsView->RefreshLayout(); + + VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView); + }); + connect(ui->pushButtonLayoutExport, &QPushButton::clicked, this, &VPMainWindow::on_ExportLayout); } @@ -1276,6 +1335,17 @@ void VPMainWindow::SetPropertyTabLayoutData() ui->doubleSpinBoxSheetPiecesGap->setSuffix(" " + UnitsToStr(LayoutUnit(), true)); + ui->groupBoxLayoutScale->setDisabled(false); + + const qreal xScale = m_layout->LayoutSettings().HorizontalScale(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxHorizontalScale, xScale * 100.); + + const qreal yScale = m_layout->LayoutSettings().VerticalScale(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxVerticalScale, yScale * 100.); + + m_scaleConnected = qFuzzyCompare(xScale, yScale); + UpdateScaleConnection(); + ui->groupBoxLayoutExport->setDisabled(false); } else @@ -1298,6 +1368,8 @@ void VPMainWindow::SetPropertyTabLayoutData() SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPiecesGap, 0); + ui->groupBoxLayoutScale->setDisabled(true); + ui->groupBoxLayoutExport->setDisabled(true); } } @@ -2139,7 +2211,7 @@ void VPMainWindow::ExportScene(const VPExportData &data) for (int i=0; i < sheets.size(); ++i) { - VPSheetPtr sheet = sheets.at(i); + const VPSheetPtr& sheet = sheets.at(i); if (sheet.isNull()) { continue; @@ -2390,8 +2462,9 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data) if (not m_layout->LayoutSettings().IgnoreTilesMargins()) { - QMarginsF tiledMargins = m_layout->LayoutSettings().GetTilesMargins(); + QMarginsF printerMargins; + QMarginsF tiledMargins = m_layout->LayoutSettings().GetTilesMargins(); if(tiledPDFOrientation == QPageLayout::Landscape) { // because when painting we have a -90rotation in landscape mode, @@ -2510,6 +2583,15 @@ void VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, QPainter *paint sheet->SceneData()->CleanAfterExport(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::UpdateScaleConnection() const +{ + QIcon icon; + icon.addFile(m_scaleConnected ? QStringLiteral(":/icon/32x32/link.png") + : QStringLiteral(":/icon/32x32/broken_link.png")); + ui->toolButtonScaleConnected->setIcon(icon); +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_actionNew_triggered() { @@ -3363,8 +3445,8 @@ void VPMainWindow::on_ExportLayout() data.path = dialog.Path(); data.fileName = dialog.FileName(); data.sheets = sheets; - data.xScale = dialog.GetXScale(); - data.yScale = dialog.GetYScale(); + data.xScale = m_layout->LayoutSettings().HorizontalScale(); + data.yScale = m_layout->LayoutSettings().VerticalScale(); data.isBinaryDXF = dialog.IsBinaryDXFFormat(); data.textAsPaths = dialog.IsTextAsPaths(); data.exportUnified = dialog.IsExportUnified(); @@ -3400,8 +3482,8 @@ void VPMainWindow::on_ExportSheet() data.path = dialog.Path(); data.fileName = dialog.FileName(); data.sheets = QList{sheet}; - data.xScale = dialog.GetXScale(); - data.yScale = dialog.GetYScale(); + data.xScale = m_layout->LayoutSettings().HorizontalScale(); + data.yScale = m_layout->LayoutSettings().VerticalScale(); data.isBinaryDXF = dialog.IsBinaryDXFFormat(); data.textAsPaths = dialog.IsTextAsPaths(); data.exportUnified = dialog.IsExportUnified(); diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 5ca5ce92e..5ff32e917 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -316,6 +316,8 @@ private: Unit m_oldPieceTranslationUnit{Unit::Mm}; Unit m_oldLayoutUnit{Unit::Mm}; + bool m_scaleConnected{true}; + /** * @brief InitMenuBar Inits the menu bar (File, Edit, Help ...) */ @@ -446,6 +448,8 @@ private: void GenerateUnifiedPdfFile(const VPExportData &data, const QString &name); void ExportPdfTiledFile(const VPExportData &data); void GeneratePdfTiledFile(const VPSheetPtr &sheet, QPainter *painter, QPrinter *printer, bool firstSheet); + + void UpdateScaleConnection() const; }; #endif // VPMAINWINDOW_H diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 8fa9e2f22..c52e42942 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -208,7 +208,7 @@ QTabWidget::Rounded - 1 + 3 @@ -1589,7 +1589,7 @@ 700 - + @@ -1691,6 +1691,179 @@ + + + + Scale + + + + + + + + + 0 + 0 + + + + Horizontal: + + + + + + + + 0 + 0 + + + + Vertical: + + + + + + + + + + + % + + + 1 + + + 1.000000000000000 + + + 300.000000000000000 + + + 0.100000000000000 + + + 100.000000000000000 + + + + + + + % + + + 1 + + + 1.000000000000000 + + + 300.000000000000000 + + + 0.100000000000000 + + + 100.000000000000000 + + + + + + + + + 1 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 10 + + + + <html><head/><body><p><span style=" font-size:16pt;">┐</span></p></body></html> + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + ... + + + + :/icon/32x32/link.png:/icon/32x32/link.png + + + + 32 + 32 + + + + QToolButton::DelayedPopup + + + + + + + + 0 + 0 + + + + <html><head/><body><p><span style=" font-size:16pt; font-weight:600;">┘</span></p></body></html> + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index 934c836e5..e20226e15 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -83,16 +83,23 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet QPen penTileDrawing = QPen(Qt::black, m_commonSettings->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + painter->setPen(penTileDrawing); + // paint the content of the page - QRectF source = QRectF(col*m_drawingAreaWidth, + qreal xScale = layout->LayoutSettings().HorizontalScale(); + qreal yScale = layout->LayoutSettings().VerticalScale(); + QRectF source = QRectF(col*m_drawingAreaWidth / xScale, + row*m_drawingAreaHeight / yScale, + m_drawingAreaWidth / xScale + m_infoStripeWidth, + m_drawingAreaHeight / yScale + m_infoStripeWidth + ); + + QRectF target = QRectF(col*m_drawingAreaWidth, row*m_drawingAreaHeight, m_drawingAreaWidth + m_infoStripeWidth, m_drawingAreaHeight + m_infoStripeWidth ); - - painter->setPen(penTileDrawing); - - sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, source), source, + sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, target), source, Qt::IgnoreAspectRatio); QScopedPointer svgRenderer(new QSvgRenderer()); @@ -306,8 +313,16 @@ auto VPTileFactory::RowNb(const VPSheetPtr &sheet) const -> int { return 0; } + + qreal yScale = 1; + VPLayoutPtr layout = m_layout.toStrongRef(); + if(not layout.isNull()) + { + yScale = layout->LayoutSettings().VerticalScale(); + } + QSizeF sheetSize = sheet->GetSheetSize(); - return qCeil(sheetSize.height() / m_drawingAreaHeight); + return qCeil(sheetSize.height() * yScale / m_drawingAreaHeight); } //--------------------------------------------------------------------------------------------------------------------- @@ -317,8 +332,16 @@ auto VPTileFactory::ColNb(const VPSheetPtr &sheet) const -> int { return 0; } + + qreal xScale = 1; + VPLayoutPtr layout = m_layout.toStrongRef(); + if(not layout.isNull()) + { + xScale = layout->LayoutSettings().HorizontalScale(); + } + QSizeF sheetSize = sheet->GetSheetSize(); - return qCeil(sheetSize.width() / m_drawingAreaWidth); + return qCeil(sheetSize.width() * xScale / m_drawingAreaWidth); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 9bb8d6095..f5f9015ae 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -242,7 +242,8 @@ void VPLayoutFileReader::ReadProperties(const VPLayoutPtr &layout) ML::TagTitle, // 1 ML::TagDescription, // 2 ML::TagControl, // 3 - ML::TagTiles // 4 + ML::TagTiles, // 4 + ML::TagScale // 5 }; while (readNextStartElement()) @@ -271,6 +272,10 @@ void VPLayoutFileReader::ReadProperties(const VPLayoutPtr &layout) qDebug("read tiles"); ReadTiles(layout); break; + case 5: // scale + qDebug("read scale"); + ReadScale(layout); + break; default: qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); skipCurrentElement(); @@ -338,6 +343,18 @@ void VPLayoutFileReader::ReadTiles(const VPLayoutPtr &layout) readElementText(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadScale(const VPLayoutPtr &layout) +{ + AssertRootTag(ML::TagScale); + + QXmlStreamAttributes attribs = attributes(); + layout->LayoutSettings().SetHorizontalScale(ReadAttributeDouble(attribs, ML::AttrXScale, QChar('1'))); + layout->LayoutSettings().SetVerticalScale(ReadAttributeDouble(attribs, ML::AttrYScale, QChar('1'))); + + readElementText(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPLayoutFileReader::ReadSheets(const VPLayoutPtr &layout) { diff --git a/src/app/puzzle/xml/vplayoutfilereader.h b/src/app/puzzle/xml/vplayoutfilereader.h index 46ded12a1..8b6a8f745 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.h +++ b/src/app/puzzle/xml/vplayoutfilereader.h @@ -56,6 +56,7 @@ private: void ReadProperties(const VPLayoutPtr &layout); void ReadControl(const VPLayoutPtr &layout); void ReadTiles(const VPLayoutPtr &layout); + void ReadScale(const VPLayoutPtr &layout); void ReadUnplacedPieces(const VPLayoutPtr &layout); void ReadSheets(const VPLayoutPtr &layout); void ReadSheet(const VPLayoutPtr &layout); diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index 2d0666b04..3b911be7f 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -179,6 +179,11 @@ void VPLayoutFileWriter::WriteLayoutProperties(const VPLayoutPtr &layout) WriteTiles(layout); + writeStartElement(ML::TagScale); + SetAttribute(ML::AttrXScale, layout->LayoutSettings().HorizontalScale()); + SetAttribute(ML::AttrYScale, layout->LayoutSettings().VerticalScale()); + writeEndElement(); // scale + writeEndElement(); // properties } diff --git a/src/app/puzzle/xml/vplayoutliterals.cpp b/src/app/puzzle/xml/vplayoutliterals.cpp index bb182e4b5..af9341fd6 100644 --- a/src/app/puzzle/xml/vplayoutliterals.cpp +++ b/src/app/puzzle/xml/vplayoutliterals.cpp @@ -58,6 +58,7 @@ const QString TagPieceLabel = QStringLiteral("pieceLabel"); const QString TagPatternLabel = QStringLiteral("patternLabel"); const QString TagLines = QStringLiteral("lines"); const QString TagLine = QStringLiteral("line"); +const QString TagScale = QStringLiteral("scale"); const QString AttrVersion = QStringLiteral("version"); const QString AttrWarningSuperposition = QStringLiteral("warningSuperposition"); @@ -98,6 +99,8 @@ const QString AttrAlignment = QStringLiteral("alignment"); const QString AttrGradationLabel = QStringLiteral("gradationLabel"); const QString AttrCopyNumber = QStringLiteral("copyNumber"); const QString AttrGrainlineType = QStringLiteral("grainlineType"); +const QString AttrXScale = QStringLiteral("xScale"); +const QString AttrYScale = QStringLiteral("yScale"); const QString atFrontStr = QStringLiteral("atFront"); const QString atRearStr = QStringLiteral("atRear"); diff --git a/src/app/puzzle/xml/vplayoutliterals.h b/src/app/puzzle/xml/vplayoutliterals.h index f5cf4f6e2..cde58eafb 100644 --- a/src/app/puzzle/xml/vplayoutliterals.h +++ b/src/app/puzzle/xml/vplayoutliterals.h @@ -63,6 +63,7 @@ extern const QString TagPieceLabel; extern const QString TagPatternLabel; extern const QString TagLines; extern const QString TagLine; +extern const QString TagScale; extern const QString AttrVersion; extern const QString AttrWarningSuperposition; @@ -103,6 +104,8 @@ extern const QString AttrAlignment; extern const QString AttrGradationLabel; extern const QString AttrCopyNumber; extern const QString AttrGrainlineType; +extern const QString AttrXScale; +extern const QString AttrYScale; extern const QString atFrontStr; extern const QString atRearStr; diff --git a/src/libs/ifc/schema/layout/v0.1.0.xsd b/src/libs/ifc/schema/layout/v0.1.0.xsd index c226ae332..b9a976439 100644 --- a/src/libs/ifc/schema/layout/v0.1.0.xsd +++ b/src/libs/ifc/schema/layout/v0.1.0.xsd @@ -39,6 +39,12 @@ + + + + + + @@ -489,4 +495,10 @@ + + + + + +