diff options
author | 2015-07-05 12:01:43 -0700 | |
---|---|---|
committer | 2015-07-05 12:01:43 -0700 | |
commit | 9c6a3a7ff387578ddede2e69d8b994a11cf8eaee (patch) | |
tree | 72a08592a24d8d3d1f4fc7d7713da8029bc80c3f /printer.cpp | |
parent | 35dc81410518e6d39ba8b3f99348884778bedc5b (diff) | |
parent | cc53dc7acf801f022612678f697e6d76c2443153 (diff) | |
download | subsurface-9c6a3a7ff387578ddede2e69d8b994a11cf8eaee.tar.gz |
Merge branch 'custom-print' of github.com:neolit123/subsurface
Diffstat (limited to 'printer.cpp')
-rw-r--r-- | printer.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/printer.cpp b/printer.cpp index 79f04e4a0..f8a90f96d 100644 --- a/printer.cpp +++ b/printer.cpp @@ -6,10 +6,11 @@ #include <QWebElementCollection> #include <QWebElement> -Printer::Printer(QPrinter *printer, print_options *printOptions) +Printer::Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions) { this->printer = printer; this->printOptions = printOptions; + this->templateOptions = templateOptions; dpi = 0; done = 0; } @@ -26,9 +27,25 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter void Printer::render() { - QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics(); + // 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(); int animationOriginal = prefs.animation_speed; double fontScale = profile->getFontPrintScale(); @@ -36,7 +53,7 @@ void Printer::render() // apply printing settings to profile profile->setFrameStyle(QFrame::NoFrame); profile->setPrintMode(true, !printOptions->color_selected); - profile->setFontPrintScale(0.6); + profile->setFontPrintScale(printer->pageLayout().paintRect(QPageLayout::Inch).width() * dpi * 0.001); profile->setToolTipVisibile(false); prefs.animation_speed = 0; @@ -47,17 +64,6 @@ void Printer::render() painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); - int divesPerPage; - switch (printOptions->p_template) { - case print_options::ONE_DIVE: - divesPerPage = 1; - break; - case print_options::TWO_DIVE: - divesPerPage = 2; - break; - } - int Pages = ceil(getTotalWork() / (float)divesPerPage); - // get all refereces to diveprofile class in the Html template QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile"); @@ -111,7 +117,7 @@ void Printer::templateProgessUpdated(int value) void Printer::print() { - TemplateLayout t(printOptions); + TemplateLayout t(printOptions, templateOptions); webView = new QWebView(); connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int))); |