aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/printer.cpp
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2016-08-09 00:12:12 +0200
committerGravatar Robert C. Helling <helling@atdotde.de>2016-12-30 19:43:00 +0100
commit529a4d499b8dad35de6cd43e3004017ccfd288aa (patch)
treefb0f163c32c029134a849ac49183849870b3c0ae /desktop-widgets/printer.cpp
parent10b8bda6626fe1de602e38da34de419972031755 (diff)
downloadsubsurface-529a4d499b8dad35de6cd43e3004017ccfd288aa.tar.gz
Start transition from QWebKit to QWebEngine
This removes all references to WebKit if cmake option USE_WEBKIT is enabled. For the user manual it changes it to WebEngine (seems to work for me). Similar for the Facebook connection (minus a reference to a cookie jar). This I could not test at the moment, as I wrote this on a train. Printing does not work, it is a null operation at the moment. Currently, large parts of of the printing code are commented out as there is no direct way to access page elements in WebEngine. It seems this needs to be done via Javascript (with a callback invoked). There is new functionality in WebEngine to render a view to a PDF file but this needs more work (and probably some thoughts towards page breaks). Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'desktop-widgets/printer.cpp')
-rw-r--r--desktop-widgets/printer.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp
index eea304347..bad1c2760 100644
--- a/desktop-widgets/printer.cpp
+++ b/desktop-widgets/printer.cpp
@@ -4,10 +4,14 @@
#include "core/helpers.h"
#include <algorithm>
-#include <QtWebKitWidgets>
#include <QPainter>
+#ifdef USE_WEBENGINE
+#include <QtWebEngineWidgets>
+#else
+#include <QtWebKitWidgets>
#include <QWebElementCollection>
#include <QWebElement>
+#endif
#include "profile-widget/profilewidget2.h"
Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode)
@@ -18,7 +22,11 @@ Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, templat
this->printMode = printMode;
dpi = 0;
done = 0;
+#ifdef USE_WEBENGINE
+ webView = new QWebEngineView();
+#else
webView = new QWebView();
+#endif
}
Printer::~Printer()
@@ -61,6 +69,7 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter
void Printer::flowRender()
{
// add extra padding at the bottom to pages with height not divisible by view port
+#ifndef USE_WEBENGINE
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);
@@ -115,6 +124,9 @@ void Printer::flowRender()
webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer, reigon);
painter.end();
+#else
+ // FIX ME
+#endif
}
void Printer::render(int Pages = 0)
@@ -140,6 +152,9 @@ void Printer::render(int Pages = 0)
painter.setRenderHint(QPainter::SmoothPixmapTransform);
// get all refereces to diveprofile class in the Html template
+#ifdef USE_WEBENGINE
+ //FIX ME
+#else
QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile");
QSize originalSize = profile->size();
@@ -173,13 +188,18 @@ void Printer::render(int Pages = 0)
static_cast<QPrinter*>(paintDevice)->newPage();
}
painter.end();
+#endif
// return profle settings
profile->setFrameStyle(profileFrameStyle);
profile->setPrintMode(false);
profile->setFontPrintScale(fontScale);
profile->setToolTipVisibile(true);
+#ifdef USE_WEBENGINE
+ //FIXME
+#else
profile->resize(originalSize);
+#endif
prefs.animation_speed = animationOriginal;
//replot the dive after returning the settings
@@ -210,8 +230,12 @@ void Printer::print()
//rendering resolution = selected paper size in inchs * printer dpi
pageSize.setHeight(qCeil(printerPtr->pageRect(QPrinter::Inch).height() * dpi));
pageSize.setWidth(qCeil(printerPtr->pageRect(QPrinter::Inch).width() * dpi));
+#ifdef USE_WEBENGINE
+ //FIXME
+#else
webView->page()->setViewportSize(pageSize);
webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
+#endif
// export border width with at least 1 pixel
templateOptions->border_width = std::max(1, pageSize.width() / 1000);
if (printOptions->type == print_options::DIVELIST) {
@@ -229,11 +253,15 @@ void Printer::print()
// get number of dives per page from data-numberofdives attribute in the body of the selected template
bool ok;
+#ifdef USE_WEBENGINE
+ // FIX ME
+#else
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
}
+#endif
int Pages;
if (divesPerPage == 0) {
flowRender();
@@ -250,7 +278,11 @@ void Printer::previewOnePage()
pageSize.setHeight(paintDevice->height());
pageSize.setWidth(paintDevice->width());
+#ifdef USE_WEBENGINE
+ //FIXME
+#else
webView->page()->setViewportSize(pageSize);
+#endif
// initialize the border settings
templateOptions->border_width = std::max(1, pageSize.width() / 1000);
if (printOptions->type == print_options::DIVELIST) {
@@ -258,7 +290,10 @@ void Printer::previewOnePage()
} else if (printOptions->type == print_options::STATISTICS ) {
webView->setHtml(t.generateStatistics());
}
-
+#ifdef USE_WEBENGINE
+ // FIX ME
+ render(1);
+#else
bool ok;
int divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok);
if (!ok) {
@@ -270,5 +305,6 @@ void Printer::previewOnePage()
} else {
render(1);
}
+#endif
}
}