summaryrefslogtreecommitdiffstats
path: root/printer.cpp
diff options
context:
space:
mode:
authorGravatar Gehad elrobey <gehadelrobey@gmail.com>2015-06-17 17:05:14 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2015-06-19 21:41:58 +0300
commit554e64c43fc05d9c529a20263ccec46b6b6dc308 (patch)
tree67355c9bec5c6eb39dc5e4441e998800c94e6b8c /printer.cpp
parent75263e3d2cba649d03579ccfe7f31bcfefd67e8c (diff)
downloadsubsurface-554e64c43fc05d9c529a20263ccec46b6b6dc308.tar.gz
Printing: add support for printing on any page size
Make page size and orientation customizable. The user can select any page size and orientation and then the rendering resolution will be calculated based on the selected preferences and the printer DPI. The HTML templates must be responsive, also the font-size must be based on the viewport width so that we don't lose quality. Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'printer.cpp')
-rw-r--r--printer.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/printer.cpp b/printer.cpp
index f21ff478d..9e5a34b57 100644
--- a/printer.cpp
+++ b/printer.cpp
@@ -6,20 +6,10 @@
#include <QWebElementCollection>
#include <QWebElement>
-#define A4_300DPI_WIDTH 2480
-#define A4_300DPI_HIGHT 3508
-
Printer::Printer(QPrinter *printer, print_options *printOptions)
{
this->printer = printer;
this->printOptions = printOptions;
-
- //override these settings for now.
- printer->setFullPage(true);
- printer->setOrientation(QPrinter::Portrait);
- printer->setPaperSize(QPrinter::A4);
- printer->setPrintRange(QPrinter::AllPages);
- printer->setResolution(300);
done = 0;
}
@@ -51,12 +41,10 @@ void Printer::render()
// render the Qwebview
QPainter painter;
- QSize size(A4_300DPI_WIDTH, A4_300DPI_HIGHT);
- QRect viewPort(0, 0, size.width(), size.height());
+ QRect viewPort(0, 0, pageSize.width(), pageSize.height());
painter.begin(printer);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
- webView->page()->setViewportSize(size);
int divesPerPage;
switch (printOptions->p_template) {
@@ -91,8 +79,8 @@ void Printer::render()
}
// scroll the webview to the next page
- webView->page()->mainFrame()->scroll(0, size.height());
- viewPort.adjust(0, size.height(), 0, size.height());
+ webView->page()->mainFrame()->scroll(0, pageSize.height());
+ viewPort.adjust(0, pageSize.height(), 0, pageSize.height());
// rendering progress is 4/5 of total work
emit(progessUpdated((i * 80.0 / Pages) + done));
@@ -123,8 +111,14 @@ void Printer::templateProgessUpdated(int value)
void Printer::print()
{
TemplateLayout t(printOptions);
- connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
webView = new QWebView();
+ connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
+
+ dpi = printer->resolution();
+ //rendering resolution = selected paper size in inchs * printer dpi
+ pageSize.setHeight(printer->pageLayout().paintRect(QPageLayout::Inch).height() * dpi);
+ pageSize.setWidth(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi);
+ webView->page()->setViewportSize(pageSize);
webView->setHtml(t.generate());
render();
}