From 4411cccd9c86efdabb6cffa15642d83601de2d27 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Nov 2015 13:33:36 +0200 Subject: [PATCH] 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