From 3f801298e138ce51bf05ae220d054b892155219d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 19 Apr 2015 12:33:30 +0300 Subject: [PATCH] Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter. --HG-- branch : develop --- src/app/tablewindow.cpp | 49 +++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/app/tablewindow.cpp b/src/app/tablewindow.cpp index 3792a2c0f..b5536f283 100644 --- a/src/app/tablewindow.cpp +++ b/src/app/tablewindow.cpp @@ -313,17 +313,52 @@ void TableWindow::Print(QPrinter *printer) return; } - for (int i=0; i < poster.size(); i++) + // Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter. + int firstPage = printer->fromPage() - 1; + if (firstPage >= poster.size()) { - painter.drawImage(QPointF(), poster.at(i)); + return; + } + if (firstPage == -1) + { + firstPage = 0; + } - if (i+1 < poster.size()) + int lastPage = printer->toPage() - 1; + if (lastPage == -1 || lastPage >= poster.size()) + { + lastPage = poster.size() - 1; + } + + const int numPages = lastPage - firstPage + 1; + int copyCount = 1; + if (not printer->supportsMultipleCopies()) + { + copyCount = printer->copyCount(); + } + + for (int i = 0; i < copyCount; ++i) + { + for (int j = 0; j < numPages; ++j) { - if (not printer->newPage()) + if (i != 0 || j != 0) { - qWarning("failed in flushing page to disk, disk full?"); - return; + if (not printer->newPage()) + { + qWarning("failed in flushing page to disk, disk full?"); + return; + } } + int index; + if (printer->pageOrder() == QPrinter::FirstPageFirst) + { + index = firstPage + j; + } + else + { + index = lastPage - j; + } + painter.drawImage(QPointF(), poster.at(index)); } } @@ -334,7 +369,7 @@ void TableWindow::Print(QPrinter *printer) void TableWindow::LayoutPrint() { // display print dialog and if accepted print - QPrinter printer; + QPrinter printer(QPrinter::HighResolution); printer.setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion()); printer.setDocName(fileName); QPrintDialog dialog( &printer, this );