From 142fd950c8d69dc4d4aad4034fe65ca400d37783 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 20:34:25 +0200 Subject: Printing: change QPrinter to parent class QPaintDevice Use general class QPaintDevice to be used for printing and previewing instances, printing uses a QPrinter object while previewing uses a QPixmap instance. We use static_cast to use the needed object. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'printer.cpp') diff --git a/printer.cpp b/printer.cpp index e1179319e..da5d5142d 100644 --- a/printer.cpp +++ b/printer.cpp @@ -6,9 +6,9 @@ #include #include -Printer::Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions) +Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions) { - this->printer = printer; + this->paintDevice = paintDevice; this->printOptions = printOptions; this->templateOptions = templateOptions; dpi = 0; @@ -49,7 +49,7 @@ void Printer::render(int Pages = 0) // render the Qwebview QPainter painter; QRect viewPort(0, 0, pageSize.width(), pageSize.height()); - painter.begin(printer); + painter.begin(paintDevice); painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); @@ -81,7 +81,7 @@ void Printer::render(int Pages = 0) // rendering progress is 4/5 of total work emit(progessUpdated((i * 80.0 / Pages) + done)); if (i < Pages - 1) - printer->newPage(); + static_cast(paintDevice)->newPage(); } painter.end(); @@ -106,19 +106,21 @@ void Printer::templateProgessUpdated(int value) void Printer::print() { + QPrinter *printerPtr; + printerPtr = static_cast(paintDevice); + TemplateLayout t(printOptions, templateOptions); connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int))); - - dpi = printer->resolution(); + dpi = printerPtr->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); + pageSize.setHeight(printerPtr->pageLayout().paintRect(QPageLayout::Inch).height() * dpi); + pageSize.setWidth(printerPtr->pageLayout().paintRect(QPageLayout::Inch).width() * dpi); webView->page()->setViewportSize(pageSize); webView->setHtml(t.generate()); - if (printOptions->color_selected && printer->colorMode()) { - printer->setColorMode(QPrinter::Color); + if (printOptions->color_selected && printerPtr->colorMode()) { + printerPtr->setColorMode(QPrinter::Color); } else { - printer->setColorMode(QPrinter::GrayScale); + printerPtr->setColorMode(QPrinter::GrayScale); } // apply user settings int divesPerPage; -- cgit v1.2.3-70-g09d2