summaryrefslogtreecommitdiffstats
path: root/printer.cpp
diff options
context:
space:
mode:
authorGravatar Gehad elrobey <gehadelrobey@gmail.com>2015-08-13 23:23:07 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2015-08-15 15:04:45 +0300
commit6a9c4cb9d794056ccb75e6a0d35cde060473b71e (patch)
tree1bf1ce46d2c34dfd257fcf813a4bb564cbb5281a /printer.cpp
parent31df69c401ad8995d8201242a1db1b74de19a18a (diff)
downloadsubsurface-6a9c4cb9d794056ccb75e6a0d35cde060473b71e.tar.gz
Printing: don't break dives into successive pages
While rendering a template with "0" dives per page value, try to fit as many dives per page but don't break a dive into 2 pages. Use a dynamically sized view port to fit the rendered area only, and don't render the full page. All the Template elements that shouldn't be broken should have the CSS class "dontbreak". Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Diffstat (limited to 'printer.cpp')
-rw-r--r--printer.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/printer.cpp b/printer.cpp
index 115b17526..5d7adcacc 100644
--- a/printer.cpp
+++ b/printer.cpp
@@ -57,6 +57,46 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter
}
}
+void Printer::flowRender()
+{
+ // render the Qwebview
+ QPainter painter;
+ QRect viewPort(0, 0, 0, 0);
+ painter.begin(paintDevice);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setRenderHint(QPainter::SmoothPixmapTransform);
+
+ // get all references to dontbreak divs
+ int start = 0, end = 0;
+ int fullPageResolution = webView->page()->mainFrame()->contentsSize().height();
+ QWebElementCollection dontbreak = webView->page()->mainFrame()->findAllElements(".dontbreak");
+ foreach (QWebElement dontbreakElement, dontbreak) {
+ if ((dontbreakElement.geometry().y() + dontbreakElement.geometry().height()) - start < pageSize.height()) {
+ // One more element can be placed
+ end = dontbreakElement.geometry().y() + dontbreakElement.geometry().height();
+ } else {
+ QRegion reigon(0, 0, pageSize.width(), end - start);
+ viewPort.setRect(0, start, pageSize.width(), end - start);
+
+ // render the base Html template
+ webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer, reigon);
+
+ // scroll the webview to the next page
+ webView->page()->mainFrame()->scroll(0, dontbreakElement.geometry().y() - start);
+
+ // rendering progress is 4/5 of total work
+ emit(progessUpdated((end * 80.0 / fullPageResolution) + done));
+ static_cast<QPrinter*>(paintDevice)->newPage();
+ start = dontbreakElement.geometry().y();
+ }
+ }
+ // render the remianing page
+ QRegion reigon(0, 0, pageSize.width(), end - start);
+ webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer, reigon);
+
+ painter.end();
+}
+
void Printer::render(int Pages = 0)
{
// keep original preferences
@@ -175,11 +215,11 @@ void Printer::print()
int paddingBottom = pageSize.height() - (webView->page()->mainFrame()->contentsSize().height() % pageSize.height());
QString styleString = QString::fromUtf8("padding-bottom: ") + QString::number(paddingBottom) + "px;";
webView->page()->mainFrame()->findFirstElement("body").setAttribute("style", styleString);
- Pages = ceil(webView->page()->mainFrame()->contentsSize().height() / (float)pageSize.height());
+ flowRender();
} else {
Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage);
+ render(Pages);
}
- render(Pages);
}
void Printer::print_statistics()