From 4411cccd9c86efdabb6cffa15642d83601de2d27 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Nov 2015 13:33:36 +0200 Subject: [PATCH 1/5] First draft of the issue #313. Layout pieces too close to right edge. --HG-- branch : feature --- .../dialogs/dialoglayoutsettings.cpp | 180 +++++++- .../valentina/dialogs/dialoglayoutsettings.h | 13 +- .../valentina/dialogs/dialoglayoutsettings.ui | 418 ++++++++++-------- src/app/valentina/mainwindowsnogui.cpp | 37 +- src/app/valentina/mainwindowsnogui.h | 1 + src/libs/vlayout/vlayoutgenerator.cpp | 28 +- src/libs/vlayout/vlayoutgenerator.h | 8 + src/libs/vlayout/vposter.cpp | 8 +- src/libs/vmisc/backport/qmarginsf.cpp | 374 ++++++++++++++++ src/libs/vmisc/backport/qmarginsf.h | 251 +++++++++++ src/libs/vmisc/def.cpp | 24 + src/libs/vmisc/def.h | 3 + src/libs/vmisc/vmargins.h | 43 ++ src/libs/vmisc/vmisc.pri | 7 +- src/libs/vmisc/vmisc.pro | 2 +- src/libs/vmisc/vsettings.cpp | 93 +++- src/libs/vmisc/vsettings.h | 16 + 17 files changed, 1270 insertions(+), 236 deletions(-) create mode 100644 src/libs/vmisc/backport/qmarginsf.cpp create mode 100644 src/libs/vmisc/backport/qmarginsf.h create mode 100644 src/libs/vmisc/vmargins.h diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index 00b02afd1..1e131a91d 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -38,6 +38,7 @@ # include #endif +#include #include //must be the same order as PaperSizeTemplate constants @@ -98,6 +99,13 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget connect(ui->doubleSpinBoxPaperHeight, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogLayoutSettings::FindTemplate); + connect(ui->doubleSpinBoxPaperWidth, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogLayoutSettings::CorrectMaxFileds); + connect(ui->doubleSpinBoxPaperHeight, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogLayoutSettings::CorrectMaxFileds); + + connect(ui->checkBoxIgnoreFileds, &QCheckBox::stateChanged, this, &DialogLayoutSettings::IgnoreAllFields); + connect(ui->toolButtonPortrate, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->comboBoxLayoutUnit, static_cast(&QComboBox::currentIndexChanged), @@ -125,6 +133,7 @@ qreal DialogLayoutSettings::GetPaperHeight() const //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::SetPaperHeight(qreal value) { + ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, PaperUnit())); ui->doubleSpinBoxPaperHeight->setValue(UnitConvertor(value, Unit::Px, PaperUnit())); } @@ -137,6 +146,7 @@ qreal DialogLayoutSettings::GetPaperWidth() const //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::SetPaperWidth(qreal value) { + ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, PaperUnit())); ui->doubleSpinBoxPaperWidth->setValue(UnitConvertor(value, Unit::Px, PaperUnit())); } @@ -164,6 +174,26 @@ void DialogLayoutSettings::SetLayoutWidth(qreal value) ui->doubleSpinBoxLayoutWidth->setValue(UnitConvertor(value, Unit::Px, LayoutUnit())); } +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF DialogLayoutSettings::GetFields() const +{ + QMarginsF fields; + fields.setLeft(UnitConvertor(ui->doubleSpinBoxLeftField->value(), oldLayoutUnit, Unit::Px)); + fields.setRight(UnitConvertor(ui->doubleSpinBoxRightField->value(), oldLayoutUnit, Unit::Px)); + fields.setTop(UnitConvertor(ui->doubleSpinBoxTopField->value(), oldLayoutUnit, Unit::Px)); + fields.setBottom(UnitConvertor(ui->doubleSpinBoxBottomField->value(), oldLayoutUnit, Unit::Px)); + return fields; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::SetFields(const QMarginsF &value) +{ + ui->doubleSpinBoxLeftField->setValue(UnitConvertor(value.left(), Unit::Px, LayoutUnit())); + ui->doubleSpinBoxRightField->setValue(UnitConvertor(value.right(), Unit::Px, LayoutUnit())); + ui->doubleSpinBoxTopField->setValue(UnitConvertor(value.top(), Unit::Px, LayoutUnit())); + ui->doubleSpinBoxBottomField->setValue(UnitConvertor(value.bottom(), Unit::Px, LayoutUnit())); +} + //--------------------------------------------------------------------------------------------------------------------- Cases DialogLayoutSettings::GetGroup() const { @@ -271,6 +301,18 @@ void DialogLayoutSettings::SetUnitePages(bool save) ui->checkBoxUnitePages->setChecked(save); } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogLayoutSettings::IsIgnoreAllFields() const +{ + return ui->checkBoxIgnoreFileds->isChecked(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::SetIgnoreAllFields(bool value) +{ + ui->checkBoxIgnoreFileds->setChecked(value); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::TemplateSelected() { @@ -317,6 +359,11 @@ void DialogLayoutSettings::ConvertPaperSize() const qreal width = ui->doubleSpinBoxPaperWidth->value(); const qreal height = ui->doubleSpinBoxPaperHeight->value(); + const qreal left = ui->doubleSpinBoxLeftField->value(); + const qreal right = ui->doubleSpinBoxRightField->value(); + const qreal top = ui->doubleSpinBoxTopField->value(); + const qreal bottom = ui->doubleSpinBoxBottomField->value(); + ui->doubleSpinBoxPaperWidth->blockSignals(true); ui->doubleSpinBoxPaperHeight->blockSignals(true); ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, paperUnit)); @@ -327,12 +374,22 @@ void DialogLayoutSettings::ConvertPaperSize() const qreal newWidth = UnitConvertor(width, oldPaperUnit, paperUnit); const qreal newHeight = UnitConvertor(height, oldPaperUnit, paperUnit); + const qreal newLeft = UnitConvertor(left, oldPaperUnit, paperUnit); + const qreal newRight = UnitConvertor(right, oldPaperUnit, paperUnit); + const qreal newTop = UnitConvertor(top, oldPaperUnit, paperUnit); + const qreal newBottom = UnitConvertor(bottom, oldPaperUnit, paperUnit); + oldPaperUnit = paperUnit; CorrectPaperDecimals(); MinimumPaperSize(); ui->doubleSpinBoxPaperWidth->setValue(newWidth); ui->doubleSpinBoxPaperHeight->setValue(newHeight); + + ui->doubleSpinBoxLeftField->setValue(newLeft); + ui->doubleSpinBoxRightField->setValue(newRight); + ui->doubleSpinBoxTopField->setValue(newTop); + ui->doubleSpinBoxBottomField->setValue(newBottom); } //--------------------------------------------------------------------------------------------------------------------- @@ -433,8 +490,6 @@ void DialogLayoutSettings::PaperSizeChanged() ui->toolButtonLandscape->setChecked(true); ui->toolButtonLandscape->blockSignals(false); } - - Label(); } //--------------------------------------------------------------------------------------------------------------------- @@ -464,8 +519,6 @@ void DialogLayoutSettings::Swap(bool checked) ui->doubleSpinBoxPaperHeight->blockSignals(true); ui->doubleSpinBoxPaperHeight->setValue(width); ui->doubleSpinBoxPaperHeight->blockSignals(false); - - Label(); } } @@ -484,6 +537,48 @@ void DialogLayoutSettings::DialogAccepted() generator->SetSaveLength(IsSaveLength()); generator->SetUnitePages(IsUnitePages()); + if (IsIgnoreAllFields()) + { + generator->SetFields(QMarginsF()); + } + else + { + const QMarginsF minFields = RoundMargins(VSettings::GetDefFields()); + const QMarginsF fields = RoundMargins(GetFields()); + if (fields.left() < minFields.left() || fields.right() < minFields.right() || + fields.top() < minFields.top() || fields.bottom() < minFields.bottom()) + { + QMessageBox::StandardButton answer; + answer = QMessageBox::question(this, tr("Wrong fields."), + tr("Fields go beyond printing. \n\nApply settings anyway?"), + QMessageBox::Yes|QMessageBox::No, QMessageBox::No); + if (answer == QMessageBox::No) + { + if (fields.left() < minFields.left()) + { + ui->doubleSpinBoxLeftField->setValue(UnitConvertor(minFields.left(), Unit::Px, LayoutUnit())); + } + + if (fields.right() < minFields.right()) + { + ui->doubleSpinBoxRightField->setValue(UnitConvertor(minFields.right(), Unit::Px, LayoutUnit())); + } + + if (fields.top() < minFields.top()) + { + ui->doubleSpinBoxTopField->setValue(UnitConvertor(minFields.top(), Unit::Px, LayoutUnit())); + } + + if (fields.bottom() < minFields.bottom()) + { + ui->doubleSpinBoxBottomField->setValue(UnitConvertor(minFields.bottom(), Unit::Px, LayoutUnit())); + } + } + } + + generator->SetFields(GetFields()); + } + //don't want to break visual settings when cmd used if (disableSettings == false) { @@ -505,6 +600,36 @@ void DialogLayoutSettings::RestoreDefaults() SetGroup(VSettings::GetDefLayoutGroup()); SetRotate(VSettings::GetDefLayoutRotate()); SetIncrease(VSettings::GetDefLayoutRotationIncrease()); + SetFields(VSettings::GetDefFields()); + SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields()); + + CorrectMaxFileds(); + IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::CorrectMaxFileds() +{ + const qreal width = ui->doubleSpinBoxPaperWidth->value(); + const qreal height = ui->doubleSpinBoxPaperHeight->value(); + + // 80%/2 of paper size for each field + const qreal widthField = (width*80.0/100.0)/2.0; + const qreal heightField = (height*80.0/100.0)/2.0; + + ui->doubleSpinBoxLeftField->setMaximum(widthField); + ui->doubleSpinBoxRightField->setMaximum(widthField); + ui->doubleSpinBoxTopField->setMaximum(heightField); + ui->doubleSpinBoxBottomField->setMaximum(heightField); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::IgnoreAllFields(int state) +{ + ui->doubleSpinBoxLeftField->setDisabled(state); + ui->doubleSpinBoxRightField->setDisabled(state); + ui->doubleSpinBoxTopField->setDisabled(state); + ui->doubleSpinBoxBottomField->setDisabled(state); } //--------------------------------------------------------------------------------------------------------------------- @@ -711,6 +836,17 @@ QSizeF DialogLayoutSettings::RoundTemplateSize(qreal width, qreal height) const return QSizeF(width, height); } +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF DialogLayoutSettings::RoundMargins(const QMarginsF &margins) const +{ + QMarginsF newMargins; + newMargins.setLeft(qRound(margins.left() * 100.0) / 100.0); + newMargins.setRight(qRound(margins.right() * 100.0) / 100.0); + newMargins.setTop(qRound(margins.top() * 100.0) / 100.0); + newMargins.setBottom(qRound(margins.bottom() * 100.0) / 100.0); + return newMargins; +} + //--------------------------------------------------------------------------------------------------------------------- Unit DialogLayoutSettings::PaperUnit() const { @@ -740,16 +876,23 @@ void DialogLayoutSettings::CorrectPaperDecimals() { case Unit::Cm: case Unit::Mm: + case Unit::Px: ui->doubleSpinBoxPaperWidth->setDecimals(2); ui->doubleSpinBoxPaperHeight->setDecimals(2); + + ui->doubleSpinBoxLeftField->setDecimals(4); + ui->doubleSpinBoxRightField->setDecimals(4); + ui->doubleSpinBoxTopField->setDecimals(4); + ui->doubleSpinBoxBottomField->setDecimals(4); break; case Unit::Inch: ui->doubleSpinBoxPaperWidth->setDecimals(5); ui->doubleSpinBoxPaperHeight->setDecimals(5); - break; - case Unit::Px: - ui->doubleSpinBoxPaperWidth->setDecimals(2); - ui->doubleSpinBoxPaperHeight->setDecimals(2); + + ui->doubleSpinBoxLeftField->setDecimals(5); + ui->doubleSpinBoxRightField->setDecimals(5); + ui->doubleSpinBoxTopField->setDecimals(5); + ui->doubleSpinBoxBottomField->setDecimals(5); break; default: break; @@ -763,6 +906,7 @@ void DialogLayoutSettings::CorrectLayoutDecimals() { case Unit::Cm: case Unit::Mm: + case Unit::Px: ui->doubleSpinBoxLayoutWidth->setDecimals(2); ui->doubleSpinBoxShift->setDecimals(2); break; @@ -770,24 +914,11 @@ void DialogLayoutSettings::CorrectLayoutDecimals() ui->doubleSpinBoxLayoutWidth->setDecimals(5); ui->doubleSpinBoxShift->setDecimals(5); break; - case Unit::Px: - ui->doubleSpinBoxLayoutWidth->setDecimals(2); - ui->doubleSpinBoxShift->setDecimals(2); - break; default: break; } } -//--------------------------------------------------------------------------------------------------------------------- -void DialogLayoutSettings::Label() -{ - const int width = qFloor(UnitConvertor(ui->doubleSpinBoxPaperWidth->value(), PaperUnit(), Unit::Px)); - const int height = qFloor(UnitConvertor(ui->doubleSpinBoxPaperHeight->value(), PaperUnit(), Unit::Px)); - QString text = QString("%1 x %2 px, \n%3 ppi").arg(width).arg(height).arg(PrintDPI); - ui->labelSizeDescription->setText(text); -} - //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::MinimumPaperSize() { @@ -819,8 +950,13 @@ void DialogLayoutSettings::ReadSettings() SetAutoCrop(settings->GetLayoutAutoCrop()); SetSaveLength(settings->GetLayoutSaveLength()); SetUnitePages(settings->GetLayoutUnitePages()); + SetFields(settings->GetFields()); + SetIgnoreAllFields(settings->GetIgnoreAllFields()); FindTemplate(); + + CorrectMaxFileds(); + IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked()); } //--------------------------------------------------------------------------------------------------------------------- @@ -837,6 +973,8 @@ void DialogLayoutSettings::WriteSettings() const settings->SetLayoutAutoCrop(GetAutoCrop()); settings->SetLayoutSaveLength(IsSaveLength()); settings->SetLayoutUnitePages(IsUnitePages()); + settings->SetFields(GetFields()); + settings->SetIgnoreAllFields(IsIgnoreAllFields()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.h b/src/app/valentina/dialogs/dialoglayoutsettings.h index 75743db20..a3395a36a 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.h +++ b/src/app/valentina/dialogs/dialoglayoutsettings.h @@ -35,6 +35,7 @@ #include "../vlayout/vbank.h" #include "../ifc/ifcdef.h" #include "../vlayout/vlayoutgenerator.h" +#include "../vmisc/vmargins.h" namespace Ui { @@ -75,6 +76,9 @@ public: qreal GetLayoutWidth() const; void SetLayoutWidth(qreal value); + QMarginsF GetFields() const; + void SetFields(const QMarginsF &value); + Cases GetGroup() const; void SetGroup(const Cases &value); @@ -93,6 +97,9 @@ public: bool IsUnitePages() const; void SetUnitePages(bool save); + bool IsIgnoreAllFields() const; + void SetIgnoreAllFields(bool value); + //support functions for the command line parser which uses invisible dialog to properly build layout generator bool SelectTemplate(const PaperSizeTemplate& id); static QString MakeHelpTemplateList(); @@ -114,7 +121,9 @@ public slots: void DialogAccepted(); void RestoreDefaults(); - +private slots: + void CorrectMaxFileds(); + void IgnoreAllFields(int state); private: Q_DISABLE_COPY(DialogLayoutSettings) typedef QStringList FormatsVector; @@ -135,13 +144,13 @@ private: QSizeF Template(); QSizeF TemplateSize(const PaperSizeTemplate &tmpl) const; QSizeF RoundTemplateSize(qreal width, qreal height) const; + QMarginsF RoundMargins(const QMarginsF &margins) const; Unit PaperUnit() const; Unit LayoutUnit() const; void CorrectPaperDecimals(); void CorrectLayoutDecimals(); - void Label(); void MinimumPaperSize(); void MinimumLayoutSize(); diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.ui b/src/app/valentina/dialogs/dialoglayoutsettings.ui index ff6c761bc..e755a1707 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.ui +++ b/src/app/valentina/dialogs/dialoglayoutsettings.ui @@ -7,7 +7,7 @@ 0 0 661 - 345 + 453 @@ -23,12 +23,12 @@ - + false - Paper size + Paper format false @@ -72,22 +72,6 @@ - - - - - 0 - 0 - - - - - 124 - 0 - - - - @@ -146,14 +130,7 @@ - - - - TextLabel - - - - + @@ -203,175 +180,77 @@ + + + + + 0 + 0 + + + + + 124 + 0 + + + + - - - - Auto crop unused length - - - - - - - Unite pages (if possible) - - - - - - Qt::Horizontal - - - - - + - Rotate workpiece + Fields - - true - - - - - - - 0 - 0 - - + + + - Rotate by + Left: - - - - 21 + + + + + + + Right: - - - 1 - - - - - 2 - - - - - 3 - - - - - 4 - - - - - 5 - - - - - 6 - - - - - 8 - - - - - 9 - - - - - 10 - - - - - 12 - - - - - 15 - - - - - 18 - - - - - 20 - - - - - 24 - - - - - 30 - - - - - 36 - - - - - 40 - - - - - 45 - - - - - 60 - - - - - 72 - - - - - 90 - - - - - 180 - - - - + + + + + - degree + Top: + + + + + + + + + + Bottom: + + + + + + + + + + Ignore fileds @@ -463,6 +342,162 @@ + + + + Rotate workpiece + + + true + + + + + + + 0 + 0 + + + + Rotate by + + + + + + + 21 + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 12 + + + + + 15 + + + + + 18 + + + + + 20 + + + + + 24 + + + + + 30 + + + + + 36 + + + + + 40 + + + + + 45 + + + + + 60 + + + + + 72 + + + + + 90 + + + + + 180 + + + + + + + + degree + + + + + + + + + + Qt::Horizontal + + + @@ -512,6 +547,27 @@ + + + + Qt::Horizontal + + + + + + + Auto crop unused length + + + + + + + Unite pages (if possible) + + + @@ -567,7 +623,7 @@ - + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 98947e9ee..cfef7d7a1 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -62,7 +62,7 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), doc(nullptr), papers(QList()), shadows(QList()), scenes(QList()), details(QList >()), undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), - isLayoutStale(true), isTiled(false) + isLayoutStale(true), margins(), isTiled(false) { InitTempLayoutScene(); } @@ -132,6 +132,7 @@ bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator) CreateShadows(); CreateScenes(); PrepareSceneList(); + margins = lGenerator.GetFields(); isLayoutStale = false; break; case LayoutErrors::ProcessStoped: @@ -356,7 +357,7 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) { index = lastPage - j; } - painter.drawImage(QPointF(), poster.at(index)); + painter.drawImage(QPointF(margins.left(), margins.top()), poster.at(index)); } } @@ -789,28 +790,18 @@ void MainWindowsNoGUI::PrintPreview() return; } } - QPrinterInfo def = QPrinterInfo::defaultPrinter(); - //if there is no default printer set the print preview won't show - if(def.isNull() || def.printerName().isEmpty()) + QSharedPointer printer = DefaultPrinter(); + if (printer.isNull()) { - if(QPrinterInfo::availablePrinters().isEmpty()) - { - qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), - qUtf8Printable(tr("Cannot proceed because there are no available printers in your system."))); - return; - } - else - { - def = QPrinterInfo::availablePrinters().first(); - } + qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), + qUtf8Printable(tr("Cannot proceed because there are no available printers in your system."))); + return; } - QPrinter printer(def, QPrinter::ScreenResolution); - printer.setResolution(static_cast(PrintDPI)); - SetPrinterSettings(&printer); + SetPrinterSettings(printer.data()); // display print preview dialog - QPrintPreviewDialog preview(&printer); + QPrintPreviewDialog preview(printer.data()); connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages); preview.exec(); } @@ -867,6 +858,14 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer) FromPixel(paper->rect().height(), Unit::Mm)), QPrinter::Millimeter ); } + { + 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); + printer->setPageMargins(left, top, right, bottom, QPrinter::Millimeter); + } + printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName() + QLatin1Literal(".pdf")); printer->setDocName(FileName()); diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 05a514eec..549b70f20 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -87,6 +87,7 @@ protected: QString curFile; bool isLayoutStale; + QMarginsF margins; void PrepareDetailsForLayout(const QHash *details); void ExportLayout(const DialogSaveLayout &dialog); diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 25f7f8da3..5bb039bde 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -38,7 +38,7 @@ //--------------------------------------------------------------------------------------------------------------------- VLayoutGenerator::VLayoutGenerator(QObject *parent) - :QObject(parent), papers(QVector()), bank(new VBank()), paperHeight(0), paperWidth(0), + :QObject(parent), papers(QVector()), bank(new VBank()), paperHeight(0), paperWidth(0), margins(), stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), rotationIncrease(180), autoCrop(false), saveLength(false), unitePages(false) {} @@ -99,7 +99,7 @@ void VLayoutGenerator::Generate() break; } - VLayoutPaper paper(paperHeight, paperWidth); + VLayoutPaper paper(PageHeight(), PageWidth()); paper.SetShift(shift); paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetPaperIndex(static_cast(papers.count())); @@ -189,6 +189,18 @@ void VLayoutGenerator::Abort() #endif } +//--------------------------------------------------------------------------------------------------------------------- +int VLayoutGenerator::PageHeight() const +{ + return paperHeight - static_cast(margins.top() + margins.bottom()); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VLayoutGenerator::PageWidth() const +{ + return paperWidth - static_cast(margins.left() + margins.right()); +} + //--------------------------------------------------------------------------------------------------------------------- bool VLayoutGenerator::IsUnitePages() const { @@ -267,6 +279,18 @@ void VLayoutGenerator::SetPaperWidth(int value) paperWidth = value; } +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VLayoutGenerator::GetFields() const +{ + return margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::SetFields(const QMarginsF &value) +{ + margins = value; +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VLayoutGenerator::GetShift() const { diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 224f0d0db..429e017e8 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -34,6 +34,7 @@ #include "vlayoutdef.h" #include "vbank.h" +#include "../vmisc/vmargins.h" #include class VLayoutPaper; @@ -58,6 +59,9 @@ public: int GetPaperWidth() const; void SetPaperWidth(int value); + QMarginsF GetFields() const; + void SetFields(const QMarginsF &value); + quint32 GetShift() const; void SetShift(quint32 shift); @@ -98,6 +102,7 @@ private: VBank *bank; int paperHeight; int paperWidth; + QMarginsF margins; volatile bool stopGeneration; LayoutErrors state; quint32 shift; @@ -106,6 +111,9 @@ private: bool autoCrop; bool saveLength; bool unitePages; + + int PageHeight() const; + int PageWidth() const; }; typedef std::shared_ptr VLayoutGeneratorPtr; diff --git a/src/libs/vlayout/vposter.cpp b/src/libs/vlayout/vposter.cpp index 6cb3510c0..f26c36f0c 100644 --- a/src/libs/vlayout/vposter.cpp +++ b/src/libs/vlayout/vposter.cpp @@ -190,7 +190,7 @@ QImage VPoster::Borders(int rows, int colomns, int i, int j, QImage &image, int pen.setColor(Qt::black); painter.setPen(pen); - const QRect rec = image.rect(); + const QRect rec = image.rect(); if (j != 0 && PageRect().x() > 0) {// Left border painter.drawLine(QLine(0, 0, 0, rec.height())); @@ -244,11 +244,11 @@ QImage VPoster::Borders(int rows, int colomns, int i, int j, QImage &image, int QRect VPoster::PageRect() const { // Because the Point unit is defined to be 1/72th of an inch - // we can't use method pageRect(QPrinter::Point). Our dpi different can be different. + // we can't use method pageRect(QPrinter::Point). Our dpi value can be different. // We convert value yourself to pixels. const QRectF rect = printer->pageRect(QPrinter::Millimeter); - QRect pageRect(qFloor(ToPixel(rect.x())), qFloor(ToPixel(rect.y())), qFloor(ToPixel(rect.width())), - qFloor(ToPixel(rect.height()))); + const QRect pageRect(qFloor(ToPixel(rect.x())), qFloor(ToPixel(rect.y())), qFloor(ToPixel(rect.width())), + qFloor(ToPixel(rect.height()))); return pageRect; } diff --git a/src/libs/vmisc/backport/qmarginsf.cpp b/src/libs/vmisc/backport/qmarginsf.cpp new file mode 100644 index 000000000..cfff0d988 --- /dev/null +++ b/src/libs/vmisc/backport/qmarginsf.cpp @@ -0,0 +1,374 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmarginsf.h" +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) +#include +#include + +/*! + \class QMarginsF + \inmodule QtCore + \ingroup painting + \since 5.3 + + \brief The QMarginsF class defines the four margins of a rectangle. + + QMarginsF defines a set of four margins; left, top, right and bottom, + that describe the size of the borders surrounding a rectangle. + + The isNull() function returns \c true only if all margins are set to zero. + + QMarginsF objects can be streamed as well as compared. +*/ + + +/***************************************************************************** + QMarginsF member functions + *****************************************************************************/ + +/*! + \fn QMarginsF::QMarginsF() + + Constructs a margins object with all margins set to 0. + + \sa isNull() +*/ + +/*! + \fn QMarginsF::QMarginsF(qreal left, qreal top, qreal right, qreal bottom) + + Constructs margins with the given \a left, \a top, \a right, \a bottom + + \sa setLeft(), setRight(), setTop(), setBottom() +*/ + +/*! + \fn QMarginsF::QMarginsF(const QMargins &margins) + + Constructs margins copied from the given \a margins +*/ + +/*! + \fn bool QMarginsF::isNull() const + + Returns \c true if all margins are 0; otherwise returns + false. +*/ + + +/*! + \fn qreal QMarginsF::left() const + + Returns the left margin. + + \sa setLeft() +*/ + +/*! + \fn qreal QMarginsF::top() const + + Returns the top margin. + + \sa setTop() +*/ + +/*! + \fn qreal QMarginsF::right() const + + Returns the right margin. +*/ + +/*! + \fn qreal QMarginsF::bottom() const + + Returns the bottom margin. +*/ + + +/*! + \fn void QMarginsF::setLeft(qreal left) + + Sets the left margin to \a left. +*/ + +/*! + \fn void QMarginsF::setTop(qreal Top) + + Sets the Top margin to \a Top. +*/ + +/*! + \fn void QMarginsF::setRight(qreal right) + + Sets the right margin to \a right. +*/ + +/*! + \fn void QMarginsF::setBottom(qreal bottom) + + Sets the bottom margin to \a bottom. +*/ + +/*! + \fn bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns \c true if \a lhs and \a rhs are equal; otherwise returns \c false. +*/ + +/*! + \fn bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns \c true if \a lhs and \a rhs are different; otherwise returns \c false. +*/ + +/*! + \fn const QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns a QMarginsF object that is the sum of the given margins, \a lhs + and \a rhs; each component is added separately. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns a QMarginsF object that is formed by subtracting \a rhs from + \a lhs; each component is subtracted separately. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator+(const QMarginsF &lhs, qreal rhs) + \relates QMarginsF + + Returns a QMarginsF object that is formed by adding \a rhs to + \a lhs. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator+(qreal lhs, const QMarginsF &rhs) + \relates QMarginsF + + Returns a QMarginsF object that is formed by adding \a lhs to + \a rhs. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator-(const QMarginsF &lhs, qreal rhs) + \relates QMarginsF + + Returns a QMarginsF object that is formed by subtracting \a rhs from + \a lhs. + + \sa QMarginsF::operator+=(), QMarginsF::operator-=() +*/ + +/*! + \fn const QMarginsF operator*(const QMarginsF &lhs, qreal rhs) + \relates QMarginsF + \overload + + Returns a QMarginsF object that is formed by multiplying each component + of the given \a lhs margins by \a rhs factor. + + \sa QMarginsF::operator*=(), QMarginsF::operator/=() +*/ + +/*! + \fn const QMarginsF operator*(qreal lhs, const QMarginsF &rhs) + \relates QMarginsF + \overload + + Returns a QMarginsF object that is formed by multiplying each component + of the given \a lhs margins by \a rhs factor. + + \sa QMarginsF::operator*=(), QMarginsF::operator/=() +*/ + +/*! + \fn const QMarginsF operator/(const QMarginsF &lhs, qreal rhs) + \relates QMarginsF + \overload + + Returns a QMarginsF object that is formed by dividing the components of + the given \a lhs margins by the given \a rhs divisor. + + \sa QMarginsF::operator*=(), QMarginsF::operator/=() +*/ + +/*! + \fn QMarginsF operator+(const QMarginsF &margins) + \relates QMarginsF + + Returns a QMargin object that is formed from all components of \a margins. +*/ + +/*! + \fn QMarginsF operator-(const QMarginsF &margins) + \relates QMarginsF + + Returns a QMargin object that is formed by negating all components of \a margins. +*/ + +/*! + \fn QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) + + Add each component of \a margins to the respective component of this object + and returns a reference to it. + + \sa operator-=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) + + Subtract each component of \a margins from the respective component of this object + and returns a reference to it. + + \sa operator+=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator+=(qreal addend) + \overload + + Adds the \a addend to each component of this object + and returns a reference to it. + + \sa operator-=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator-=(qreal subtrahend) + \overload + + Subtracts the \a subtrahend from each component of this object + and returns a reference to it. + + \sa operator+=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator*=(qreal factor) + + Multiplies each component of this object by \a factor + and returns a reference to it. + + \sa operator/=() +*/ + +/*! + \fn QMarginsF &QMarginsF::operator/=(qreal divisor) + + Divides each component of this object by \a divisor + and returns a reference to it. + + \sa operator*=() +*/ + +/*! + \fn QMargins QMarginsF::toMargins() const + + Returns an integer based copy of this margins object. + + Note that the components in the returned margins will be rounded to + the nearest integer. + + \sa QMarginsF() +*/ + +/***************************************************************************** + QMarginsF stream functions + *****************************************************************************/ +#ifndef QT_NO_DATASTREAM +/*! + \fn QDataStream &operator<<(QDataStream &stream, const QMarginsF &m) + \relates QMarginsF + + Writes margin \a m to the given \a stream and returns a + reference to the stream. + + \sa {Serializing Qt Data Types} +*/ + +QDataStream &operator<<(QDataStream &s, const QMarginsF &m) +{ + s << double(m.left()) << double(m.top()) << double(m.right()) << double(m.bottom()); + return s; +} + +/*! + \fn QDataStream &operator>>(QDataStream &stream, QMarginsF &m) + \relates QMarginsF + + Reads a margin from the given \a stream into margin \a m + and returns a reference to the stream. + + \sa {Serializing Qt Data Types} +*/ + +QDataStream &operator>>(QDataStream &s, QMarginsF &m) +{ + double left, top, right, bottom; + s >> left; + s >> top; + s >> right; + s >> bottom; + m = QMarginsF(qreal(left), qreal(top), qreal(right), qreal(bottom)); + return s; +} +#endif // QT_NO_DATASTREAM + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QMarginsF &m) +{ + QDebugStateSaver saver(dbg); + dbg.nospace(); + dbg << "QMarginsF" << '('; + dbg << m.left() << ", " << m.top() << ", " << m.right() << ", " << m.bottom(); + dbg << ')'; + return dbg; +} +#endif +#endif // QT_VERSION < QT_VERSION_CHECK(5, 3, 0) diff --git a/src/libs/vmisc/backport/qmarginsf.h b/src/libs/vmisc/backport/qmarginsf.h new file mode 100644 index 000000000..cf27ba8a6 --- /dev/null +++ b/src/libs/vmisc/backport/qmarginsf.h @@ -0,0 +1,251 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMARGINSF_H +#define QMARGINSF_H + +#include + +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) +#include + +/***************************************************************************** + QMarginsF class + *****************************************************************************/ + +class QMarginsF +{ +public: + Q_DECL_CONSTEXPR QMarginsF() Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom) Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins) Q_DECL_NOTHROW; + + Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW; + + Q_DECL_CONSTEXPR qreal left() const Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR qreal top() const Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR qreal right() const Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR qreal bottom() const Q_DECL_NOTHROW; + + void setLeft(qreal left) Q_DECL_NOTHROW; + void setTop(qreal top) Q_DECL_NOTHROW; + void setRight(qreal right) Q_DECL_NOTHROW; + void setBottom(qreal bottom) Q_DECL_NOTHROW; + + QMarginsF &operator+=(const QMarginsF &margins) Q_DECL_NOTHROW; + QMarginsF &operator-=(const QMarginsF &margins) Q_DECL_NOTHROW; + QMarginsF &operator+=(qreal addend) Q_DECL_NOTHROW; + QMarginsF &operator-=(qreal subtrahend) Q_DECL_NOTHROW; + QMarginsF &operator*=(qreal factor) Q_DECL_NOTHROW; + QMarginsF &operator/=(qreal divisor); + + Q_DECL_CONSTEXPR inline QMargins toMargins() const Q_DECL_NOTHROW; + +private: + qreal m_left; + qreal m_top; + qreal m_right; + qreal m_bottom; +}; + +Q_DECLARE_TYPEINFO(QMarginsF, Q_MOVABLE_TYPE); + +/***************************************************************************** + QMarginsF stream functions + *****************************************************************************/ + +#ifndef QT_NO_DATASTREAM +Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMarginsF &); +Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &); +#endif + +/***************************************************************************** + QMarginsF inline functions + *****************************************************************************/ + +Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() Q_DECL_NOTHROW + : m_left(0), m_top(0), m_right(0), m_bottom(0) {} + +Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom) Q_DECL_NOTHROW + : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {} + +Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins) Q_DECL_NOTHROW + : m_left(margins.left()), m_top(margins.top()), m_right(margins.right()), m_bottom(margins.bottom()) {} + +Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const Q_DECL_NOTHROW +{ return qFuzzyIsNull(m_left) && qFuzzyIsNull(m_top) && qFuzzyIsNull(m_right) && qFuzzyIsNull(m_bottom); } + +Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const Q_DECL_NOTHROW +{ return m_left; } + +Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const Q_DECL_NOTHROW +{ return m_top; } + +Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const Q_DECL_NOTHROW +{ return m_right; } + +Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const Q_DECL_NOTHROW +{ return m_bottom; } + +inline void QMarginsF::setLeft(qreal aleft) Q_DECL_NOTHROW +{ m_left = aleft; } + +inline void QMarginsF::setTop(qreal atop) Q_DECL_NOTHROW +{ m_top = atop; } + +inline void QMarginsF::setRight(qreal aright) Q_DECL_NOTHROW +{ m_right = aright; } + +inline void QMarginsF::setBottom(qreal abottom) Q_DECL_NOTHROW +{ m_bottom = abottom; } + +Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +{ + return qFuzzyCompare(lhs.left(), rhs.left()) + && qFuzzyCompare(lhs.top(), rhs.top()) + && qFuzzyCompare(lhs.right(), rhs.right()) + && qFuzzyCompare(lhs.bottom(), rhs.bottom()); +} + +Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +{ + return !operator==(lhs, rhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +{ + return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(), + lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom()); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +{ + return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(), + lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW +{ + return QMarginsF(lhs.left() + rhs, lhs.top() + rhs, + lhs.right() + rhs, lhs.bottom() + rhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +{ + return QMarginsF(rhs.left() + lhs, rhs.top() + lhs, + rhs.right() + lhs, rhs.bottom() + lhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW +{ + return QMarginsF(lhs.left() - rhs, lhs.top() - rhs, + lhs.right() - rhs, lhs.bottom() - rhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW +{ + return QMarginsF(lhs.left() * rhs, lhs.top() * rhs, + lhs.right() * rhs, lhs.bottom() * rhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW +{ + return QMarginsF(rhs.left() * lhs, rhs.top() * lhs, + rhs.right() * lhs, rhs.bottom() * lhs); +} + +Q_DECL_CONSTEXPR inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor) +{ + return QMarginsF(lhs.left() / divisor, lhs.top() / divisor, + lhs.right() / divisor, lhs.bottom() / divisor); +} + +inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) Q_DECL_NOTHROW +{ + return *this = *this + margins; +} + +inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) Q_DECL_NOTHROW +{ + return *this = *this - margins; +} + +inline QMarginsF &QMarginsF::operator+=(qreal addend) Q_DECL_NOTHROW +{ + m_left += addend; + m_top += addend; + m_right += addend; + m_bottom += addend; + return *this; +} + +inline QMarginsF &QMarginsF::operator-=(qreal subtrahend) Q_DECL_NOTHROW +{ + m_left -= subtrahend; + m_top -= subtrahend; + m_right -= subtrahend; + m_bottom -= subtrahend; + return *this; +} + +inline QMarginsF &QMarginsF::operator*=(qreal factor) Q_DECL_NOTHROW +{ + return *this = *this * factor; +} + +inline QMarginsF &QMarginsF::operator/=(qreal divisor) +{ + return *this = *this / divisor; +} + +Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins) Q_DECL_NOTHROW +{ + return margins; +} + +Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins) Q_DECL_NOTHROW +{ + return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom()); +} + +Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const Q_DECL_NOTHROW +{ + return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom)); +} + +#ifndef QT_NO_DEBUG_STREAM +Q_CORE_EXPORT QDebug operator<<(QDebug, const QMarginsF &); +#endif + +#endif // QT_VERSION < QT_VERSION_CHECK(5, 3, 0) +#endif // QMARGINSF_H diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 4dcc015af..57a350dbd 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -32,6 +32,7 @@ #include #include +#include // Keep synchronize all names with initialization in VTranslateVars class!!!!! //measurements @@ -1719,3 +1720,26 @@ QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath) return QString();// should never reach } + +//--------------------------------------------------------------------------------------------------------------------- +QSharedPointer DefaultPrinter() +{ + QPrinterInfo def = QPrinterInfo::defaultPrinter(); + + //if there is no default printer set the print preview won't show + if(def.isNull() || def.printerName().isEmpty()) + { + if(QPrinterInfo::availablePrinters().isEmpty()) + { + return QSharedPointer(); + } + else + { + def = QPrinterInfo::availablePrinters().first(); + } + } + + QSharedPointer printer = QSharedPointer(new QPrinter(def, QPrinter::ScreenResolution)); + printer->setResolution(static_cast(PrintDPI)); + return printer; +} diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 5bfa30d26..39b9e889a 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -43,6 +43,7 @@ #endif /* Q_CC_MSVC */ class QComboBox; +class QPrinter; #define SceneSize 50000 #define DefPointRadius 1.5//mm @@ -591,4 +592,6 @@ QString StrippedName(const QString &fullFileName); QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath); QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath); +QSharedPointer DefaultPrinter(); + #endif // DEF_H diff --git a/src/libs/vmisc/vmargins.h b/src/libs/vmisc/vmargins.h new file mode 100644 index 000000000..056d4d7ee --- /dev/null +++ b/src/libs/vmisc/vmargins.h @@ -0,0 +1,43 @@ +/************************************************************************ + ** + ** @file vmargins.h + ** @author Roman Telezhynskyi + ** @date 7 11, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 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 VMARGINS_H +#define VMARGINS_H + +#include +#include + +#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) +# include "backport/qmarginsf.h" +#else +# include +#endif + +Q_DECLARE_METATYPE(QMarginsF) + +#endif // VMARGINS_H diff --git a/src/libs/vmisc/vmisc.pri b/src/libs/vmisc/vmisc.pri index 4e51bccae..4b665749d 100644 --- a/src/libs/vmisc/vmisc.pri +++ b/src/libs/vmisc/vmisc.pri @@ -10,7 +10,8 @@ SOURCES += \ $$PWD/vabstractapplication.cpp \ $$PWD/projectversion.cpp \ $$PWD/vcommonsettings.cpp \ - $$PWD/vtapesettings.cpp + $$PWD/vtapesettings.cpp \ + $$PWD/backport/qmarginsf.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -29,4 +30,6 @@ HEADERS += \ $$PWD/vtapesettings.h \ $$PWD/debugbreak.h \ $$PWD/vlockguard.h \ - $$PWD/vsysexits.h + $$PWD/vsysexits.h \ + $$PWD/backport/qmarginsf.h \ + $$PWD/vmargins.h diff --git a/src/libs/vmisc/vmisc.pro b/src/libs/vmisc/vmisc.pro index 5bb3e4bc4..0072a2f51 100644 --- a/src/libs/vmisc/vmisc.pro +++ b/src/libs/vmisc/vmisc.pro @@ -7,7 +7,7 @@ # File with common stuff for whole project include(../../../common.pri) -QT += widgets +QT += widgets printsupport # Name of library TARGET = vmisc diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index a24754305..5be25d3fe 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "../ifc/ifcdef.h" @@ -69,12 +71,16 @@ const QString VSettings::SettingLayoutRotationIncrease = QStringLitera const QString VSettings::SettingLayoutAutoCrop = QStringLiteral("layout/autoCrop"); const QString VSettings::SettingLayoutSaveLength = QStringLiteral("layout/saveLength"); const QString VSettings::SettingLayoutUnitePages = QStringLiteral("layout/unitePages"); +const QString VSettings::SettingFields = QStringLiteral("layout/fields"); +const QString VSettings::SettingIgnoreFields = QStringLiteral("layout/ignoreFields"); //--------------------------------------------------------------------------------------------------------------------- VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application, QObject *parent) :VCommonSettings(format, scope, organization, application, parent) -{} +{ + qRegisterMetaTypeStreamOperators("QMarginsF"); +} //--------------------------------------------------------------------------------------------------------------------- QString VSettings::GetLabelLanguage() const @@ -350,6 +356,49 @@ void VSettings::SetLayoutWidth(qreal value) setValue(SettingLayoutWidth, value); } +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VSettings::GetFields() const +{ + const QMarginsF def = GetDefFields(); + const QVariant val = value(SettingFields, QVariant::fromValue(def)); + if (val.canConvert()) + { + return val.value(); + } + return def; +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VSettings::GetDefFields() +{ + QSharedPointer printer = DefaultPrinter(); + if (printer.isNull()) + { + return QMarginsF(); + } + + qreal left = 0; + qreal top = 0; + qreal right = 0; + qreal bottom = 0; + printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter); + // We can't use Unit::Px because our dpi in most cases is different + QMarginsF def; + def.setLeft(UnitConvertor(left, Unit::Mm, Unit::Px)); + def.setRight(UnitConvertor(right, Unit::Mm, Unit::Px)); + def.setTop(UnitConvertor(top, Unit::Mm, Unit::Px)); + def.setBottom(UnitConvertor(bottom, Unit::Mm, Unit::Px)); + return def; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSettings::SetFields(const QMarginsF &value) +{ + QVariant val = QVariant::fromValue(value); + QString str = val.toString(); + setValue(SettingFields, val); +} + //--------------------------------------------------------------------------------------------------------------------- Cases VSettings::GetLayoutGroup() const { @@ -441,7 +490,13 @@ void VSettings::SetLayoutRotationIncrease(int value) //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetLayoutAutoCrop() const { - return value(SettingLayoutAutoCrop, false).toBool(); + return value(SettingLayoutAutoCrop, GetDefLayoutAutoCrop()).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetDefLayoutAutoCrop() +{ + return false; } //--------------------------------------------------------------------------------------------------------------------- @@ -453,7 +508,13 @@ void VSettings::SetLayoutAutoCrop(bool value) //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetLayoutSaveLength() const { - return value(SettingLayoutSaveLength, false).toBool(); + return value(SettingLayoutSaveLength, GetDefLayoutSaveLength()).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetDefLayoutSaveLength() +{ + return false; } //--------------------------------------------------------------------------------------------------------------------- @@ -465,7 +526,13 @@ void VSettings::SetLayoutSaveLength(bool value) //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetLayoutUnitePages() const { - return value(SettingLayoutUnitePages, false).toBool(); + return value(SettingLayoutUnitePages, GetDefLayoutUnitePages()).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetDefLayoutUnitePages() +{ + return false; } //--------------------------------------------------------------------------------------------------------------------- @@ -474,6 +541,24 @@ void VSettings::SetLayoutUnitePages(bool value) setValue(SettingLayoutUnitePages, value); } +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetIgnoreAllFields() const +{ + return value(SettingIgnoreFields, GetDefIgnoreAllFields()).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetDefIgnoreAllFields() +{ + return false; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSettings::SetIgnoreAllFields(bool value) +{ + setValue(SettingIgnoreFields, value); +} + //--------------------------------------------------------------------------------------------------------------------- QString VSettings::StandardTablesPath() const { diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index 14db58194..176d0df09 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -32,6 +32,8 @@ #include "vcommonsettings.h" #include "../vlayout/vbank.h" +#include "../vmisc/vmargins.h" + class VSettings : public VCommonSettings { Q_OBJECT @@ -83,6 +85,7 @@ public: QString GetUserPassword() const; void SetUserPassword(const QString &value); + // Layout settings qreal GetLayoutPaperHeight() const; void SetLayoutPaperHeight(qreal value); @@ -97,6 +100,10 @@ public: static qreal GetDefLayoutWidth(); void SetLayoutWidth(qreal value); + QMarginsF GetFields() const; + static QMarginsF GetDefFields(); + void SetFields(const QMarginsF &value); + Cases GetLayoutGroup() const; static Cases GetDefLayoutGroup(); void SetLayoutGroup(const Cases &value); @@ -110,14 +117,21 @@ public: void SetLayoutRotationIncrease(int value); bool GetLayoutAutoCrop() const; + static bool GetDefLayoutAutoCrop(); void SetLayoutAutoCrop(bool value); bool GetLayoutSaveLength() const; + static bool GetDefLayoutSaveLength(); void SetLayoutSaveLength(bool value); bool GetLayoutUnitePages() const; + static bool GetDefLayoutUnitePages(); void SetLayoutUnitePages(bool value); + bool GetIgnoreAllFields() const; + static bool GetDefIgnoreAllFields(); + void SetIgnoreAllFields(bool value); + private: Q_DISABLE_COPY(VSettings) static const QString SettingConfigurationLabelLanguage; @@ -148,6 +162,8 @@ private: static const QString SettingLayoutAutoCrop; static const QString SettingLayoutSaveLength; static const QString SettingLayoutUnitePages; + static const QString SettingFields; + static const QString SettingIgnoreFields; }; #endif // VSETTINGS_H From 9327da7a2cb75fabcf37ba5291d64fee18efb1b7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Nov 2015 13:58:45 +0200 Subject: [PATCH 2/5] Calculate correct paper size. Print preview doesn't support non native printers. --HG-- branch : feature --- .../dialogs/dialoglayoutsettings.cpp | 4 +-- src/app/valentina/mainwindowsnogui.cpp | 26 ++++++++++--------- src/app/valentina/mainwindowsnogui.h | 3 ++- src/libs/vlayout/vlayoutgenerator.cpp | 12 ++++----- src/libs/vlayout/vlayoutgenerator.h | 12 ++++----- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index 1e131a91d..f490ff8bc 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -528,8 +528,8 @@ void DialogLayoutSettings::DialogAccepted() SCASSERT(generator != nullptr) generator->SetLayoutWidth(GetLayoutWidth()); generator->SetCaseType(GetGroup()); - generator->SetPaperHeight(qFloor(GetPaperHeight())); - generator->SetPaperWidth(qFloor(GetPaperWidth())); + generator->SetPaperHeight(GetPaperHeight()); + generator->SetPaperWidth(GetPaperWidth()); generator->SetShift(qFloor(GetShift())); generator->SetRotate(GetRotate()); generator->SetRotationIncrease(GetIncrease()); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index e596a6802..7ce56afd8 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -62,7 +62,7 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), doc(nullptr), papers(QList()), shadows(QList()), scenes(QList()), details(QList >()), undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), - isLayoutStale(true), margins(), isTiled(false) + isLayoutStale(true), margins(), paperSize(), isTiled(false) { InitTempLayoutScene(); } @@ -133,6 +133,7 @@ bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator) CreateScenes(); PrepareSceneList(); margins = lGenerator.GetFields(); + paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight()); isLayoutStale = false; break; case LayoutErrors::ProcessStoped: @@ -799,7 +800,7 @@ void MainWindowsNoGUI::PrintPreview() return; } - SetPrinterSettings(printer.data()); + SetPrinterSettings(printer.data(), false); // display print preview dialog QPrintPreviewDialog preview(printer.data()); connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages); @@ -830,7 +831,7 @@ void MainWindowsNoGUI::LayoutPrint() } //--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer) +void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, bool prepareForPrinting) { SCASSERT(printer != nullptr) printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion()); @@ -852,10 +853,8 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer) if (not isTiled && papers.size() > 0) { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(0)); - SCASSERT(paper != nullptr) - printer->setPaperSize ( QSizeF(FromPixel(paper->rect().width(), Unit::Mm), - FromPixel(paper->rect().height(), Unit::Mm)), QPrinter::Millimeter ); + printer->setPaperSize ( QSizeF(FromPixel(paperSize.width(), Unit::Mm), + FromPixel(paperSize.height(), Unit::Mm)), QPrinter::Millimeter ); } { @@ -866,11 +865,14 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer) printer->setPageMargins(left, top, right, bottom, QPrinter::Millimeter); } - #ifdef Q_OS_WIN - printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName()); - #else - printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName() + QLatin1Literal(".pdf")); - #endif + if (prepareForPrinting) + { + #ifdef Q_OS_WIN + printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName()); + #else + printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName() + QLatin1Literal(".pdf")); + #endif + } printer->setDocName(FileName()); IsLayoutGrayscale() ? printer->setColorMode(QPrinter::GrayScale) : printer->setColorMode(QPrinter::Color); diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 549b70f20..757e547d4 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -88,6 +88,7 @@ protected: bool isLayoutStale; QMarginsF margins; + QSizeF paperSize; void PrepareDetailsForLayout(const QHash *details); void ExportLayout(const DialogSaveLayout &dialog); @@ -120,7 +121,7 @@ private: void PrintPreview(); void LayoutPrint(); - void SetPrinterSettings(QPrinter *printer); + void SetPrinterSettings(QPrinter *printer, bool prepareForPrinting = true); bool IsLayoutGrayscale() const; bool isPagesUniform() const; diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 5bb039bde..9df5dd755 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -192,13 +192,13 @@ void VLayoutGenerator::Abort() //--------------------------------------------------------------------------------------------------------------------- int VLayoutGenerator::PageHeight() const { - return paperHeight - static_cast(margins.top() + margins.bottom()); + return static_cast(paperHeight - (margins.top() + margins.bottom())); } //--------------------------------------------------------------------------------------------------------------------- int VLayoutGenerator::PageWidth() const { - return paperWidth - static_cast(margins.left() + margins.right()); + return static_cast(paperWidth - (margins.left() + margins.right())); } //--------------------------------------------------------------------------------------------------------------------- @@ -268,13 +268,13 @@ void VLayoutGenerator::SetRotate(bool value) } //--------------------------------------------------------------------------------------------------------------------- -int VLayoutGenerator::GetPaperWidth() const +qreal VLayoutGenerator::GetPaperWidth() const { return paperWidth; } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::SetPaperWidth(int value) +void VLayoutGenerator::SetPaperWidth(qreal value) { paperWidth = value; } @@ -304,13 +304,13 @@ void VLayoutGenerator::SetShift(quint32 shift) } //--------------------------------------------------------------------------------------------------------------------- -int VLayoutGenerator::GetPaperHeight() const +qreal VLayoutGenerator::GetPaperHeight() const { return paperHeight; } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::SetPaperHeight(int value) +void VLayoutGenerator::SetPaperHeight(qreal value) { paperHeight = value; } diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 429e017e8..2f57538ea 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -53,11 +53,11 @@ public: void SetCaseType(Cases caseType); int DetailsCount(); - int GetPaperHeight() const; - void SetPaperHeight(int value); + qreal GetPaperHeight() const; + void SetPaperHeight(qreal value); - int GetPaperWidth() const; - void SetPaperWidth(int value); + qreal GetPaperWidth() const; + void SetPaperWidth(qreal value); QMarginsF GetFields() const; void SetFields(const QMarginsF &value); @@ -100,8 +100,8 @@ private: Q_DISABLE_COPY(VLayoutGenerator) QVector papers; VBank *bank; - int paperHeight; - int paperWidth; + qreal paperHeight; + qreal paperWidth; QMarginsF margins; volatile bool stopGeneration; LayoutErrors state; From e7e177898c55769d5d9a7c5c3a52198f8b3ab3da Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Nov 2015 14:29:37 +0200 Subject: [PATCH 3/5] Each time when set paper size first try to find predefined template size. This will help user undertand what paper size is setted now. --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 54 ++++++++++++++++++++++++-- src/app/valentina/mainwindowsnogui.h | 2 + 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 7ce56afd8..d1b71bf81 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -853,8 +852,16 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, bool prepareForPrin if (not isTiled && papers.size() > 0) { - printer->setPaperSize ( QSizeF(FromPixel(paperSize.width(), Unit::Mm), - FromPixel(paperSize.height(), Unit::Mm)), QPrinter::Millimeter ); + const QSizeF size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), FromPixel(paperSize.height(), Unit::Mm)); + const QPrinter::PageSize pSZ = FindTemplate(size); + if (pSZ == QPrinter::Custom) + { + printer->setPaperSize (size, QPrinter::Millimeter ); + } + else + { + printer->setPaperSize (pSZ); + } } { @@ -894,6 +901,47 @@ bool MainWindowsNoGUI::IsLayoutGrayscale() const return true; } +//--------------------------------------------------------------------------------------------------------------------- +QPrinter::PaperSize MainWindowsNoGUI::FindTemplate(const QSizeF &size) const +{ + if (size == QSizeF(841, 1189)) + { + return QPrinter::A0; + } + + if (size == QSizeF(594, 841)) + { + return QPrinter::A1; + } + + if (size == QSizeF(420, 594)) + { + return QPrinter::A2; + } + + if (size == QSizeF(297, 420)) + { + return QPrinter::A3; + } + + if (size == QSizeF(210, 297)) + { + return QPrinter::A4; + } + + if (size == QSizeF(215.9, 355.6)) + { + return QPrinter::Legal; + } + + if (size == QSizeF(215.9, 279.4)) + { + return QPrinter::Letter; + } + + return QPrinter::Custom; +} + //--------------------------------------------------------------------------------------------------------------------- bool MainWindowsNoGUI::isPagesUniform() const { diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 757e547d4..63ab1e799 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -30,6 +30,7 @@ #define MAINWINDOWSNOGUI_H #include +#include #include "../vpatterndb/vdetail.h" #include "../vlayout/vlayoutdetail.h" @@ -123,6 +124,7 @@ private: void SetPrinterSettings(QPrinter *printer, bool prepareForPrinting = true); bool IsLayoutGrayscale() const; + QPrinter::PaperSize FindTemplate(const QSizeF &size) const; bool isPagesUniform() const; QString FileName() const; From 01a23b5e0819ae39a1892bd5ff58aa1ecf04a7ba Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Nov 2015 17:23:15 +0200 Subject: [PATCH 4/5] Keep order of options. --HG-- branch : feature --- src/app/valentina/core/vcmdexport.cpp | 174 +++++++++++++------------- src/app/valentina/core/vcmdexport.h | 6 +- 2 files changed, 88 insertions(+), 92 deletions(-) diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index 6e7baed7b..9631fc1c5 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -66,17 +66,19 @@ const static auto SINGLE_OPTION_GRADATIONHEIGHT = QStringLiteral("e"); #define translate(context, source) QCoreApplication::translate((context), (source)) //--------------------------------------------------------------------------------------------------------------------- -VCommandLine::VCommandLine() : parser(), optionsUsed(InitOptionsUsed()), isGuiEnabled(false) +VCommandLine::VCommandLine() : parser(), optionsUsed(), optionsIndex(), isGuiEnabled(false) { parser.setApplicationDescription(translate("VCommandLine", "Pattern making program.")); parser.addHelpOption(); parser.addVersionOption(); parser.addPositionalArgument("filename", translate("VCommandLine", "Pattern file.")); - QMap::const_iterator i = optionsUsed.constBegin(); + InitOptions(optionsUsed, optionsIndex); + + VCommandLineOptions::const_iterator i = optionsUsed.constBegin(); while (i != optionsUsed.constEnd()) { - parser.addOption(*i.value()); + parser.addOption(*((*i))); ++i; } } @@ -94,45 +96,44 @@ qreal VCommandLine::Pg2Px(const QString& src, const DialogLayoutSettings& conver } //--------------------------------------------------------------------------------------------------------------------- -QMap VCommandLine::InitOptionsUsed() +void VCommandLine::InitOptions(VCommandLineOptions &options, QMap &optionsIndex) { - QMap options; - + int index = 0; //keep in mind order here - that is how user will see it, so group-up for usability //================================================================================================================= - options.insert(LONG_OPTION_BASENAME, - new QCommandLineOption(QStringList() << SINGLE_OPTION_BASENAME << LONG_OPTION_BASENAME, + optionsIndex.insert(LONG_OPTION_BASENAME, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_BASENAME << LONG_OPTION_BASENAME, translate("VCommandLine", "The base filename of exported layout files. Use " "it to enable console export mode."), translate("VCommandLine", "The base filename of layout files"))); - options.insert(LONG_OPTION_DESTINATION, - new QCommandLineOption(QStringList() << SINGLE_OPTION_DESTINATION << LONG_OPTION_DESTINATION, + optionsIndex.insert(LONG_OPTION_DESTINATION, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_DESTINATION << LONG_OPTION_DESTINATION, translate("VCommandLine", "The path to output destination folder."), translate("VCommandLine", "The destination folder"))); - options.insert(LONG_OPTION_MEASUREFILE, - new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE, + optionsIndex.insert(LONG_OPTION_MEASUREFILE, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE, translate("VCommandLine", "Path to custom measure file (export mode)."), translate("VCommandLine", "The measure file"))); - options.insert(LONG_OPTION_EXP2FORMAT, - new QCommandLineOption(QStringList() << SINGLE_OPTION_EXP2FORMAT << LONG_OPTION_EXP2FORMAT, + optionsIndex.insert(LONG_OPTION_EXP2FORMAT, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_EXP2FORMAT << LONG_OPTION_EXP2FORMAT, translate("VCommandLine", "Number corresponding to output format (default = " "0, export mode): ") + DialogSaveLayout::MakeHelpFormatList(), translate("VCommandLine", "Format number"), "0")); - options.insert(LONG_OPTION_GRADATIONSIZE, - new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE, + optionsIndex.insert(LONG_OPTION_GRADATIONSIZE, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE, translate("VCommandLine", "Set size value a pattern file, that was opened " "with standard measurements (export mode). Valid " "values: %1cm.") .arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")), translate("VCommandLine", "The size value"))); - options.insert(LONG_OPTION_GRADATIONHEIGHT, - new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONHEIGHT << LONG_OPTION_GRADATIONHEIGHT, + optionsIndex.insert(LONG_OPTION_GRADATIONHEIGHT, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONHEIGHT << LONG_OPTION_GRADATIONHEIGHT, translate("VCommandLine", "Set height value a pattern file, that was opened " "with standard measurements (export mode). Valid " "values: %1cm.") @@ -140,91 +141,86 @@ QMap VCommandLine::InitOptionsUsed() translate("VCommandLine", "The height value"))); //================================================================================================================= - - options.insert(LONG_OPTION_PAGETEMPLATE, - new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE, + optionsIndex.insert(LONG_OPTION_PAGETEMPLATE, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE, translate("VCommandLine", "Number corresponding to page template (default = " "0, export mode): ") + DialogLayoutSettings::MakeHelpTemplateList(), translate("VCommandLine", "Template number"), "0")); - - options.insert(LONG_OPTION_PAGEW, - new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW, + optionsIndex.insert(LONG_OPTION_PAGEW, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW, translate("VCommandLine", "Page width in current units like 12.0 (cannot be " "used with \"%1\", export mode).") .arg(LONG_OPTION_PAGETEMPLATE), translate("VCommandLine", "The page width"))); - options.insert(LONG_OPTION_PAGEH, - new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH, + optionsIndex.insert(LONG_OPTION_PAGEH, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH, translate("VCommandLine", "Page height in current units like 12.0 (cannot " "be used with \"%1\", export mode).") .arg(LONG_OPTION_PAGETEMPLATE), ("The page height"))); - options.insert(LONG_OPTION_PAGEUNITS, - new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS, + optionsIndex.insert(LONG_OPTION_PAGEUNITS, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS, translate("VCommandLine", "Page height/width measure units (cannot be used " "with \"%1\", export mode): ") .arg(LONG_OPTION_PAGETEMPLATE) + VDomDocument::UnitsHelpString(), translate("VCommandLine", "The measure unit"))); //================================================================================================================= - - options.insert(LONG_OPTION_ROTATE, - new QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE, + optionsIndex.insert(LONG_OPTION_ROTATE, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE, translate("VCommandLine", "Rotation in degrees (one of predefined). Default " "(or 0) is no-rotate (export mode)."), translate("VCommandLine", "Angle"))); - options.insert(LONG_OPTION_CROP, - new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP, + optionsIndex.insert(LONG_OPTION_CROP, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP, translate("VCommandLine", "Auto crop unused length (export mode)."))); - options.insert(LONG_OPTION_UNITE, - new QCommandLineOption(QStringList() << SINGLE_OPTION_UNITE << LONG_OPTION_UNITE, + optionsIndex.insert(LONG_OPTION_UNITE, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_UNITE << LONG_OPTION_UNITE, translate("VCommandLine", "Unite pages if possible (export mode)."))); //================================================================================================================= - - options.insert(LONG_OPTION_SAVELENGTH, - new QCommandLineOption(QStringList() << SINGLE_OPTION_SAVELENGTH << LONG_OPTION_SAVELENGTH, + optionsIndex.insert(LONG_OPTION_SAVELENGTH, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SAVELENGTH << LONG_OPTION_SAVELENGTH, translate("VCommandLine", "Save length of the sheet if set. (export mode)."))); - options.insert(LONG_OPTION_SHIFTUNITS, - new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTUNITS << LONG_OPTION_SHIFTUNITS, + optionsIndex.insert(LONG_OPTION_SHIFTUNITS, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTUNITS << LONG_OPTION_SHIFTUNITS, translate("VCommandLine", "Layout units (as paper's one except px, export mode)."), translate("VCommandLine", "The unit"))); - options.insert(LONG_OPTION_SHIFTLENGTH, - new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTLENGTH << LONG_OPTION_SHIFTLENGTH, + optionsIndex.insert(LONG_OPTION_SHIFTLENGTH, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTLENGTH << LONG_OPTION_SHIFTLENGTH, translate("VCommandLine", "Shift layout length measured in layout units " "(export mode)."), translate("VCommandLine", "Shift length"))); - options.insert(LONG_OPTION_GAPWIDTH, - new QCommandLineOption(QStringList() << SINGLE_OPTION_GAPWIDTH << LONG_OPTION_GAPWIDTH, + optionsIndex.insert(LONG_OPTION_GAPWIDTH, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GAPWIDTH << LONG_OPTION_GAPWIDTH, translate("VCommandLine", "Gap width x2, measured in layout units. (export mode)."), translate("VCommandLine", "The gap width"))); - options.insert(LONG_OPTION_GROUPPING, - new QCommandLineOption(QStringList() << SINGLE_OPTION_GROUPPING << LONG_OPTION_GROUPPING, + optionsIndex.insert(LONG_OPTION_GROUPPING, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GROUPPING << LONG_OPTION_GROUPPING, translate("VCommandLine", "Sets layout groupping (export mode): ") + DialogLayoutSettings::MakeGroupsHelp(), translate("VCommandLine", "Grouping type"), "2")); - options.insert(LONG_OPTION_TEST, - new QCommandLineOption(QStringList() << SINGLE_OPTION_TEST << LONG_OPTION_TEST, + optionsIndex.insert(LONG_OPTION_TEST, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_TEST << LONG_OPTION_TEST, translate("VCommandLine", "Run the program in a test mode. The program this " "mode load a single pattern file and silently " "quit without showing the main window. The key " "have priority before key '%1'.") .arg(LONG_OPTION_BASENAME))); - return options; } //------------------------------------------------------------------------------------------------------ @@ -237,11 +233,11 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const { //just anonymous namespace ...don' like to have a,b,c,d everywhere defined - bool x = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE)); + bool x = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE))); - bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEH)); - bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEW)); - bool c = parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEUNITS)); + bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH))); + bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEW))); + bool c = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS))); if ((a || b || c) && x) { @@ -260,8 +256,8 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const { //just anonymous namespace ...don' like to have a,b,c,d everywhere defined - bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)); - bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS)); + bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH))); + bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS))); if ((a || b) && !(a && b)) { @@ -272,8 +268,8 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const { //just anonymous namespace ...don' like to have a,b,c,d everywhere defined - bool a = parser.isSet(*optionsUsed.value(LONG_OPTION_GAPWIDTH)); - bool b = parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS)); + bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))); + bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS))); if ((a || b) && !(a && b)) { @@ -302,46 +298,44 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const const_cast(this)->parser.showHelp(V_EX_USAGE); } - if (parser.isSet(*optionsUsed.value(LONG_OPTION_PAGEH))) //at this point we already sure 3 are set or none - { + if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH)))) + { //at this point we already sure 3 are set or none - if (!diag.SelectPaperUnit(parser.value(*optionsUsed.value(LONG_OPTION_PAGEUNITS)))) + if (!diag.SelectPaperUnit(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS))))) { qCritical() << translate("VCommandLine", "Unsupported paper units.") << "\n"; const_cast(this)->parser.showHelp(V_EX_USAGE); } - diag.SetPaperHeight (Pg2Px(parser.value(*optionsUsed.value(LONG_OPTION_PAGEH)), diag)); - diag.SetPaperWidth (Pg2Px(parser.value(*optionsUsed.value(LONG_OPTION_PAGEW)), diag)); + diag.SetPaperHeight (Pg2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH))), diag)); + diag.SetPaperWidth (Pg2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEW))), diag)); } - if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTUNITS))) + if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)))) { - if (!diag.SelectLayoutUnit(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTUNITS)))) + if (!diag.SelectLayoutUnit(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS))))) { qCritical() << translate("VCommandLine", "Unsupported layout units.") << "\n"; const_cast(this)->parser.showHelp(V_EX_USAGE); } } - if (parser.isSet(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH))) + if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH)))) { - diag.SetShift(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_SHIFTLENGTH)), diag)); + diag.SetShift(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH))), diag)); } - if (parser.isSet(*optionsUsed.value(LONG_OPTION_GAPWIDTH))) + if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH)))) { - diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(LONG_OPTION_GAPWIDTH)), diag)); + diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))), diag)); } - diag.SetAutoCrop(parser.isSet(*optionsUsed.value(LONG_OPTION_CROP))); - diag.SetUnitePages(parser.isSet(*optionsUsed.value(LONG_OPTION_UNITE))); - diag.SetSaveLength(parser.isSet(*optionsUsed.value(LONG_OPTION_SAVELENGTH))); + diag.SetAutoCrop(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CROP)))); + diag.SetUnitePages(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_UNITE)))); + diag.SetSaveLength(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SAVELENGTH)))); diag.SetGroup(OptGroup()); - - diag.DialogAccepted(); // filling VLayoutGenerator return res; @@ -378,7 +372,7 @@ void VCommandLine::Reset() //--------------------------------------------------------------------------------------------------------------------- bool VCommandLine::IsTestModeEnabled() const { - const bool r = parser.isSet(*optionsUsed.value(LONG_OPTION_TEST)); + const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TEST))); if (r && parser.positionalArguments().size() != 1) { qCritical() << translate("VCommandLine", "Test option can be used with single input file only.") << "/n"; @@ -390,7 +384,7 @@ bool VCommandLine::IsTestModeEnabled() const //------------------------------------------------------------------------------------------------------ bool VCommandLine::IsExportEnabled() const { - const bool r = parser.isSet(*optionsUsed.value(LONG_OPTION_BASENAME)); + const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BASENAME))); if (r && parser.positionalArguments().size() != 1) { qCritical() << translate("VCommandLine", "Export options can be used with single input file only.") << "/n"; @@ -403,9 +397,9 @@ bool VCommandLine::IsExportEnabled() const DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const { int ppsize = 0; - if (parser.isSet(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE))) + if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE)))) { - ppsize = parser.value(*optionsUsed.value(LONG_OPTION_PAGETEMPLATE)).toInt(); + ppsize = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE))).toInt(); } return static_cast(ppsize); } @@ -414,9 +408,9 @@ DialogLayoutSettings::PaperSizeTemplate VCommandLine::OptPaperSize() const int VCommandLine::OptRotation() const { int rotate = 0; - if (parser.isSet(*optionsUsed.value(LONG_OPTION_ROTATE))) + if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_ROTATE)))) { - rotate = parser.value(*optionsUsed.value(LONG_OPTION_ROTATE)).toInt(); + rotate = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_ROTATE))).toInt(); } return rotate; @@ -425,7 +419,7 @@ int VCommandLine::OptRotation() const //------------------------------------------------------------------------------------------------------ Cases VCommandLine::OptGroup() const { - int r = parser.value(*optionsUsed.value(LONG_OPTION_GROUPPING)).toInt(); + int r = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GROUPPING))).toInt(); if ( r < 0 || r >= static_cast(Cases::UnknownCase)) { r = 0; @@ -437,11 +431,11 @@ Cases VCommandLine::OptGroup() const QString VCommandLine::OptMeasurePath() const { QString measure; - if (parser.isSet(*optionsUsed.value(LONG_OPTION_MEASUREFILE)) + if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_MEASUREFILE))) && IsExportEnabled() //todo: don't want yet to allow user set measure file for general loading, because need to fix multiply opened windows as well ) { - measure = parser.value(*optionsUsed.value(LONG_OPTION_MEASUREFILE)); + measure = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_MEASUREFILE))); } return measure; @@ -453,7 +447,7 @@ QString VCommandLine::OptBaseName() const QString path; if (IsExportEnabled()) { - path = parser.value(*optionsUsed.value(LONG_OPTION_BASENAME)); + path = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BASENAME))); } return path; @@ -465,7 +459,7 @@ QString VCommandLine::OptDestinationPath() const QString path; if (IsExportEnabled()) { - path = parser.value(*optionsUsed.value(LONG_OPTION_DESTINATION)); + path = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_DESTINATION))); } return path; @@ -475,9 +469,9 @@ QString VCommandLine::OptDestinationPath() const int VCommandLine::OptExportType() const { int r = 0; - if (parser.isSet(*optionsUsed.value(LONG_OPTION_EXP2FORMAT))) + if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXP2FORMAT)))) { - r = parser.value(*optionsUsed.value(LONG_OPTION_EXP2FORMAT)).toInt(); + r = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXP2FORMAT))).toInt(); } return r; } @@ -497,19 +491,19 @@ bool VCommandLine::IsGuiEnabled() const //--------------------------------------------------------------------------------------------------------------------- bool VCommandLine::IsSetGradationSize() const { - return parser.isSet(*optionsUsed.value(LONG_OPTION_GRADATIONSIZE)); + return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONSIZE))); } //--------------------------------------------------------------------------------------------------------------------- bool VCommandLine::IsSetGradationHeight() const { - return parser.isSet(*optionsUsed.value(LONG_OPTION_GRADATIONHEIGHT)); + return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONHEIGHT))); } //--------------------------------------------------------------------------------------------------------------------- QString VCommandLine::OptGradationSize() const { - const QString size = parser.value(*optionsUsed.value(LONG_OPTION_GRADATIONSIZE)); + const QString size = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONSIZE))); if (VMeasurement::IsGradationSizeValid(size)) { return size; @@ -524,7 +518,7 @@ QString VCommandLine::OptGradationSize() const //--------------------------------------------------------------------------------------------------------------------- QString VCommandLine::OptGradationHeight() const { - const QString height = parser.value(*optionsUsed.value(LONG_OPTION_GRADATIONHEIGHT)); + const QString height = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONHEIGHT))); if (VMeasurement::IsGradationHeightValid(height)) { return height; diff --git a/src/app/valentina/core/vcmdexport.h b/src/app/valentina/core/vcmdexport.h index fe2cd8863..78a4b0620 100644 --- a/src/app/valentina/core/vcmdexport.h +++ b/src/app/valentina/core/vcmdexport.h @@ -17,6 +17,7 @@ class VCommandLine; typedef std::shared_ptr VCommandLinePtr; +typedef QList VCommandLineOptions; //@brief: class used to install export command line options and parse their values //QCommandLineParser* object must exists until this object alive @@ -81,14 +82,15 @@ private: Q_DISABLE_COPY(VCommandLine) static VCommandLinePtr instance; QCommandLineParser parser; - QMap optionsUsed; + VCommandLineOptions optionsUsed; + QMap optionsIndex; bool isGuiEnabled; friend class VApplication; static qreal Lo2Px(const QString& src, const DialogLayoutSettings& converter); static qreal Pg2Px(const QString& src, const DialogLayoutSettings& converter); - static QMap InitOptionsUsed(); + static void InitOptions(VCommandLineOptions &options, QMap &optionsIndex); }; #endif // VCMDEXPORT_H From 39f7994f1bc1761856e5067c0820ee094cc9c7a9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Nov 2015 17:52:38 +0200 Subject: [PATCH 5/5] Command line options for dealing with margins. --HG-- branch : feature --- src/app/valentina/core/vcmdexport.cpp | 142 ++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index 9631fc1c5..f1b5ac38a 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -63,6 +63,21 @@ const static auto SINGLE_OPTION_GRADATIONSIZE = QStringLiteral("x"); const static auto LONG_OPTION_GRADATIONHEIGHT = QStringLiteral("gheight"); const static auto SINGLE_OPTION_GRADATIONHEIGHT = QStringLiteral("e"); +const static auto LONG_OPTION_IGNORE_MARGINS = QStringLiteral("ignoremargins"); +const static auto SINGLE_OPTION_IGNORE_MARGINS = QStringLiteral("i"); + +const static auto LONG_OPTION_LEFT_MARGIN = QStringLiteral("lmargin"); +const static auto SINGLE_OPTION_LEFT_MARGIN = QStringLiteral("L"); + +const static auto LONG_OPTION_RIGHT_MARGIN = QStringLiteral("rmargin"); +const static auto SINGLE_OPTION_RIGHT_MARGIN = QStringLiteral("R"); + +const static auto LONG_OPTION_TOP_MARGIN = QStringLiteral("tmargin"); +const static auto SINGLE_OPTION_TOP_MARGIN = QStringLiteral("T"); + +const static auto LONG_OPTION_BOTTOM_MARGIN = QStringLiteral("bmargin"); +const static auto SINGLE_OPTION_BOTTOM_MARGIN = QStringLiteral("B"); + #define translate(context, source) QCoreApplication::translate((context), (source)) //--------------------------------------------------------------------------------------------------------------------- @@ -169,6 +184,43 @@ void VCommandLine::InitOptions(VCommandLineOptions &options, QMap .arg(LONG_OPTION_PAGETEMPLATE) + VDomDocument::UnitsHelpString(), translate("VCommandLine", "The measure unit"))); + optionsIndex.insert(LONG_OPTION_IGNORE_MARGINS, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_IGNORE_MARGINS << LONG_OPTION_IGNORE_MARGINS, + translate("VCommandLine", + "Ignore margins printing (export mode). Set all margins to 0."))); + + optionsIndex.insert(LONG_OPTION_LEFT_MARGIN, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_LEFT_MARGIN << LONG_OPTION_LEFT_MARGIN, + translate("VCommandLine", + "Page left margin in current units like 3.0 (export mode). If " + "not set will be used value from default printer. Or 0 if none " + "printers was found."), + ("The left margin"))); + + optionsIndex.insert(LONG_OPTION_RIGHT_MARGIN, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_RIGHT_MARGIN << LONG_OPTION_RIGHT_MARGIN, + translate("VCommandLine", + "Page right margin in current units like 3.0 (export mode). If " + "not set will be used value from default printer. Or 0 if none " + "printers was found."), + ("The right margin"))); + + optionsIndex.insert(LONG_OPTION_TOP_MARGIN, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_TOP_MARGIN << LONG_OPTION_TOP_MARGIN, + translate("VCommandLine", + "Page top margin in current units like 3.0 (export mode). If " + "not set will be used value from default printer. Or 0 if none " + "printers was found."), + ("The top margin"))); + + optionsIndex.insert(LONG_OPTION_BOTTOM_MARGIN, index++); + options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_BOTTOM_MARGIN << LONG_OPTION_BOTTOM_MARGIN, + translate("VCommandLine", + "Page bottom margin in current units like 3.0 (export mode). If " + "not set will be used value from default printer. Or 0 if none " + "printers was found."), + ("The bottom margin"))); + //================================================================================================================= optionsIndex.insert(LONG_OPTION_ROTATE, index++); options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE, @@ -278,6 +330,54 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const } } + { + //just anonymous namespace ...don' like to have a,b,c,d everywhere defined + bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_LEFT_MARGIN))); + bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS))); + + if ((a || b) && !(a && b)) + { + qCritical() << translate("VCommandLine", "Left margin must be used together with page units.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + } + + { + //just anonymous namespace ...don' like to have a,b,c,d everywhere defined + bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_RIGHT_MARGIN))); + bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS))); + + if ((a || b) && !(a && b)) + { + qCritical() << translate("VCommandLine", "Right margin must be used together with page units.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + } + + { + //just anonymous namespace ...don' like to have a,b,c,d everywhere defined + bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TOP_MARGIN))); + bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS))); + + if ((a || b) && !(a && b)) + { + qCritical() << translate("VCommandLine", "Top margin must be used together with page units.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + } + + { + //just anonymous namespace ...don' like to have a,b,c,d everywhere defined + bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BOTTOM_MARGIN))); + bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS))); + + if ((a || b) && !(a && b)) + { + qCritical() << translate("VCommandLine", "Bottom margin must be used together with page units.") << "\n"; + const_cast(this)->parser.showHelp(V_EX_USAGE); + } + } + int rotateDegree = OptRotation(); diag.SetRotate(rotateDegree != 0 ); @@ -336,6 +436,48 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const diag.SetSaveLength(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SAVELENGTH)))); diag.SetGroup(OptGroup()); + if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_IGNORE_MARGINS)))) + { + diag.SetIgnoreAllFields(true); + } + else + { + QMarginsF margins = diag.GetFields(); + + { + const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_LEFT_MARGIN)); + if (parser.isSet(*option)) + { + margins.setLeft(Pg2Px(parser.value(*option), diag)); + } + } + + { + const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_RIGHT_MARGIN)); + if (parser.isSet(*option)) + { + margins.setRight(Pg2Px(parser.value(*option), diag)); + } + } + + { + const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_TOP_MARGIN)); + if (parser.isSet(*option)) + { + margins.setTop(Pg2Px(parser.value(*option), diag)); + } + } + + { + const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_BOTTOM_MARGIN)); + if (parser.isSet(*option)) + { + margins.setBottom(Pg2Px(parser.value(*option), diag)); + } + } + diag.SetFields(margins); + } + diag.DialogAccepted(); // filling VLayoutGenerator return res;