diff options
-rw-r--r-- | printer.cpp | 39 | ||||
-rw-r--r-- | printer.h | 2 |
2 files changed, 20 insertions, 21 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); } @@ -21,7 +21,7 @@ private: QSize pageSize; int done; int dpi; - void render(); + void render(int Pages); void putProfileImage(QRect box, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile); private slots: |