From d2396820c5880c92432e7788f74ac7d60a114e46 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 18 Jun 2019 12:35:43 +0300 Subject: [PATCH] Fix bug with landscape oriention. --HG-- branch : develop --- src/app/valentina/mainwindowsnogui.cpp | 20 +++++++++++++++++--- src/app/valentina/mainwindowsnogui.h | 1 + src/libs/vlayout/vlayoutgenerator.h | 3 ++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 753a1bc09..cd0cddd6b 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -319,6 +319,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator) details = lGenerator.GetAllDetailsItems();// All details items detailsOnLayout = lGenerator.GetAllDetails();// All details items shadows = CreateShadows(papers); + isLayoutPortrait = lGenerator.IsPortrait(); scenes = CreateScenes(papers, shadows, details); //Uncomment to debug, shows global contour // gcontours = lGenerator.GetGlobalContours(); // uncomment for debugging @@ -1522,7 +1523,7 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr printer->setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+ QCoreApplication::applicationVersion()); - printer->setOrientation(QPrinter::Portrait); + printer->setOrientation(isLayoutPortrait ? QPrinter::Portrait : QPrinter::Landscape); if (not isTiled) { @@ -1532,11 +1533,24 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr auto *paper = qgraphicsitem_cast(papers.at(0)); if (paper) { - size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), - FromPixel(paper->rect().height() + margins.top() + margins.bottom(), Unit::Mm)); + if (isLayoutPortrait) + { + size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), + FromPixel(paper->rect().height() + margins.top() + margins.bottom(), Unit::Mm)); + } + else + { + size = QSizeF(FromPixel(paper->rect().width() + margins.left() + margins.right(), Unit::Mm), + FromPixel(paperSize.height(), Unit::Mm)); + } } } + if (not isLayoutPortrait) + { + size.transpose(); // QPrinter reverse this for landscape orientation + } + const QPageSize::PageSizeId pSZ = FindPageSizeId(size); if (pSZ == QPageSize::Custom) { diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index f8e556d53..c80ae6ba8 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -114,6 +114,7 @@ protected: bool isLayoutStale; bool isNeedAutosave; bool ignorePrinterFields; + bool isLayoutPortrait{true}; QMarginsF margins; QSizeF paperSize; diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 80c4265e2..2f8181d3a 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -122,6 +122,8 @@ public: bool IsRotationNeeded() const; + bool IsPortrait() const; + public slots: void Abort(); void Timeout(); @@ -152,7 +154,6 @@ private: int PageHeight() const; int PageWidth() const; - bool IsPortrait() const; void GatherPages(); void UnitePages();