From 723d68b2456ba8239f8f9c9ac27c9a028a119b72 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 30 Sep 2016 19:33:10 +0300 Subject: [PATCH] Resolved issue #570. Error: Tiled PDF : field values not taken into account if one of them is smaller than 0,3. --HG-- branch : develop --- .../dialogs/dialoglayoutsettings.cpp | 140 ++++++++++++++---- .../valentina/dialogs/dialoglayoutsettings.h | 4 + .../valentina/dialogs/dialoglayoutsettings.ui | 10 +- src/app/valentina/mainwindowsnogui.cpp | 7 +- src/app/valentina/mainwindowsnogui.h | 1 + src/libs/vlayout/vlayoutgenerator.cpp | 17 ++- src/libs/vlayout/vlayoutgenerator.h | 6 +- src/libs/vmisc/vsettings.cpp | 31 +--- src/libs/vmisc/vsettings.h | 4 +- 9 files changed, 149 insertions(+), 71 deletions(-) diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index fdd8d5e9d..1637a3ce9 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -572,44 +572,58 @@ void DialogLayoutSettings::DialogAccepted() if (IsIgnoreAllFields()) { - generator->SetFields(QMarginsF()); + generator->SetPrinterFields(false, 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()) + QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText()); + if (printer.isNull()) { - 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) + generator->SetPrinterFields(true, GetFields()); + } + else + { + const QMarginsF minFields = RoundMargins(GetMinPrinterFields()); + const QMarginsF fields = RoundMargins(GetFields()); + if (fields.left() < minFields.left() || fields.right() < minFields.right() || + fields.top() < minFields.top() || fields.bottom() < minFields.bottom()) { - if (fields.left() < minFields.left()) + 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) { - ui->doubleSpinBoxLeftField->setValue(UnitConvertor(minFields.left(), Unit::Px, LayoutUnit())); - } + const QMarginsF defFields = RoundMargins(GetDefPrinterFields()); + if (fields.left() < defFields.left()) + { + ui->doubleSpinBoxLeftField->setValue(UnitConvertor(defFields.left(), Unit::Px, LayoutUnit())); + } - if (fields.right() < minFields.right()) - { - ui->doubleSpinBoxRightField->setValue(UnitConvertor(minFields.right(), Unit::Px, LayoutUnit())); - } + if (fields.right() < defFields.right()) + { + ui->doubleSpinBoxRightField->setValue(UnitConvertor(defFields.right(), Unit::Px, LayoutUnit())); + } - if (fields.top() < minFields.top()) - { - ui->doubleSpinBoxTopField->setValue(UnitConvertor(minFields.top(), Unit::Px, LayoutUnit())); - } + if (fields.top() < defFields.top()) + { + ui->doubleSpinBoxTopField->setValue(UnitConvertor(defFields.top(), Unit::Px, LayoutUnit())); + } - if (fields.bottom() < minFields.bottom()) + if (fields.bottom() < defFields.bottom()) + { + ui->doubleSpinBoxBottomField->setValue(UnitConvertor(defFields.bottom(), Unit::Px, + LayoutUnit())); + } + + generator->SetPrinterFields(true, GetFields()); + } + else { - ui->doubleSpinBoxBottomField->setValue(UnitConvertor(minFields.bottom(), Unit::Px, LayoutUnit())); + generator->SetPrinterFields(false, GetFields()); } } } - - generator->SetFields(GetFields()); } //don't want to break visual settings when cmd used @@ -637,7 +651,7 @@ void DialogLayoutSettings::RestoreDefaults() SetGroup(VSettings::GetDefLayoutGroup()); SetRotate(VSettings::GetDefLayoutRotate()); SetIncrease(VSettings::GetDefLayoutRotationIncrease()); - SetFields(VSettings::GetDefFields()); + SetFields(GetDefPrinterFields()); SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields()); SetMultiplier(VSettings::GetDefMultiplier()); @@ -651,7 +665,11 @@ void DialogLayoutSettings::PrinterMargins() QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText()); if (not printer.isNull()) { - SetFields(VSettings::GetPrinterFields(QSharedPointer(new QPrinter(printer)))); + SetFields(GetPrinterFields(QSharedPointer(new QPrinter(printer)))); + } + else + { + SetFields(QMarginsF()); } } @@ -940,6 +958,50 @@ QMarginsF DialogLayoutSettings::RoundMargins(const QMarginsF &margins) const return newMargins; } +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF DialogLayoutSettings::GetMinPrinterFields() const +{ + QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText()); + if (not printer.isNull()) + { + QSharedPointer pr = QSharedPointer(new QPrinter(printer)); +#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) + QPageLayout layout = pr->pageLayout(); + layout.setUnits(QPageLayout::Millimeter); + const QMarginsF minMargins = layout.minimumMargins(); + + QMarginsF min; + min.setLeft(UnitConvertor(minMargins.left(), Unit::Mm, Unit::Px)); + min.setRight(UnitConvertor(minMargins.right(), Unit::Mm, Unit::Px)); + min.setTop(UnitConvertor(minMargins.top(), Unit::Mm, Unit::Px)); + min.setBottom(UnitConvertor(minMargins.bottom(), Unit::Mm, Unit::Px)); + return min; +#else + pr->setFullPage(false); + pr->setPageMargins(0, 0, 0, 0, QPrinter::Millimeter); + return GetPrinterFields(QSharedPointer(new QPrinter(printer))); +#endif //QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) + } + else + { + return QMarginsF(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF DialogLayoutSettings::GetDefPrinterFields() const +{ + QPrinterInfo printer = QPrinterInfo::printerInfo(ui->comboBoxPrinter->currentText()); + if (not printer.isNull()) + { + return GetPrinterFields(QSharedPointer(new QPrinter(printer))); + } + else + { + return QMarginsF(); + } +} + //--------------------------------------------------------------------------------------------------------------------- Unit DialogLayoutSettings::PaperUnit() const { @@ -1043,7 +1105,7 @@ void DialogLayoutSettings::ReadSettings() SetAutoCrop(settings->GetLayoutAutoCrop()); SetSaveLength(settings->GetLayoutSaveLength()); SetUnitePages(settings->GetLayoutUnitePages()); - SetFields(settings->GetFields()); + SetFields(settings->GetFields(GetDefPrinterFields())); SetIgnoreAllFields(settings->GetIgnoreAllFields()); SetStripOptimization(settings->GetStripOptimization()); SetMultiplier(settings->GetMultiplier()); @@ -1096,3 +1158,25 @@ void DialogLayoutSettings::SetAdditionalOptions(bool value) SetUnitePages(value); SetStripOptimization(value); } + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF DialogLayoutSettings::GetPrinterFields(const QSharedPointer &printer) +{ + 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; +} diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.h b/src/app/valentina/dialogs/dialoglayoutsettings.h index 982b0608f..69f26e2a8 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.h +++ b/src/app/valentina/dialogs/dialoglayoutsettings.h @@ -159,6 +159,8 @@ private: QSizeF TemplateSize(const PaperSizeTemplate &tmpl) const; QSizeF RoundTemplateSize(qreal width, qreal height) const; QMarginsF RoundMargins(const QMarginsF &margins) const; + QMarginsF GetMinPrinterFields() const; + QMarginsF GetDefPrinterFields() const; Unit PaperUnit() const; Unit LayoutUnit() const; @@ -174,6 +176,8 @@ private: void SheetSize(const QSizeF &size); void SetAdditionalOptions(bool value); + + static QMarginsF GetPrinterFields(const QSharedPointer &printer); }; #endif // DIALOGLAYOUTSETTINGS_H diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.ui b/src/app/valentina/dialogs/dialoglayoutsettings.ui index 1cbf210e8..256cc8332 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.ui +++ b/src/app/valentina/dialogs/dialoglayoutsettings.ui @@ -205,6 +205,12 @@ + + + 0 + 0 + + Printer: @@ -292,7 +298,7 @@ - + 0 0 @@ -726,7 +732,7 @@ - + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 253185689..423d5650e 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -65,6 +65,7 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), actionDockWidgetGroups(nullptr), curFile(QString()), isLayoutStale(true), + ignorePrinterFields(false), margins(), paperSize(), isTiled(false), @@ -137,7 +138,8 @@ bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator) CreateShadows(); CreateScenes(); PrepareSceneList(); - margins = lGenerator.GetFields(); + ignorePrinterFields = not lGenerator.IsUsePrinterFields(); + margins = lGenerator.GetPrinterFields(); paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight()); isAutoCrop = lGenerator.GetAutoCrop(); isUnitePages = lGenerator.IsUnitePages(); @@ -647,6 +649,7 @@ void MainWindowsNoGUI::PdfFile(const QString &name, int i) const { printer.setOrientation(QPrinter::Landscape); } + printer.setFullPage(ignorePrinterFields); printer.setPaperSize ( QSizeF(FromPixel(r.width() + margins.left() + margins.right(), Unit::Mm), FromPixel(r.height() + margins.top() + margins.bottom(), Unit::Mm)), QPrinter::Millimeter ); @@ -955,6 +958,8 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr } } + printer->setFullPage(ignorePrinterFields); + const qreal left = FromPixel(margins.left(), Unit::Mm); const qreal top = FromPixel(margins.top(), Unit::Mm); const qreal right = FromPixel(margins.right(), Unit::Mm); diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 208828f9d..5ef548a21 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -86,6 +86,7 @@ protected: QString curFile; bool isLayoutStale; + bool ignorePrinterFields; QMarginsF margins; QSizeF paperSize; diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index ed0359639..7783d388d 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -42,9 +42,9 @@ class QMarginsF; //--------------------------------------------------------------------------------------------------------------------- VLayoutGenerator::VLayoutGenerator(QObject *parent) :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), stripOptimizationEnabled(false), multiplier(1), - stripOptimization(false) + usePrinterFields(true),stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), + rotationIncrease(180), autoCrop(false), saveLength(false), unitePages(false), stripOptimizationEnabled(false), + multiplier(1), stripOptimization(false) {} //--------------------------------------------------------------------------------------------------------------------- @@ -499,14 +499,21 @@ void VLayoutGenerator::SetPaperWidth(qreal value) } //--------------------------------------------------------------------------------------------------------------------- -QMarginsF VLayoutGenerator::GetFields() const +bool VLayoutGenerator::IsUsePrinterFields() const +{ + return usePrinterFields; +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VLayoutGenerator::GetPrinterFields() const { return margins; } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::SetFields(const QMarginsF &value) +void VLayoutGenerator::SetPrinterFields(bool usePrinterFields, const QMarginsF &value) { + this->usePrinterFields = usePrinterFields; margins = value; } diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 2a9d57c8c..90caa59bd 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -71,8 +71,9 @@ public: qreal GetPaperWidth() const; void SetPaperWidth(qreal value); - QMarginsF GetFields() const; - void SetFields(const QMarginsF &value); + bool IsUsePrinterFields() const; + QMarginsF GetPrinterFields() const; + void SetPrinterFields(bool usePrinterFields, const QMarginsF &value); quint32 GetShift() const; void SetShift(quint32 shift); @@ -121,6 +122,7 @@ private: qreal paperHeight; qreal paperWidth; QMarginsF margins; + bool usePrinterFields; volatile bool stopGeneration; LayoutErrors state; quint32 shift; diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index 1340562e2..372be8c51 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -362,9 +362,8 @@ void VSettings::SetLayoutWidth(qreal value) } //--------------------------------------------------------------------------------------------------------------------- -QMarginsF VSettings::GetFields() const +QMarginsF VSettings::GetFields(const QMarginsF &def) const { - const QMarginsF def = GetDefFields(); const QVariant val = value(SettingFields, QVariant::fromValue(def)); if (val.canConvert()) { @@ -373,34 +372,6 @@ QMarginsF VSettings::GetFields() const return def; } -//--------------------------------------------------------------------------------------------------------------------- -QMarginsF VSettings::GetDefFields() -{ - return GetPrinterFields(PreparePrinter(QPrinterInfo::defaultPrinter())); -} - -//--------------------------------------------------------------------------------------------------------------------- -QMarginsF VSettings::GetPrinterFields(const QSharedPointer &printer) -{ - 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) { diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index f1cf57cd8..f419711d3 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -112,9 +112,7 @@ public: static qreal GetDefLayoutWidth(); void SetLayoutWidth(qreal value); - QMarginsF GetFields() const; - static QMarginsF GetDefFields(); - static QMarginsF GetPrinterFields(const QSharedPointer &printer); + QMarginsF GetFields(const QMarginsF &def = QMarginsF()) const; void SetFields(const QMarginsF &value); Cases GetLayoutGroup() const;