From 342095408a6fd6f0dce28627c09ecabd3d5d43dd Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 2 Jun 2016 16:51:37 +0300 Subject: [PATCH] Show message "Pages will be cropped because they do not fit printer paper size." --HG-- branch : develop --- src/app/valentina/mainwindowsnogui.cpp | 28 +++++++++++++++++++++++++- src/app/valentina/mainwindowsnogui.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 1d9dfa98b..d810b50d5 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -341,6 +341,9 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) copyCount = printer->copyCount(); } + qreal left, top, right, bottom; + printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter); + for (int i = 0; i < copyCount; ++i) { for (int j = 0; j < numPages; ++j) @@ -362,7 +365,7 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) { index = lastPage - j; } - painter.drawImage(QPointF(margins.left(), margins.top()), poster.at(index)); + painter.drawImage(QPointF(left, top), poster.at(index)); } } @@ -793,6 +796,12 @@ void MainWindowsNoGUI::SaveLayoutAs() QPrinter printer; SetPrinterSettings(&printer, PrintType::PrintPDF); + // Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size + if (not isTiled && not IsPagesFit(printer.paperRect().size())) + { + qWarning()<ValentinaSettings()->GetPathLayout()+"/"+FileName()+".pdf", tr("PDF file (*.pdf)")); @@ -831,6 +840,7 @@ void MainWindowsNoGUI::PrintPreview() } SetPrinterSettings(printer.data(), PrintType::PrintPreview); + printer->setResolution(static_cast(PrintDPI)); // display print preview dialog QPrintPreviewDialog preview(printer.data()); connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages); @@ -1023,6 +1033,22 @@ bool MainWindowsNoGUI::isPagesUniform() const return true; } +//--------------------------------------------------------------------------------------------------------------------- +bool MainWindowsNoGUI::IsPagesFit(const QSizeF &printPaper) const +{ + // On previous stage already was checked if pages have uniform size + // Enough will be to check only one page + QGraphicsRectItem *p = qgraphicsitem_cast(papers.at(0)); + SCASSERT(p != nullptr); + const QSizeF pSize = p->rect().size(); + if (pSize.height() <= printPaper.height() && pSize.width() <= printPaper.width()) + { + return true; + } + + return false; +} + //--------------------------------------------------------------------------------------------------------------------- QString MainWindowsNoGUI::FileName() const { diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index c2d0a8cb4..d51ebc22e 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -130,6 +130,7 @@ private: QPrinter::PaperSize FindTemplate(const QSizeF &size) const; bool isPagesUniform() const; + bool IsPagesFit(const QSizeF &printPaper) const; QString FileName() const; int ContinueIfLayoutStale();