mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <gehadelrobey@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
4e1a5d954b
commit
142fd950c8
2 changed files with 15 additions and 13 deletions
24
printer.cpp
24
printer.cpp
|
@ -6,9 +6,9 @@
|
||||||
#include <QWebElementCollection>
|
#include <QWebElementCollection>
|
||||||
#include <QWebElement>
|
#include <QWebElement>
|
||||||
|
|
||||||
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->printOptions = printOptions;
|
||||||
this->templateOptions = templateOptions;
|
this->templateOptions = templateOptions;
|
||||||
dpi = 0;
|
dpi = 0;
|
||||||
|
@ -49,7 +49,7 @@ void Printer::render(int Pages = 0)
|
||||||
// render the Qwebview
|
// render the Qwebview
|
||||||
QPainter painter;
|
QPainter painter;
|
||||||
QRect viewPort(0, 0, pageSize.width(), pageSize.height());
|
QRect viewPort(0, 0, pageSize.width(), pageSize.height());
|
||||||
painter.begin(printer);
|
painter.begin(paintDevice);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ void Printer::render(int Pages = 0)
|
||||||
// rendering progress is 4/5 of total work
|
// rendering progress is 4/5 of total work
|
||||||
emit(progessUpdated((i * 80.0 / Pages) + done));
|
emit(progessUpdated((i * 80.0 / Pages) + done));
|
||||||
if (i < Pages - 1)
|
if (i < Pages - 1)
|
||||||
printer->newPage();
|
static_cast<QPrinter*>(paintDevice)->newPage();
|
||||||
}
|
}
|
||||||
painter.end();
|
painter.end();
|
||||||
|
|
||||||
|
@ -106,19 +106,21 @@ void Printer::templateProgessUpdated(int value)
|
||||||
|
|
||||||
void Printer::print()
|
void Printer::print()
|
||||||
{
|
{
|
||||||
|
QPrinter *printerPtr;
|
||||||
|
printerPtr = static_cast<QPrinter*>(paintDevice);
|
||||||
|
|
||||||
TemplateLayout t(printOptions, templateOptions);
|
TemplateLayout t(printOptions, templateOptions);
|
||||||
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
||||||
|
dpi = printerPtr->resolution();
|
||||||
dpi = printer->resolution();
|
|
||||||
//rendering resolution = selected paper size in inchs * printer dpi
|
//rendering resolution = selected paper size in inchs * printer dpi
|
||||||
pageSize.setHeight(printer->pageLayout().paintRect(QPageLayout::Inch).height() * dpi);
|
pageSize.setHeight(printerPtr->pageLayout().paintRect(QPageLayout::Inch).height() * dpi);
|
||||||
pageSize.setWidth(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi);
|
pageSize.setWidth(printerPtr->pageLayout().paintRect(QPageLayout::Inch).width() * dpi);
|
||||||
webView->page()->setViewportSize(pageSize);
|
webView->page()->setViewportSize(pageSize);
|
||||||
webView->setHtml(t.generate());
|
webView->setHtml(t.generate());
|
||||||
if (printOptions->color_selected && printer->colorMode()) {
|
if (printOptions->color_selected && printerPtr->colorMode()) {
|
||||||
printer->setColorMode(QPrinter::Color);
|
printerPtr->setColorMode(QPrinter::Color);
|
||||||
} else {
|
} else {
|
||||||
printer->setColorMode(QPrinter::GrayScale);
|
printerPtr->setColorMode(QPrinter::GrayScale);
|
||||||
}
|
}
|
||||||
// apply user settings
|
// apply user settings
|
||||||
int divesPerPage;
|
int divesPerPage;
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Printer : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPrinter *printer;
|
QPaintDevice *paintDevice;
|
||||||
QWebView *webView;
|
QWebView *webView;
|
||||||
print_options *printOptions;
|
print_options *printOptions;
|
||||||
template_options *templateOptions;
|
template_options *templateOptions;
|
||||||
|
@ -28,7 +28,7 @@ private slots:
|
||||||
void templateProgessUpdated(int value);
|
void templateProgessUpdated(int value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions);
|
Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions);
|
||||||
~Printer();
|
~Printer();
|
||||||
void print();
|
void print();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue