From 9327da7a2cb75fabcf37ba5291d64fee18efb1b7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Nov 2015 13:58:45 +0200 Subject: [PATCH] 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;