From 67b01c03374821fdc37fa1dda1412ba5e0aadaa9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 10 Oct 2017 12:22:59 +0300 Subject: [PATCH] Resolved issue #657. Improve feature: Allow more paper formats for printing tiled PDF. --HG-- branch : develop --- ChangeLog.txt | 1 + .../dialogs/dialoglayoutprogress.cpp | 3 +- .../dialogs/dialoglayoutsettings.cpp | 154 ++---------- .../valentina/dialogs/dialoglayoutsettings.h | 23 +- .../valentina/dialogs/dialoglayoutsettings.ui | 2 +- src/app/valentina/dialogs/dialogs.pri | 6 +- .../valentina/dialogs/dialogsavelayout.cpp | 133 +++++++++- src/app/valentina/dialogs/dialogsavelayout.h | 9 +- src/app/valentina/dialogs/dialogsavelayout.ui | 227 +++++++++++++++--- .../dialogs/vabstractlayoutdialog.cpp | 172 +++++++++++++ .../valentina/dialogs/vabstractlayoutdialog.h | 69 ++++++ src/app/valentina/mainwindowsnogui.cpp | 81 +++++-- src/app/valentina/mainwindowsnogui.h | 2 +- src/libs/vlayout/vposter.cpp | 115 ++++----- src/libs/vlayout/vposter.h | 14 +- src/libs/vmisc/def.cpp | 21 ++ src/libs/vmisc/def.h | 2 + src/libs/vmisc/vsettings.cpp | 120 +++++++++ src/libs/vmisc/vsettings.h | 14 ++ src/test/ValentinaTest/tst_vposter.cpp | 4 +- 20 files changed, 885 insertions(+), 287 deletions(-) create mode 100644 src/app/valentina/dialogs/vabstractlayoutdialog.cpp create mode 100644 src/app/valentina/dialogs/vabstractlayoutdialog.h diff --git a/ChangeLog.txt b/ChangeLog.txt index c5a5ab06c..f8bdabf1a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -25,6 +25,7 @@ - New math parser function "r2cm". Round to up to 1 decimal. - Two new shortcut sequences: Ctrl+PgDown and Ctrl+PgUp to switch to next and previous pattern piece. - [#765] New feature. Free curve mode. +- [#657] Improve feature: Allow more paper formats for printing tiled PDF # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/src/app/valentina/dialogs/dialoglayoutprogress.cpp b/src/app/valentina/dialogs/dialoglayoutprogress.cpp index 0564cd80f..4d22f1732 100644 --- a/src/app/valentina/dialogs/dialoglayoutprogress.cpp +++ b/src/app/valentina/dialogs/dialoglayoutprogress.cpp @@ -92,7 +92,8 @@ void DialogLayoutProgress::Error(const LayoutErrors &state) qCritical() << tr("Couldn't prepare data for creation layout"); break; case LayoutErrors::EmptyPaperError: - qCritical() << tr("Several workpieces left not arranged, but none of them match for paper"); + qCritical() << tr("One or more pattern pieces are bigger than the paper format you selected. Please, " + "select a bigger paper format."); break; case LayoutErrors::ProcessStoped: default: diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index cf1f5da27..db687c173 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -38,25 +38,12 @@ #include #include -//must be the same order as PaperSizeTemplate constants -const DialogLayoutSettings::FormatsVector DialogLayoutSettings::pageFormatNames = - DialogLayoutSettings::FormatsVector () << QLatin1String("A0") - << QLatin1String("A1") - << QLatin1String("A2") - << QLatin1String("A3") - << QLatin1String("A4") - << QApplication::translate("DialogLayoutSettings", "Letter") - << QApplication::translate("DialogLayoutSettings", "Legal") - << QApplication::translate("DialogLayoutSettings", "Roll 24in") - << QApplication::translate("DialogLayoutSettings", "Roll 30in") - << QApplication::translate("DialogLayoutSettings", "Roll 36in") - << QApplication::translate("DialogLayoutSettings", "Roll 42in") - << QApplication::translate("DialogLayoutSettings", "Roll 44in") - << QApplication::translate("DialogLayoutSettings", "Custom"); - //--------------------------------------------------------------------------------------------------------------------- DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent, bool disableSettings) - : QDialog(parent), disableSettings(disableSettings), ui(new Ui::DialogLayoutSettings), oldPaperUnit(Unit::Mm), + : VAbstractLayoutDialog(parent), + disableSettings(disableSettings), + ui(new Ui::DialogLayoutSettings), + oldPaperUnit(Unit::Mm), oldLayoutUnit(Unit::Mm), generator(generator), isInitialized(false) { ui->setupUi(this); @@ -67,7 +54,7 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget //even cleanse lists before adding InitPaperUnits(); InitLayoutUnits(); - InitTemplates(); + InitTemplates(ui->comboBoxTemplates); MinimumPaperSize(); MinimumLayoutSize(); InitPrinter(); @@ -107,7 +94,7 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget connect(ui->checkBoxIgnoreFileds, &QCheckBox::stateChanged, this, &DialogLayoutSettings::IgnoreAllFields); - connect(ui->toolButtonPortrate, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); + connect(ui->toolButtonPortrait, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->comboBoxLayoutUnit, static_cast(&QComboBox::currentIndexChanged), this, &DialogLayoutSettings::ConvertLayoutSize); @@ -368,10 +355,12 @@ void DialogLayoutSettings::FindTemplate() const qreal height = ui->doubleSpinBoxPaperHeight->value(); QSizeF size(width, height); + const Unit paperUnit = PaperUnit(); + const int max = static_cast(PaperSizeTemplate::Custom); for (int i=0; i < max; ++i) { - const QSizeF tmplSize = TemplateSize(static_cast(i)); + const QSizeF tmplSize = GetTemplateSize(static_cast(i), paperUnit); if (size == tmplSize) { ui->comboBoxTemplates->blockSignals(true); @@ -522,9 +511,9 @@ void DialogLayoutSettings::PaperSizeChanged() { if (ui->doubleSpinBoxPaperHeight->value() > ui->doubleSpinBoxPaperWidth->value()) { - ui->toolButtonPortrate->blockSignals(true); - ui->toolButtonPortrate->setChecked(true); - ui->toolButtonPortrate->blockSignals(false); + ui->toolButtonPortrait->blockSignals(true); + ui->toolButtonPortrait->setChecked(true); + ui->toolButtonPortrait->blockSignals(false); } else { @@ -602,7 +591,7 @@ void DialogLayoutSettings::DialogAccepted() { QMessageBox::StandardButton answer; answer = QMessageBox::question(this, tr("Wrong fields."), - tr("Fields go beyond printing. \n\nApply settings anyway?"), + tr("Margins go beyond printing. \n\nApply settings anyway?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No); if (answer == QMessageBox::No) { @@ -748,31 +737,6 @@ void DialogLayoutSettings::InitLayoutUnits() } } -//--------------------------------------------------------------------------------------------------------------------- -void DialogLayoutSettings::InitTemplates() -{ - const QIcon icoPaper("://icon/16x16/template.png"); - const QIcon icoRoll("://icon/16x16/roll.png"); - const QString pdi = QString("(%1ppi)").arg(PrintDPI); - - auto cntr = static_cast(PaperSizeTemplate::A0); - foreach(const auto& v, pageFormatNames) - { - if (cntr <= static_cast(PaperSizeTemplate::Legal)) - { - ui->comboBoxTemplates->addItem(icoPaper, v+" "+pdi, QVariant(cntr++)); - } - else if (cntr <= static_cast(PaperSizeTemplate::Roll44in)) - { - ui->comboBoxTemplates->addItem(icoRoll, v+" "+pdi, QVariant(cntr++)); - } - else - { - ui->comboBoxTemplates->addItem(v+" "+pdi, QVariant(cntr++)); - } - } - ui->comboBoxTemplates->setCurrentIndex(-1); -} //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::InitPrinter() @@ -825,13 +789,13 @@ QString DialogLayoutSettings::MakeHelpTemplateList() QString out = "\n"; auto cntr = static_cast(PaperSizeTemplate::A0); - for (int i = 0; i < pageFormatNames.size(); ++i) + for (int i = 0; i < VAbstractLayoutDialog::pageFormatNames.size(); ++i) { if (cntr <= static_cast(PaperSizeTemplate::Roll44in))// Don't include custom template { - out += "\t* "+pageFormatNames.at(i)+" = "+ QString::number(cntr++); + out += "\t* "+VAbstractLayoutDialog::pageFormatNames.at(i)+" = "+ QString::number(cntr++); - if (i < pageFormatNames.size() - 1) + if (i < VAbstractLayoutDialog::pageFormatNames.size() - 1) { out += ",\n"; } @@ -850,6 +814,8 @@ QSizeF DialogLayoutSettings::Template() PaperSizeTemplate temp; temp = static_cast(ui->comboBoxTemplates->currentData().toInt()); + const Unit paperUnit = PaperUnit(); + switch (temp) { case PaperSizeTemplate::A0: @@ -859,7 +825,7 @@ QSizeF DialogLayoutSettings::Template() case PaperSizeTemplate::A4: case PaperSizeTemplate::Letter: SetAdditionalOptions(false); - return TemplateSize(temp); + return GetTemplateSize(temp, paperUnit); case PaperSizeTemplate::Legal: case PaperSizeTemplate::Roll24in: case PaperSizeTemplate::Roll30in: @@ -867,9 +833,9 @@ QSizeF DialogLayoutSettings::Template() case PaperSizeTemplate::Roll42in: case PaperSizeTemplate::Roll44in: SetAdditionalOptions(true); - return TemplateSize(temp); + return GetTemplateSize(temp, paperUnit); case PaperSizeTemplate::Custom: - return TemplateSize(temp); + return GetTemplateSize(temp, paperUnit); default: break; } @@ -877,96 +843,24 @@ QSizeF DialogLayoutSettings::Template() } //--------------------------------------------------------------------------------------------------------------------- -QSizeF DialogLayoutSettings::TemplateSize(const PaperSizeTemplate &tmpl) const +QSizeF DialogLayoutSettings::GetTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const { - const Unit paperUnit = PaperUnit(); qreal width = 0; qreal height = 0; switch (tmpl) { - case PaperSizeTemplate::A0: - width = UnitConvertor(841, Unit::Mm, paperUnit); - height = UnitConvertor(1189, Unit::Mm, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::A1: - width = UnitConvertor(594, Unit::Mm, paperUnit); - height = UnitConvertor(841, Unit::Mm, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::A2: - width = UnitConvertor(420, Unit::Mm, paperUnit); - height = UnitConvertor(594, Unit::Mm, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::A3: - width = UnitConvertor(297, Unit::Mm, paperUnit); - height = UnitConvertor(420, Unit::Mm, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::A4: - width = UnitConvertor(210, Unit::Mm, paperUnit); - height = UnitConvertor(297, Unit::Mm, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::Letter: - width = UnitConvertor(8.5, Unit::Inch, paperUnit); - height = UnitConvertor(11, Unit::Inch, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::Legal: - width = UnitConvertor(8.5, Unit::Inch, paperUnit); - height = UnitConvertor(14, Unit::Inch, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::Roll24in: - width = UnitConvertor(24, Unit::Inch, paperUnit); - height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::Roll30in: - width = UnitConvertor(30, Unit::Inch, paperUnit); - height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::Roll36in: - width = UnitConvertor(36, Unit::Inch, paperUnit); - height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::Roll42in: - width = UnitConvertor(42, Unit::Inch, paperUnit); - height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); - return RoundTemplateSize(width, height); - case PaperSizeTemplate::Roll44in: - width = UnitConvertor(44, Unit::Inch, paperUnit); - height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); - return RoundTemplateSize(width, height); case PaperSizeTemplate::Custom: width = ui->doubleSpinBoxPaperWidth->value(); height = ui->doubleSpinBoxPaperHeight->value(); - return RoundTemplateSize(width, height); + return RoundTemplateSize(width, height, unit); default: - break; + return VAbstractLayoutDialog::GetTemplateSize(tmpl, unit); } - return QSizeF(); } -//--------------------------------------------------------------------------------------------------------------------- -QSizeF DialogLayoutSettings::RoundTemplateSize(qreal width, qreal height) const -{ - qreal w = 0; - qreal h = 0; - switch (PaperUnit()) - { - case Unit::Cm: - case Unit::Mm: - case Unit::Px: - w = qRound(width * 100.0) / 100.0; - h = qRound(height * 100.0) / 100.0; - return QSizeF(w, h); - case Unit::Inch: - w = qRound(width * 100000.0) / 100000.0; - h = qRound(height * 100000.0) / 100000.0; - return QSizeF(w, h); - default: - break; - } - return QSizeF(width, height); -} //--------------------------------------------------------------------------------------------------------------------- QMarginsF DialogLayoutSettings::MinPrinterFields() const diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.h b/src/app/valentina/dialogs/dialoglayoutsettings.h index bd3a5c06b..43d157796 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.h +++ b/src/app/valentina/dialogs/dialoglayoutsettings.h @@ -30,7 +30,7 @@ #define DIALOGLAYOUTSETTINGS_H #include -#include +#include "vabstractlayoutdialog.h" #include "../vlayout/vbank.h" #include "../ifc/ifcdef.h" @@ -48,23 +48,10 @@ namespace Ui class VLayoutGenerator; -class DialogLayoutSettings : public QDialog +class DialogLayoutSettings : public VAbstractLayoutDialog { Q_OBJECT public: - enum class PaperSizeTemplate : char { A0 = 0, - A1, - A2, - A3, - A4, - Letter, - Legal, - Roll24in = 7, // Be carefull when change order roll type - Roll30in, // Used also for showing icon - Roll36in, - Roll42in, - Roll44in = 11, - Custom = 12}; explicit DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent = nullptr, bool disableSettings = false); virtual ~DialogLayoutSettings(); @@ -125,6 +112,8 @@ public: static QString MakeGroupsHelp(); protected: virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; + QSizeF GetTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const; + public slots: void DialogAccepted(); private slots: @@ -155,11 +144,9 @@ private: void InitPaperUnits(); void InitLayoutUnits(); - void InitTemplates(); void InitPrinter(); QSizeF Template(); - QSizeF TemplateSize(const PaperSizeTemplate &tmpl) const; - QSizeF RoundTemplateSize(qreal width, qreal height) const; + QMarginsF MinPrinterFields() const; QMarginsF GetDefPrinterFields() const; diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.ui b/src/app/valentina/dialogs/dialoglayoutsettings.ui index ed0993653..f3bb1c0c2 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.ui +++ b/src/app/valentina/dialogs/dialoglayoutsettings.ui @@ -75,7 +75,7 @@ - + ... diff --git a/src/app/valentina/dialogs/dialogs.pri b/src/app/valentina/dialogs/dialogs.pri index 61c91e73c..2bb72de56 100644 --- a/src/app/valentina/dialogs/dialogs.pri +++ b/src/app/valentina/dialogs/dialogs.pri @@ -20,7 +20,8 @@ HEADERS += \ $$PWD/dialogdatetimeformats.h \ $$PWD/dialogknownmaterials.h \ $$PWD/dialogpatternmaterials.h \ - $$PWD/dialogfinalmeasurements.h + $$PWD/dialogfinalmeasurements.h \ + $$PWD/vabstractlayoutdialog.h SOURCES += \ $$PWD/dialogincrements.cpp \ @@ -40,7 +41,8 @@ SOURCES += \ $$PWD/dialogdatetimeformats.cpp \ $$PWD/dialogknownmaterials.cpp \ $$PWD/dialogpatternmaterials.cpp \ - $$PWD/dialogfinalmeasurements.cpp + $$PWD/dialogfinalmeasurements.cpp \ + $$PWD/vabstractlayoutdialog.cpp FORMS += \ $$PWD/dialogincrements.ui \ diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index fa3273825..a036979e5 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -39,6 +39,7 @@ #include #include #include +#include const QString baseFilenameRegExp = QStringLiteral("^[\\p{L}\\p{Nd}\\-. _]+$"); @@ -47,7 +48,7 @@ bool DialogSaveLayout::tested = false; //--------------------------------------------------------------------------------------------------------------------- DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName, QWidget *parent) - : QDialog(parent), + : VAbstractLayoutDialog(parent), ui(new Ui::DialogSaveLAyout), count(count), isInitialized(false), @@ -133,8 +134,44 @@ DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName connect(ui->lineEditPath, &QLineEdit::textChanged, this, &DialogSaveLayout::PathChanged); ui->lineEditPath->setText(qApp->ValentinaSettings()->GetPathLayout()); + + InitTemplates(ui->comboBoxTemplates); + + ReadSettings(); + + // connect for the template drop down box of the tiled pds + connect(ui->comboBoxTemplates, static_cast(&QComboBox::currentIndexChanged), + this, &DialogSaveLayout::WriteSettings); + + // connects for the margins of the tiled pdf + connect(ui->doubleSpinBoxLeftField, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogSaveLayout::WriteSettings); + connect(ui->doubleSpinBoxTopField, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogSaveLayout::WriteSettings); + connect(ui->doubleSpinBoxRightField, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogSaveLayout::WriteSettings); + connect(ui->doubleSpinBoxBottomField, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogSaveLayout::WriteSettings); + + // connects for the orientation buttons for the tiled pdf + connect(ui->toolButtonPortrait, &QToolButton::toggled, this, &DialogSaveLayout::WriteSettings); + connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogSaveLayout::WriteSettings); + + ShowExample();//Show example for current format. } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSaveLayout::InitTemplates(QComboBox *comboBoxTemplates) +{ + SCASSERT(comboBoxTemplates != nullptr) + VAbstractLayoutDialog::InitTemplates(comboBoxTemplates); + + // remove the custom format, + comboBoxTemplates->removeItem(comboBoxTemplates->findData(static_cast(PaperSizeTemplate::Custom))); +} + + //--------------------------------------------------------------------------------------------------------------------- void DialogSaveLayout::SelectFormat(LayoutExportFormats format) @@ -513,6 +550,10 @@ void DialogSaveLayout::ShowExample() const LayoutExportFormats currentFormat = Format(); ui->labelExample->setText(tr("Example:") + FileName() + QLatin1String("1") + ExportFromatSuffix(currentFormat)); + ui->checkBoxBinaryDXF->setEnabled(false); + ui->groupBoxPaperFormat->setEnabled(false); + ui->groupBoxMargins->setEnabled(false); + switch(currentFormat) { case LayoutExportFormats::DXF_AC1006_Flat: @@ -544,15 +585,17 @@ void DialogSaveLayout::ShowExample() case LayoutExportFormats::DXF_AC1027_ASTM: ui->checkBoxBinaryDXF->setEnabled(true); break; + case LayoutExportFormats::PDFTiled: + ui->groupBoxPaperFormat->setEnabled(true); + ui->groupBoxMargins->setEnabled(true); + break; case LayoutExportFormats::SVG: case LayoutExportFormats::PDF: - case LayoutExportFormats::PDFTiled: case LayoutExportFormats::PNG: case LayoutExportFormats::OBJ: case LayoutExportFormats::PS: case LayoutExportFormats::EPS: default: - ui->checkBoxBinaryDXF->setEnabled(false); break; } } @@ -691,3 +734,87 @@ void DialogSaveLayout::RemoveFormatFromList(LayoutExportFormats format) ui->comboBoxFormat->removeItem(index); } } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ReadSettings reads the values of the variables needed for the save layout dialog, for instance + * the margins, teamplte and orientation of tiled pdf. Then sets the corresponding + * elements of the dialog to these values. + */ +void DialogSaveLayout::ReadSettings() +{ + VSettings *settings = qApp->ValentinaSettings(); + const Unit unit = qApp->patternUnit(); + + // read Margins top, right, bottom, left + const QMarginsF margins = settings->GetTiledPDFMargins(unit); + + ui->doubleSpinBoxLeftField->setValue(margins.left()); + ui->doubleSpinBoxTopField->setValue(margins.top()); + ui->doubleSpinBoxRightField->setValue(margins.right()); + ui->doubleSpinBoxBottomField->setValue(margins.bottom()); + + // read Template + const QSizeF size = QSizeF(settings->GetTiledPDFPaperWidth(Unit::Mm), settings->GetTiledPDFPaperHeight(Unit::Mm)); + + const int max = static_cast(PaperSizeTemplate::Custom); + for (int i=0; i < max; ++i) + { + + const QSizeF tmplSize = GetTemplateSize(static_cast(i), Unit::Mm); + if (size == tmplSize) + { + ui->comboBoxTemplates->setCurrentIndex(i); + break; + } + } + + // read Orientation + if(settings->GetTiledPDFOrientation() == PageOrientation::Portrait) + { + ui->toolButtonPortrait->setChecked(true); + } + else + { + ui->toolButtonLandscape->setChecked(true); + } + +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief WriteSettings writes the values of some variables (like the margins, template and orientation of tiled pdf) + * of the save layout dialog into the settings. + */ +void DialogSaveLayout::WriteSettings() const +{ + VSettings *settings = qApp->ValentinaSettings(); + const Unit unit = qApp->patternUnit(); + + // write Margins top, right, bottom, left + QMarginsF margins = QMarginsF( + ui->doubleSpinBoxLeftField->value(), + ui->doubleSpinBoxTopField->value(), + ui->doubleSpinBoxRightField->value(), + ui->doubleSpinBoxBottomField->value() + ); + settings->SetTiledPDFMargins(margins,unit); + + // write Template + const PaperSizeTemplate temp = static_cast(ui->comboBoxTemplates->currentData().toInt()); + const QSizeF size = GetTemplateSize(temp, Unit::Mm); + + settings->SetTiledPDFPaperHeight(size.height(), Unit::Mm); + settings->SetTiledPDFPaperWidth(size.width(), Unit::Mm); + + // write Orientation + if(ui->toolButtonPortrait->isChecked()) + { + settings->SetTiledPDFOrientation(PageOrientation::Portrait); + } + else + { + settings->SetTiledPDFOrientation(PageOrientation::Landscape); + } +} + diff --git a/src/app/valentina/dialogs/dialogsavelayout.h b/src/app/valentina/dialogs/dialogsavelayout.h index cc45328fc..ae1b1572d 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.h +++ b/src/app/valentina/dialogs/dialogsavelayout.h @@ -29,8 +29,8 @@ #ifndef DIALOGSAVELAYOUT_H #define DIALOGSAVELAYOUT_H -#include #include "../vgeometry/vgeometrydef.h" +#include "vabstractlayoutdialog.h" #ifdef Q_OS_WIN # define PDFTOPS "pdftops.exe" @@ -82,7 +82,7 @@ enum class LayoutExportFormats : char COUNT /*Use only for validation*/ }; -class DialogSaveLayout : public QDialog +class DialogSaveLayout : public VAbstractLayoutDialog { Q_OBJECT @@ -113,6 +113,8 @@ public: protected: virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; + void InitTemplates(QComboBox *comboBoxTemplates); + private slots: void Save(); void PathChanged(const QString &text); @@ -131,6 +133,9 @@ private: static QVector > InitFormats(); void RemoveFormatFromList(LayoutExportFormats format); + + void ReadSettings(); + void WriteSettings() const; }; #endif // DIALOGSAVELAYOUT_H diff --git a/src/app/valentina/dialogs/dialogsavelayout.ui b/src/app/valentina/dialogs/dialogsavelayout.ui index df521ab4c..9162039e8 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.ui +++ b/src/app/valentina/dialogs/dialogsavelayout.ui @@ -6,8 +6,8 @@ 0 0 - 748 - 206 + 601 + 325 @@ -20,18 +20,6 @@ - - QLayout::SetDefaultConstraint - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - @@ -69,7 +57,7 @@ Select path to destination folder - Browse… + Browse... @@ -92,13 +80,6 @@ - - - - - - - @@ -109,14 +90,188 @@ - + + + + true + + + Text as paths + + + + + + + 10 + + + + + true + + + Margins + + + false + + + + + + + + Right: + + + + + + + + + + + 71 + 0 + + + + + + + + Left: + + + + + + + + + + + Top: + + + + + + + + + + Bottom: + + + + + + + + + + + + + + + true + + + Paper format + + + + + + + + Templates: + + + + + + + + + + Orientation: + + + + + + + + + ... + + + + :/icon/16x16/portrait.png:/icon/16x16/portrait.png + + + true + + + true + + + true + + + + + + + ... + + + + :/icon/16x16/landscape.png:/icon/16x16/landscape.png + + + true + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + File name: - + @@ -152,16 +307,6 @@ - - - - true - - - Text as paths - - - @@ -176,6 +321,20 @@ + + lineEditPath + pushButtonBrowse + checkBoxBinaryDXF + checkBoxTextAsPaths + doubleSpinBoxLeftField + doubleSpinBoxTopField + doubleSpinBoxRightField + doubleSpinBoxBottomField + comboBoxTemplates + toolButtonPortrait + toolButtonLandscape + lineEditFileName + diff --git a/src/app/valentina/dialogs/vabstractlayoutdialog.cpp b/src/app/valentina/dialogs/vabstractlayoutdialog.cpp new file mode 100644 index 000000000..7a10188e7 --- /dev/null +++ b/src/app/valentina/dialogs/vabstractlayoutdialog.cpp @@ -0,0 +1,172 @@ +/************************************************************************ + ** + ** @file dialogsavelayout.cpp + ** @author Roman Telezhynskyi + ** @date 9 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vabstractlayoutdialog.h" +#include "../core/vapplication.h" + +//must be the same order as PaperSizeTemplate constants +const VAbstractLayoutDialog::FormatsVector VAbstractLayoutDialog::pageFormatNames = + VAbstractLayoutDialog::FormatsVector () << QLatin1String("A0") + << QLatin1String("A1") + << QLatin1String("A2") + << QLatin1String("A3") + << QLatin1String("A4") + << QApplication::translate("VAbstractLayoutDialog", "Letter") + << QApplication::translate("VAbstractLayoutDialog", "Legal") + << QApplication::translate("VAbstractLayoutDialog", "Roll 24in") + << QApplication::translate("VAbstractLayoutDialog", "Roll 30in") + << QApplication::translate("VAbstractLayoutDialog", "Roll 36in") + << QApplication::translate("VAbstractLayoutDialog", "Roll 42in") + << QApplication::translate("VAbstractLayoutDialog", "Roll 44in") + << QApplication::translate("VAbstractLayoutDialog", "Custom"); + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractLayoutDialog::VAbstractLayoutDialog(QWidget *parent) + : QDialog(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractLayoutDialog::InitTemplates(QComboBox *comboBoxTemplates) +{ + SCASSERT(comboBoxTemplates != nullptr) + const QIcon icoPaper("://icon/16x16/template.png"); + const QIcon icoRoll("://icon/16x16/roll.png"); + const QString pdi = QString("(%1ppi)").arg(PrintDPI); + + auto cntr = static_cast(PaperSizeTemplate::A0); + foreach(const auto& v, pageFormatNames) + { + if (cntr <= static_cast(PaperSizeTemplate::Legal)) + { + comboBoxTemplates->addItem(icoPaper, v+" "+pdi, QVariant(cntr++)); + } + else if (cntr <= static_cast(PaperSizeTemplate::Roll44in)) + { + comboBoxTemplates->addItem(icoRoll, v+" "+pdi, QVariant(cntr++)); + } + else + { + comboBoxTemplates->addItem(v+" "+pdi, QVariant(cntr++)); + } + } + comboBoxTemplates->setCurrentIndex(-1); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief DialogLayoutSettings::TemplateSize + * @param tmpl + * @param unit + * @return + */ +QSizeF VAbstractLayoutDialog::GetTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const +{ + qreal width = 0; + qreal height = 0; + + switch (tmpl) + { + case PaperSizeTemplate::A0: + width = UnitConvertor(841, Unit::Mm, unit); + height = UnitConvertor(1189, Unit::Mm, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::A1: + width = UnitConvertor(594, Unit::Mm, unit); + height = UnitConvertor(841, Unit::Mm, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::A2: + width = UnitConvertor(420, Unit::Mm, unit); + height = UnitConvertor(594, Unit::Mm, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::A3: + width = UnitConvertor(297, Unit::Mm, unit); + height = UnitConvertor(420, Unit::Mm, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::A4: + width = UnitConvertor(210, Unit::Mm, unit); + height = UnitConvertor(297, Unit::Mm, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::Letter: + width = UnitConvertor(8.5, Unit::Inch, unit); + height = UnitConvertor(11, Unit::Inch, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::Legal: + width = UnitConvertor(8.5, Unit::Inch, unit); + height = UnitConvertor(14, Unit::Inch, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::Roll24in: + width = UnitConvertor(24, Unit::Inch, unit); + height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::Roll30in: + width = UnitConvertor(30, Unit::Inch, unit); + height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::Roll36in: + width = UnitConvertor(36, Unit::Inch, unit); + height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::Roll42in: + width = UnitConvertor(42, Unit::Inch, unit); + height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit); + return RoundTemplateSize(width, height, unit); + case PaperSizeTemplate::Roll44in: + width = UnitConvertor(44, Unit::Inch, unit); + height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit); + return RoundTemplateSize(width, height, unit); + default: + break; + } + return QSizeF(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QSizeF VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit unit) const +{ + qreal w = 0; + qreal h = 0; + + switch (unit) + { + case Unit::Cm: + case Unit::Mm: + case Unit::Px: + w = qRound(width * 100.0) / 100.0; + h = qRound(height * 100.0) / 100.0; + return QSizeF(w, h); + case Unit::Inch: + w = qRound(width * 100000.0) / 100000.0; + h = qRound(height * 100000.0) / 100000.0; + return QSizeF(w, h); + default: + break; + } + + return QSizeF(width, height); +} diff --git a/src/app/valentina/dialogs/vabstractlayoutdialog.h b/src/app/valentina/dialogs/vabstractlayoutdialog.h new file mode 100644 index 000000000..eb2a1687d --- /dev/null +++ b/src/app/valentina/dialogs/vabstractlayoutdialog.h @@ -0,0 +1,69 @@ +/************************************************************************ + ** + ** @file dialogsavelayout.cpp + ** @author Roman Telezhynskyi + ** @date 9 10, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VABSTRACTLAYOUTDIALOG_H +#define VABSTRACTLAYOUTDIALOG_H + +#include "../ifc/ifcdef.h" + +#include +#include + +class VAbstractLayoutDialog : public QDialog +{ +public: + enum class PaperSizeTemplate : char { A0 = 0, + A1, + A2, + A3, + A4, + Letter, + Legal, + Roll24in = 7, // Be carefull when change order roll type + Roll30in, // Used also for showing icon + Roll36in, + Roll42in, + Roll44in = 11, + Custom = 12}; + + explicit VAbstractLayoutDialog(QWidget *parent = nullptr); + +protected: + typedef QStringList FormatsVector; + const static FormatsVector pageFormatNames; + typedef int VIndexType; + + QSizeF GetTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const; + QSizeF RoundTemplateSize(qreal width, qreal height, Unit unit) const; + + void InitTemplates(QComboBox *comboBoxTemplates); +private: + Q_DISABLE_COPY(VAbstractLayoutDialog) +}; + +#endif // VABSTRACTDIALOG_H diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 214c6cd1a..aea637516 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -217,7 +217,8 @@ void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state) qCritical() << tr("Couldn't prepare data for creation layout"); break; case LayoutErrors::EmptyPaperError: - qCritical() << tr("Several workpieces left not arranged, but none of them match for paper"); + qCritical() << tr("One or more pattern pieces are bigger than the paper format you selected. Please, " + "select a bigger paper format."); break; case LayoutErrors::ProcessStoped: default: @@ -533,6 +534,15 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) if (isTiled) { + VSettings *settings = qApp->ValentinaSettings(); + // when isTiled, the landscape tiles have to be rotated, because the pages + // stay portrait in the pdf + if(settings->GetTiledPDFOrientation() == PageOrientation::Landscape) + { + painter.rotate(-90); + painter.translate(-ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm), 0); + } + poster = QSharedPointer>(new QVector()); posterazor = QSharedPointer(new VPoster(printer)); @@ -541,7 +551,7 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) auto *paper = qgraphicsitem_cast(papers.at(i)); if (paper) { - *poster += posterazor->Calc(paper->rect().toRect(), i); + *poster += posterazor->Calc(paper->rect().toRect(), i, settings->GetTiledPDFOrientation()); } } @@ -933,7 +943,6 @@ void MainWindowsNoGUI::PdfTiledFile(const QString &name) } QPrinter printer; SetPrinterSettings(&printer, PrintType::PrintPDF); - printer.setPageSize(QPrinter::A4);// Want to be sure that page size is correct. // Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size if (not isTiled && not IsPagesFit(printer.paperRect().size())) @@ -1238,10 +1247,11 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr { SCASSERT(printer != nullptr) printer->setCreator(QGuiApplication::applicationDisplayName()+" "+QCoreApplication::applicationVersion()); - printer->setOrientation(QPrinter::Portrait); if (not isTiled) { + printer->setOrientation(QPrinter::Portrait); + QSizeF size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), FromPixel(paperSize.height(), Unit::Mm)); if (isAutoCrop || isUnitePages) { @@ -1253,7 +1263,7 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr } } - const QPrinter::PageSize pSZ = FindTemplate(size); + const QPrinter::PageSize pSZ = FindQPrinterPageSize(size); if (pSZ == QPrinter::Custom) { printer->setPaperSize (size, QPrinter::Millimeter ); @@ -1265,15 +1275,50 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr } else { - printer->setPaperSize(QPrinter::A4); + VSettings *settings = qApp->ValentinaSettings(); + if(settings->GetTiledPDFOrientation() == PageOrientation::Landscape) + { + printer->setOrientation(QPrinter::Landscape); + } + else + { + printer->setOrientation(QPrinter::Portrait); + } } printer->setFullPage(ignorePrinterFields); - const qreal left = FromPixel(margins.left(), Unit::Mm); - const qreal top = FromPixel(margins.top(), Unit::Mm); - const qreal right = FromPixel(margins.right(), Unit::Mm); - const qreal bottom = FromPixel(margins.bottom(), Unit::Mm); + qreal left, top, right, bottom; + + if (not isTiled) + { + QMarginsF pageMargin = QMarginsF(UnitConvertor(margins, Unit::Px, Unit::Mm)); + left = pageMargin.left(); + top = pageMargin.top(); + right = pageMargin.right(); + bottom = pageMargin.bottom(); + } + else + { + VSettings *settings = qApp->ValentinaSettings(); + QMarginsF pageMargin = QMarginsF(settings->GetTiledPDFMargins(Unit::Mm)); + if(settings->GetTiledPDFOrientation() == PageOrientation::Landscape) + { + // because when painting we have a -90rotation in landscape modus, + // see function PrintPages. + left = pageMargin.bottom(); + top = pageMargin.left(); + right = pageMargin.top(); + bottom = pageMargin.right(); + } + else + { + left = pageMargin.left(); + top = pageMargin.top(); + right = pageMargin.right(); + bottom = pageMargin.bottom(); + } + } #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) const bool success = printer->setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Millimeter); @@ -1353,39 +1398,39 @@ bool MainWindowsNoGUI::IsLayoutGrayscale() const } //--------------------------------------------------------------------------------------------------------------------- -QPrinter::PaperSize MainWindowsNoGUI::FindTemplate(const QSizeF &size) const +QPrinter::PaperSize MainWindowsNoGUI::FindQPrinterPageSize(const QSizeF &size) const { - if (size == QSizeF(841, 1189)) + if (size == QSizeF(841, 1189) || size == QSizeF(1189, 841)) { return QPrinter::A0; } - if (size == QSizeF(594, 841)) + if (size == QSizeF(594, 841) || size == QSizeF(841, 594)) { return QPrinter::A1; } - if (size == QSizeF(420, 594)) + if (size == QSizeF(420, 594) || size == QSizeF(594, 420)) { return QPrinter::A2; } - if (size == QSizeF(297, 420)) + if (size == QSizeF(297, 420) || size == QSizeF(420, 297)) { return QPrinter::A3; } - if (size == QSizeF(210, 297)) + if (size == QSizeF(210, 297) || size == QSizeF(297, 210)) { return QPrinter::A4; } - if (size == QSizeF(215.9, 355.6)) + if (size == QSizeF(215.9, 355.6) || size == QSizeF(355.6, 215.9)) { return QPrinter::Legal; } - if (size == QSizeF(215.9, 279.4)) + if (size == QSizeF(215.9, 279.4) || size == QSizeF(279.4, 215.9)) { return QPrinter::Letter; } diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index ff2f68dfb..248248a98 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -151,7 +151,7 @@ private: void SetPrinterSettings(QPrinter *printer, const PrintType &printType); bool IsLayoutGrayscale() const; - QPrinter::PaperSize FindTemplate(const QSizeF &size) const; + QPrinter::PaperSize FindQPrinterPageSize(const QSizeF &size) const; bool isPagesUniform() const; bool IsPagesFit(const QSizeF &printPaper) const; diff --git a/src/libs/vlayout/vposter.cpp b/src/libs/vlayout/vposter.cpp index d9407b20f..287d02dd7 100644 --- a/src/libs/vlayout/vposter.cpp +++ b/src/libs/vlayout/vposter.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include "../vmisc/vmath.h" #include "../vmisc/def.h" @@ -49,7 +50,7 @@ VPoster::VPoster(const QPrinter *printer) } //--------------------------------------------------------------------------------------------------------------------- -QVector VPoster::Calc(const QRect &imageRect, int page) const +QVector VPoster::Calc(const QRect &imageRect, int page, PageOrientation orientation) const { QVector poster; @@ -58,14 +59,14 @@ QVector VPoster::Calc(const QRect &imageRect, int page) const return poster; } - const int rows = CountRows(imageRect.height()); - const int columns = CountColumns(imageRect.width()); + const int rows = CountRows(imageRect.height(), orientation); + const int columns = CountColumns(imageRect.width(), orientation); for (int i=0; i < rows; i++) { for (int j=0; j< columns; j++) { - PosterData data = Cut(i, j, imageRect); + PosterData data = Cut(i, j, imageRect, orientation); data.index = static_cast(page); data.rows = static_cast(rows); data.columns = static_cast(columns); @@ -165,89 +166,61 @@ QVector VPoster::Borders(QGraphicsItem *parent, const PosterDat } //--------------------------------------------------------------------------------------------------------------------- -int VPoster::CountRows(int height) const +int VPoster::CountRows(int height, PageOrientation orientation) const { const qreal imgLength = height; - const qreal pageLength = PageRect().height(); + qreal pageLength = 0; - // Example - // ― ― - // * * - // * * - // * * - // * * ― - // ― ― * - // * * - // * * - // * * ― - // * ― * - // — * - // * * - // * * ― - // * ― * - // * * - // — * - // * * ― - // * ― * <-(2) - // * + * - // * + * - // — + * ― <-(4) - // ^ ^ ― * - //(3) (1) * - // * - // * - // ― + if(orientation == PageOrientation::Landscape) + { + pageLength = PageRect().width(); + } + else + { + pageLength = PageRect().height(); + } - const int pCount = qCeil(imgLength/pageLength);// Pages count without allowance (or allowance = 0) (3) - - // Calculate how many pages will be after using allowance. - // We know start pages count. This number not enought because - // each n-1 pages add (n-1)*allowance length to page (1). - const qreal addionalLength = (pCount-1)*static_cast(allowance); //-V636 - - // Calculate additional length form pages that will cover this length (2). - // In the end add page length (3). - // Bottom page have mandatory border (4) - return qCeil((addionalLength + - qCeil(addionalLength/pageLength)*static_cast(allowance) + static_cast(allowance) + - imgLength)/pageLength); + return qCeil(imgLength/(pageLength - static_cast(allowance))); } //--------------------------------------------------------------------------------------------------------------------- -int VPoster::CountColumns(int width) const +int VPoster::CountColumns(int width, PageOrientation orientation) const { const qreal imgLength = width; - const qreal pageLength = PageRect().width(); + qreal pageLength = 0; - // Example - // |----|----|----|----| <- (3) - // |----|+++++++++++++++ - // |----|+++++++++++ - // |----|+++++++ - // |----|+++ <- (1) - // |----| - // ^ - // (2) - const int pCount = qCeil(imgLength/pageLength);// Pages count without allowance (or allowance = 0) (3) + if(orientation == PageOrientation::Landscape) + { + pageLength = PageRect().height(); + } + else + { + pageLength = PageRect().width(); + } - // Calculate how many pages will be after using allowance. - // We know start pages count. This number not enought because - // each n-1 pages add (n-1)*allowance length to page (1). - const qreal addionalLength = (pCount-1)*static_cast(allowance); //-V636 - - // Calculate additional length form pages that will cover this length (2). - // In the end add page length (3). - return qCeil((addionalLength + qCeil(addionalLength/pageLength)*static_cast(allowance) + - imgLength)/pageLength); + return qCeil(imgLength/(pageLength-static_cast(allowance))); } //--------------------------------------------------------------------------------------------------------------------- -PosterData VPoster::Cut(int i, int j, const QRect &imageRect) const +PosterData VPoster::Cut(int i, int j, const QRect &imageRect, PageOrientation orientation) const { Q_UNUSED(imageRect) - const int x = j*PageRect().width() - j*static_cast(allowance); - const int y = i*PageRect().height() - i*static_cast(allowance); + int pageLengthX, pageLengthY; + + if(orientation == PageOrientation::Landscape) + { + pageLengthX = PageRect().height(); + pageLengthY = PageRect().width(); + } + else + { + pageLengthX = PageRect().width(); + pageLengthY = PageRect().height(); + } + + const int x = j*pageLengthX - j*static_cast(allowance); + const int y = i*pageLengthY - i*static_cast(allowance); SCASSERT(x <= imageRect.width()) SCASSERT(y <= imageRect.height()) @@ -255,7 +228,7 @@ PosterData VPoster::Cut(int i, int j, const QRect &imageRect) const PosterData data; data.row = static_cast(i); data.column = static_cast(j); - data.rect = QRect(x, y, PageRect().width(), PageRect().height()); + data.rect = QRect(x, y, pageLengthX, pageLengthY); return data; } diff --git a/src/libs/vlayout/vposter.h b/src/libs/vlayout/vposter.h index 3d2e037cc..1316d9947 100644 --- a/src/libs/vlayout/vposter.h +++ b/src/libs/vlayout/vposter.h @@ -33,6 +33,8 @@ #include #include +#include "../vmisc/def.h" + class QGraphicsItem; class QPrinter; template class QVector; @@ -62,17 +64,21 @@ class VPoster public: explicit VPoster(const QPrinter *printer); - QVector Calc(const QRect &imageRect, int page) const; + QVector Calc(const QRect &imageRect, int page, PageOrientation orientation) const; QVector Borders(QGraphicsItem *parent, const PosterData &img, int sheets) const; private: const QPrinter *printer; + /** + * @brief allowance is the width of the strip that holds the tiled + * grid information and that is used for the gluing. + */ quint32 allowance; - int CountRows(int height) const; - int CountColumns(int width) const; + int CountRows(int height, PageOrientation orientation) const; + int CountColumns(int width, PageOrientation orientation) const; - PosterData Cut(int i, int j, const QRect &imageRect) const; + PosterData Cut(int i, int j, const QRect &imageRect, PageOrientation orientation) const; QRect PageRect() const; diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 0e7e45c6d..84f504a09 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -342,6 +342,27 @@ qreal UnitConvertor(qreal value, const Unit &from, const Unit &to) return 0; } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief UnitConvertor Converts the values of the given margin from given unit to the new unit. + * returns a new instand of QMarginsF. + * + * @param margin + * @param from + * @param to + * @return + */ +QMarginsF UnitConvertor(const QMarginsF &margins, const Unit &from, const Unit &to) +{ + const qreal left = UnitConvertor(margins.left(), from, to); + const qreal top = UnitConvertor(margins.top(), from, to); + const qreal right = UnitConvertor(margins.right(), from, to); + const qreal bottom = UnitConvertor(margins.bottom(), from, to); + + return QMarginsF(left, top, right, bottom); +} + + //--------------------------------------------------------------------------------------------------------------------- QStringList SupportedLocales() { diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 886713ab3..0dbd0c4ac 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -62,6 +62,7 @@ enum class Unit : char { Mm = 0, Cm, Inch, Px, LAST_UNIT_DO_NOT_USE}; enum class Source : char { FromGui, FromFile, FromTool }; enum class NodeUsage : bool {NotInUse = false, InUse = true}; enum class SelectionType : bool {ByMousePress, ByMouseRelease}; +enum class PageOrientation : bool {Portrait = true, Landscape = false}; enum class PieceNodeAngle : unsigned char { @@ -416,6 +417,7 @@ Q_REQUIRED_RESULT double ToPixel(double val, const Unit &unit); Q_REQUIRED_RESULT double FromPixel(double pix, const Unit &unit); Q_REQUIRED_RESULT qreal UnitConvertor(qreal value, const Unit &from, const Unit &to); +Q_REQUIRED_RESULT QMarginsF UnitConvertor(const QMarginsF &margins, const Unit &from, const Unit &to); void InitLanguages(QComboBox *combobox); Q_REQUIRED_RESULT QStringList SupportedLocales(); diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index afa553b63..946376036 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -70,6 +71,11 @@ const QString settingIgnoreFields = QStringLiteral("layout/ignoreField const QString settingStripOptimization = QStringLiteral("layout/stripOptimization"); const QString settingMultiplier = QStringLiteral("layout/multiplier"); const QString settingTextAsPaths = QStringLiteral("layout/textAsPaths"); + +const QString settingTiledPDFMargins = QStringLiteral("tiledPDF/margins"); +const QString settingTiledPDFPaperHeight = QStringLiteral("tiledPDF/paperHeight"); +const QString settingTiledPDFPaperWidth = QStringLiteral("tiledPDF/paperWidth"); +const QString settingTiledPDFOrientation = QStringLiteral("tiledPDF/orientation"); } //--------------------------------------------------------------------------------------------------------------------- @@ -500,3 +506,117 @@ void VSettings::SetRememberPatternMaterials(bool value) { setValue(settingPatternRememberMaterials, value); } + +// settings for the tiled PDFs +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetTiledPDFMargins returns the tiled pdf margins in the given unit. When the setting is + * called for the first time, the 4 default margins are 10mm. + * @param unit + * @return + */ +QMarginsF VSettings::GetTiledPDFMargins(const Unit &unit) const +{ + // default value is 10mm. We save the margins in mm in the setting. + const QMarginsF def = QMarginsF(10, 10, 10, 10); + + const QVariant val = value(settingTiledPDFMargins, QVariant::fromValue(def)); + + if (val.canConvert()) + { + return UnitConvertor(val.value(), Unit::Mm, unit); + } + return UnitConvertor(def, Unit::Mm, unit); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief SetTiledPDFMargins sets the setting tiled pdf margins to the given value. + * @param value the margins to save + * @param unit the unit in which are the value. Necessary because we save the values + * internaly as mm so there is conversion beeing made. + */ +void VSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit) +{ + setValue(settingTiledPDFMargins, QVariant::fromValue(UnitConvertor(value, unit, Unit::Mm))); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetTiledPDFPaperHeight returns the paper height of tiled pdf in the desired unit. + * @param unit the unit to return the value to (internally it's saved as mm) + * @return + */ +qreal VSettings::GetTiledPDFPaperHeight(const Unit &unit) const +{ + const qreal def = 297 /*A4*/; + bool ok = false; + const qreal height = value(settingTiledPDFPaperHeight, def).toDouble(&ok); + if (ok) + { + return UnitConvertor(height, Unit::Mm, unit); + } + else + { + return UnitConvertor(def, Unit::Mm, unit); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief SetTiledPDFPaperHeight sets the tiled pdf paper height + * @param value in Mm + * @param unit unit of the given value + */ +void VSettings::SetTiledPDFPaperHeight(qreal value, const Unit &unit) +{ + setValue(settingTiledPDFPaperHeight, UnitConvertor(value, unit, Unit::Mm)); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetTiledPDFPaperWidth returns the paper height of tiled pdf in the desired unit. + * @param unit the unit to return the value to (internally it's saved as mm) + * @return + */ +qreal VSettings::GetTiledPDFPaperWidth(const Unit &unit) const +{ + + const qreal def = 210 /*A4*/; + bool ok = false; + const qreal width = value(settingTiledPDFPaperWidth, def).toDouble(&ok); + if (ok) + { + return UnitConvertor(width, Unit::Mm, unit); + } + else + { + return UnitConvertor(def, Unit::Mm, unit); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief SetTiledPDFPaperWidth sets the tiled pdf paper width + * @param unit unit of the given value + * @param value in Mm + */ +void VSettings::SetTiledPDFPaperWidth(qreal value, const Unit &unit) +{ + setValue(settingTiledPDFPaperWidth, UnitConvertor(value,unit, Unit::Mm)); +} + +//--------------------------------------------------------------------------------------------------------------------- +PageOrientation VSettings::GetTiledPDFOrientation() const +{ + bool defaultValue = static_cast(PageOrientation::Portrait); + bool result = value(settingTiledPDFOrientation, defaultValue).toBool(); + return static_cast(result); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSettings::SetTiledPDFOrientation(PageOrientation value) +{ + setValue(settingTiledPDFOrientation, static_cast (value)); +} + diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index 4fa58a148..0f752a9bd 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -35,6 +35,7 @@ #include #include +#include "../vmisc/def.h" #include "../vlayout/vbank.h" #include "vcommonsettings.h" @@ -131,6 +132,19 @@ public: bool IsRememberPatternMaterials() const; void SetRememberPatternMaterials(bool value); + // settings for the tiled PDFs + QMarginsF GetTiledPDFMargins(const Unit &unit) const; + void SetTiledPDFMargins(const QMarginsF &value, const Unit &unit); + + qreal GetTiledPDFPaperHeight(const Unit &unit) const; + void SetTiledPDFPaperHeight(qreal value, const Unit &unit); + + qreal GetTiledPDFPaperWidth(const Unit &unit) const; + void SetTiledPDFPaperWidth(qreal value, const Unit &unit); + + PageOrientation GetTiledPDFOrientation() const; + void SetTiledPDFOrientation(PageOrientation value); + private: Q_DISABLE_COPY(VSettings) }; diff --git a/src/test/ValentinaTest/tst_vposter.cpp b/src/test/ValentinaTest/tst_vposter.cpp index a5b1e0779..8dbc4afe6 100644 --- a/src/test/ValentinaTest/tst_vposter.cpp +++ b/src/test/ValentinaTest/tst_vposter.cpp @@ -61,7 +61,7 @@ void TST_VPoster::BigPoster() const QRect image(0, 0, 2622, 3178); // Little bit bigger than A1 VPoster posterazor(&printer); - const QVector poster = posterazor.Calc(image, 0); + const QVector poster = posterazor.Calc(image, 0, PageOrientation::Portrait); QCOMPARE(poster.size(), 12); @@ -81,7 +81,7 @@ void TST_VPoster::SmallPoster() const QRect image(0, 0, 700, 1000); // Little bit less than A4 VPoster posterazor(&printer); - const QVector poster = posterazor.Calc(image, 0); + const QVector poster = posterazor.Calc(image, 0, PageOrientation::Portrait); QCOMPARE(poster.size(), 1);