From e7e177898c55769d5d9a7c5c3a52198f8b3ab3da Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Nov 2015 14:29:37 +0200 Subject: [PATCH] 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;