diff options
author | Gehad elrobey <gehadelrobey@gmail.com> | 2015-07-10 16:20:14 +0200 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2015-07-20 15:27:39 +0300 |
commit | 4e1a5d954b3cceafce3fb2e4534d7e5c9bd5c770 (patch) | |
tree | 6b5c18e355421d74e997bdd509edac03e0d57679 /printer.cpp | |
parent | 51e36fa15805fdf64d68113ef66910f3f6c8eede (diff) | |
download | subsurface-4e1a5d954b3cceafce3fb2e4534d7e5c9bd5c770.tar.gz |
Printing: refactoring printer class
- Render specific number of pages only.
- Move printer related code to print().
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.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/printer.cpp b/printer.cpp index 446a5c29d..e1179319e 100644 --- a/printer.cpp +++ b/printer.cpp @@ -31,25 +31,8 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter profile->render(painter, pos); } -void Printer::render() +void Printer::render(int Pages = 0) { - // apply user settings - int divesPerPage; - if (printOptions->color_selected && printer->colorMode()) { - printer->setColorMode(QPrinter::Color); - } else { - printer->setColorMode(QPrinter::GrayScale); - } - - // get number of dives per page from data-numberofdives attribute in the body of the selected template - bool ok; - divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); - if (!ok) { - divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed - //TODO: show warning - } - int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); - // keep original preferences QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics(); int profileFrameStyle = profile->frameStyle(); @@ -59,7 +42,7 @@ void Printer::render() // apply printing settings to profile profile->setFrameStyle(QFrame::NoFrame); profile->setPrintMode(true, !printOptions->color_selected); - profile->setFontPrintScale(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi * 0.001); + profile->setFontPrintScale(pageSize.width() * 0.001); profile->setToolTipVisibile(false); prefs.animation_speed = 0; @@ -132,5 +115,21 @@ void Printer::print() pageSize.setWidth(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi); webView->page()->setViewportSize(pageSize); webView->setHtml(t.generate()); - render(); + if (printOptions->color_selected && printer->colorMode()) { + printer->setColorMode(QPrinter::Color); + } else { + printer->setColorMode(QPrinter::GrayScale); + } + // apply user settings + int divesPerPage; + + // get number of dives per page from data-numberofdives attribute in the body of the selected template + bool ok; + divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); + if (!ok) { + divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed + //TODO: show warning + } + int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); + render(Pages); } |