This commit is contained in:
Dirk Hohndel 2016-12-30 14:27:04 -08:00
commit 47d5dc9681
10 changed files with 166 additions and 8 deletions

View file

@ -33,6 +33,7 @@ option(NO_USERMANUAL "don't include a viewer for the user manual" OFF)
option(FBSUPPORT "allow posting to Facebook" ON) option(FBSUPPORT "allow posting to Facebook" ON)
option(BTSUPPORT "enable support for QtBluetooth (requires Qt5.4 or newer)" ON) option(BTSUPPORT "enable support for QtBluetooth (requires Qt5.4 or newer)" ON)
option(FTDISUPPORT "enable support for libftdi based serial" OFF) option(FTDISUPPORT "enable support for libftdi based serial" OFF)
option(USE_WEBENGINE "Use QWebEngine instead of QWebKit" OFF)
# Options regarding What should we build on subsurface # Options regarding What should we build on subsurface
option(MAKE_TESTS "Make the tests" ON) option(MAKE_TESTS "Make the tests" ON)

View file

@ -2,6 +2,13 @@ if(NO_USERMANUAL)
message(STATUS "building without usermanual") message(STATUS "building without usermanual")
add_definitions(-DNO_USERMANUAL) add_definitions(-DNO_USERMANUAL)
else() else()
list(APPEND QT_EXTRA_COMPONENTS WebKitWidgets) if(USE_WEBENGINE)
list(APPEND QT_EXTRA_LIBRARIES Qt5::WebKitWidgets) message(STATUS "building with QWebEngine")
list(APPEND QT_EXTRA_COMPONENTS WebEngineWidgets)
list(APPEND QT_EXTRA_LIBRARIES Qt5::WebEngineWidgets)
add_definitions(-DUSE_WEBENGINE)
else()
list(APPEND QT_EXTRA_COMPONENTS WebKitWidgets)
list(APPEND QT_EXTRA_LIBRARIES Qt5::WebKitWidgets)
endif()
endif() endif()

View file

@ -100,6 +100,8 @@ SHashedImage::SHashedImage(struct picture *picture) : QImage()
// This did not load anything. Let's try to get the image from other sources // This did not load anything. Let's try to get the image from other sources
// Let's try to load it locally via its hash // Let's try to load it locally via its hash
QString filename = fileFromHash(picture->hash); QString filename = fileFromHash(picture->hash);
if (filename.isNull())
filename = QString(picture->filename);
if (filename.isNull()) { if (filename.isNull()) {
// That didn't produce a local filename. // That didn't produce a local filename.
// Try the cloud server // Try the cloud server

View file

@ -1075,6 +1075,8 @@ QByteArray hashFile(const QString filename)
void learnHash(struct picture *picture, QByteArray hash) void learnHash(struct picture *picture, QByteArray hash)
{ {
if (hash.isNull())
return;
if (picture->hash) if (picture->hash)
free(picture->hash); free(picture->hash);
QMutexLocker locker(&hashOfMutex); QMutexLocker locker(&hashOfMutex);
@ -1100,6 +1102,8 @@ QString localFilePath(const QString originalFilename)
QString fileFromHash(char *hash) QString fileFromHash(char *hash)
{ {
if (!hash || !*hash)
return "";
QMutexLocker locker(&hashOfMutex); QMutexLocker locker(&hashOfMutex);
return localFilenameOf[QByteArray::fromHex(hash)]; return localFilenameOf[QByteArray::fromHex(hash)];
@ -1120,7 +1124,7 @@ void hashPicture(struct picture *picture)
if (!picture) if (!picture)
return; return;
char *oldHash = copy_string(picture->hash); char *oldHash = copy_string(picture->hash);
learnHash(picture, hashFile(QString(picture->filename))); learnHash(picture, hashFile(localFilePath(picture->filename)));
if (!same_string(picture->hash, "") && !same_string(picture->hash, oldHash)) if (!same_string(picture->hash, "") && !same_string(picture->hash, oldHash))
mark_divelist_changed((true)); mark_divelist_changed((true));
free(oldHash); free(oldHash);

View file

@ -16,8 +16,11 @@
#include <QDebug> #include <QDebug>
#include <QMessageBox> #include <QMessageBox>
#include <QInputDialog> #include <QInputDialog>
#ifdef USE_WEBENGINE
#include <QWebEngineView>
#else
#include <QWebView> #include <QWebView>
#endif
#include "mainwindow.h" #include "mainwindow.h"
#include "profile-widget/profilewidget2.h" #include "profile-widget/profilewidget2.h"
@ -224,14 +227,22 @@ void FacebookManager::sendDive()
FacebookConnectWidget::FacebookConnectWidget(QWidget *parent) : QDialog(parent), ui(new Ui::FacebookConnectWidget) { FacebookConnectWidget::FacebookConnectWidget(QWidget *parent) : QDialog(parent), ui(new Ui::FacebookConnectWidget) {
ui->setupUi(this); ui->setupUi(this);
FacebookManager *fb = FacebookManager::instance(); FacebookManager *fb = FacebookManager::instance();
#ifdef USE_WEBENGINE
facebookWebView = new QWebEngineView(this);
#else
facebookWebView = new QWebView(this); facebookWebView = new QWebView(this);
#endif
ui->fbWebviewContainer->layout()->addWidget(facebookWebView); ui->fbWebviewContainer->layout()->addWidget(facebookWebView);
if (fb->loggedIn()) { if (fb->loggedIn()) {
facebookLoggedIn(); facebookLoggedIn();
} else { } else {
facebookDisconnect(); facebookDisconnect();
} }
#ifdef USE_WEBENGINE
connect(facebookWebView, &QWebEngineView::urlChanged, fb, &FacebookManager::tryLogin);
#else
connect(facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin); connect(facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin);
#endif
connect(fb, &FacebookManager::justLoggedIn, this, &FacebookConnectWidget::facebookLoggedIn); connect(fb, &FacebookManager::justLoggedIn, this, &FacebookConnectWidget::facebookLoggedIn);
} }
@ -250,7 +261,11 @@ void FacebookConnectWidget::facebookDisconnect()
ui->fbWebviewContainer->setEnabled(true); ui->fbWebviewContainer->setEnabled(true);
ui->FBLabel->setText(tr("To connect to Facebook, please log in. This enables Subsurface to publish dives to your timeline")); ui->FBLabel->setText(tr("To connect to Facebook, please log in. This enables Subsurface to publish dives to your timeline"));
if (facebookWebView) { if (facebookWebView) {
#ifdef USE_WEBENGINE
//FIX ME
#else
facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar()); facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar());
#endif
facebookWebView->setUrl(FacebookManager::instance()->connectUrl()); facebookWebView->setUrl(FacebookManager::instance()->connectUrl());
} }
} }

View file

@ -2,7 +2,11 @@
#define FACEBOOKCONNECTWIDGET_H #define FACEBOOKCONNECTWIDGET_H
#include <QDialog> #include <QDialog>
#ifdef USE_WEBENGINE
class QWebEngineView;
#else
class QWebView; class QWebView;
#endif
namespace Ui { namespace Ui {
class FacebookConnectWidget; class FacebookConnectWidget;
class SocialnetworksDialog; class SocialnetworksDialog;
@ -41,7 +45,11 @@ public:
void facebookDisconnect(); void facebookDisconnect();
private: private:
Ui::FacebookConnectWidget *ui; Ui::FacebookConnectWidget *ui;
#ifdef USE_WEBENGINE
QWebEngineView *facebookWebView;
#else
QWebView *facebookWebView; QWebView *facebookWebView;
#endif
}; };
class SocialNetworkDialog : public QDialog { class SocialNetworkDialog : public QDialog {

View file

@ -4,10 +4,14 @@
#include "core/helpers.h" #include "core/helpers.h"
#include <algorithm> #include <algorithm>
#include <QtWebKitWidgets>
#include <QPainter> #include <QPainter>
#ifdef USE_WEBENGINE
#include <QtWebEngineWidgets>
#else
#include <QtWebKitWidgets>
#include <QWebElementCollection> #include <QWebElementCollection>
#include <QWebElement> #include <QWebElement>
#endif
#include "profile-widget/profilewidget2.h" #include "profile-widget/profilewidget2.h"
Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode) 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; this->printMode = printMode;
dpi = 0; dpi = 0;
done = 0; done = 0;
#ifdef USE_WEBENGINE
webView = new QWebEngineView();
#else
webView = new QWebView(); webView = new QWebView();
#endif
} }
Printer::~Printer() Printer::~Printer()
@ -61,6 +69,7 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter
void Printer::flowRender() void Printer::flowRender()
{ {
// add extra padding at the bottom to pages with height not divisible by view port // 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()); int paddingBottom = pageSize.height() - (webView->page()->mainFrame()->contentsSize().height() % pageSize.height());
QString styleString = QString::fromUtf8("padding-bottom: ") + QString::number(paddingBottom) + "px;"; QString styleString = QString::fromUtf8("padding-bottom: ") + QString::number(paddingBottom) + "px;";
webView->page()->mainFrame()->findFirstElement("body").setAttribute("style", styleString); webView->page()->mainFrame()->findFirstElement("body").setAttribute("style", styleString);
@ -115,6 +124,9 @@ void Printer::flowRender()
webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer, reigon); webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer, reigon);
painter.end(); painter.end();
#else
// FIX ME
#endif
} }
void Printer::render(int Pages = 0) void Printer::render(int Pages = 0)
@ -140,6 +152,9 @@ void Printer::render(int Pages = 0)
painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::SmoothPixmapTransform);
// get all refereces to diveprofile class in the Html template // get all refereces to diveprofile class in the Html template
#ifdef USE_WEBENGINE
//FIX ME
#else
QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile"); QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile");
QSize originalSize = profile->size(); QSize originalSize = profile->size();
@ -173,13 +188,18 @@ void Printer::render(int Pages = 0)
static_cast<QPrinter*>(paintDevice)->newPage(); static_cast<QPrinter*>(paintDevice)->newPage();
} }
painter.end(); painter.end();
#endif
// return profle settings // return profle settings
profile->setFrameStyle(profileFrameStyle); profile->setFrameStyle(profileFrameStyle);
profile->setPrintMode(false); profile->setPrintMode(false);
profile->setFontPrintScale(fontScale); profile->setFontPrintScale(fontScale);
profile->setToolTipVisibile(true); profile->setToolTipVisibile(true);
#ifdef USE_WEBENGINE
//FIXME
#else
profile->resize(originalSize); profile->resize(originalSize);
#endif
prefs.animation_speed = animationOriginal; prefs.animation_speed = animationOriginal;
//replot the dive after returning the settings //replot the dive after returning the settings
@ -210,8 +230,12 @@ void Printer::print()
//rendering resolution = selected paper size in inchs * printer dpi //rendering resolution = selected paper size in inchs * printer dpi
pageSize.setHeight(qCeil(printerPtr->pageRect(QPrinter::Inch).height() * dpi)); pageSize.setHeight(qCeil(printerPtr->pageRect(QPrinter::Inch).height() * dpi));
pageSize.setWidth(qCeil(printerPtr->pageRect(QPrinter::Inch).width() * dpi)); pageSize.setWidth(qCeil(printerPtr->pageRect(QPrinter::Inch).width() * dpi));
#ifdef USE_WEBENGINE
//FIXME
#else
webView->page()->setViewportSize(pageSize); webView->page()->setViewportSize(pageSize);
webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
#endif
// export border width with at least 1 pixel // export border width with at least 1 pixel
templateOptions->border_width = std::max(1, pageSize.width() / 1000); templateOptions->border_width = std::max(1, pageSize.width() / 1000);
if (printOptions->type == print_options::DIVELIST) { 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 // get number of dives per page from data-numberofdives attribute in the body of the selected template
bool ok; bool ok;
#ifdef USE_WEBENGINE
// FIX ME
#else
divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok);
if (!ok) { if (!ok) {
divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed
//TODO: show warning //TODO: show warning
} }
#endif
int Pages; int Pages;
if (divesPerPage == 0) { if (divesPerPage == 0) {
flowRender(); flowRender();
@ -250,7 +278,11 @@ void Printer::previewOnePage()
pageSize.setHeight(paintDevice->height()); pageSize.setHeight(paintDevice->height());
pageSize.setWidth(paintDevice->width()); pageSize.setWidth(paintDevice->width());
#ifdef USE_WEBENGINE
//FIXME
#else
webView->page()->setViewportSize(pageSize); webView->page()->setViewportSize(pageSize);
#endif
// initialize the border settings // initialize the border settings
templateOptions->border_width = std::max(1, pageSize.width() / 1000); templateOptions->border_width = std::max(1, pageSize.width() / 1000);
if (printOptions->type == print_options::DIVELIST) { if (printOptions->type == print_options::DIVELIST) {
@ -258,7 +290,10 @@ void Printer::previewOnePage()
} else if (printOptions->type == print_options::STATISTICS ) { } else if (printOptions->type == print_options::STATISTICS ) {
webView->setHtml(t.generateStatistics()); webView->setHtml(t.generateStatistics());
} }
#ifdef USE_WEBENGINE
// FIX ME
render(1);
#else
bool ok; bool ok;
int divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); int divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok);
if (!ok) { if (!ok) {
@ -270,5 +305,6 @@ void Printer::previewOnePage()
} else { } else {
render(1); render(1);
} }
#endif
} }
} }

View file

@ -2,7 +2,11 @@
#define PRINTER_H #define PRINTER_H
#include <QPrinter> #include <QPrinter>
#ifdef USE_WEBENGINE
#include <QWebEngineView>
#else
#include <QWebView> #include <QWebView>
#endif
#include <QRect> #include <QRect>
#include <QPainter> #include <QPainter>
@ -20,7 +24,11 @@ public:
private: private:
QPaintDevice *paintDevice; QPaintDevice *paintDevice;
#ifdef USE_WEBENGINE
QWebEngineView *webView;
#else
QWebView *webView; QWebView *webView;
#endif
print_options *printOptions; print_options *printOptions;
template_options *templateOptions; template_options *templateOptions;
QSize pageSize; QSize pageSize;

View file

@ -34,6 +34,27 @@ void SearchBar::enableButtons(const QString &s)
ui.findNext->setEnabled(s.length()); ui.findNext->setEnabled(s.length());
} }
#ifdef USE_WEBENGINE
MyQWebEnginePage::MyQWebEnginePage(QObject* parent) : QWebEnginePage(parent)
{
}
bool MyQWebEnginePage::acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool)
{
if (type == QWebEnginePage::NavigationTypeLinkClicked)
{
QDesktopServices::openUrl(url);
return false;
}
return true;
}
MyQWebEngineView::MyQWebEngineView(QWidget* parent)
{
}
#endif
UserManual::UserManual(QWidget *parent) : QWidget(parent) UserManual::UserManual(QWidget *parent) : QWidget(parent)
{ {
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
@ -54,12 +75,20 @@ UserManual::UserManual(QWidget *parent) : QWidget(parent)
setWindowTitle(tr("User manual")); setWindowTitle(tr("User manual"));
setWindowIcon(QIcon(":/subsurface-icon")); setWindowIcon(QIcon(":/subsurface-icon"));
#ifdef USE_WEBENGINE
userManual = new MyQWebEngineView(this);
MyQWebEnginePage *page = new MyQWebEnginePage();
userManual->setPage(page);
#else
userManual = new QWebView(this); userManual = new QWebView(this);
#endif
QString colorBack = palette().highlight().color().name(QColor::HexRgb); QString colorBack = palette().highlight().color().name(QColor::HexRgb);
QString colorText = palette().highlightedText().color().name(QColor::HexRgb); QString colorText = palette().highlightedText().color().name(QColor::HexRgb);
userManual->setStyleSheet(QString("QWebView { selection-background-color: %1; selection-color: %2; }") userManual->setStyleSheet(QString("QWebView { selection-background-color: %1; selection-color: %2; }")
.arg(colorBack).arg(colorText)); .arg(colorBack).arg(colorText));
#ifndef USE_WEBENGINE
userManual->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); userManual->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
#endif
QString searchPath = getSubsurfaceDataPath("Documentation"); QString searchPath = getSubsurfaceDataPath("Documentation");
if (searchPath.size()) { if (searchPath.size()) {
// look for localized versions of the manual first // look for localized versions of the manual first
@ -84,7 +113,9 @@ UserManual::UserManual(QWidget *parent) : QWidget(parent)
searchBar->hide(); searchBar->hide();
connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show())); connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show()));
connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide())); connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide()));
#ifndef USE_WEBENGINE
connect(userManual, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl))); connect(userManual, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl)));
#endif
connect(searchBar, SIGNAL(searchTextChanged(QString)), this, SLOT(searchTextChanged(QString))); connect(searchBar, SIGNAL(searchTextChanged(QString)), this, SLOT(searchTextChanged(QString)));
connect(searchBar, SIGNAL(searchNext()), this, SLOT(searchNext())); connect(searchBar, SIGNAL(searchNext()), this, SLOT(searchNext()));
connect(searchBar, SIGNAL(searchPrev()), this, SLOT(searchPrev())); connect(searchBar, SIGNAL(searchPrev()), this, SLOT(searchPrev()));
@ -96,6 +127,13 @@ UserManual::UserManual(QWidget *parent) : QWidget(parent)
setLayout(vboxLayout); setLayout(vboxLayout);
} }
#ifdef USE_WEBENGINE
void UserManual::search(QString text, QWebEnginePage::FindFlags flags = 0)
{
userManual->findText(text, flags,
[this, text](bool found) {searchBar->setStyleSheet(found || text.length() == 0 ? "" : "QLineEdit{background: red;}");});
}
#else
void UserManual::search(QString text, QWebPage::FindFlags flags = 0) void UserManual::search(QString text, QWebPage::FindFlags flags = 0)
{ {
if (userManual->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) { if (userManual->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) {
@ -104,6 +142,7 @@ void UserManual::search(QString text, QWebPage::FindFlags flags = 0)
searchBar->setStyleSheet("QLineEdit{background: red;}"); searchBar->setStyleSheet("QLineEdit{background: red;}");
} }
} }
#endif
void UserManual::searchTextChanged(const QString& text) void UserManual::searchTextChanged(const QString& text)
{ {
@ -118,13 +157,19 @@ void UserManual::searchNext()
void UserManual::searchPrev() void UserManual::searchPrev()
{ {
#ifdef USE_WEBENGINE
search(mLastText, QWebEnginePage::FindBackward);
#else
search(mLastText, QWebPage::FindBackward); search(mLastText, QWebPage::FindBackward);
#endif
} }
#ifndef USE_WEBENGINE
void UserManual::linkClickedSlot(const QUrl& url) void UserManual::linkClickedSlot(const QUrl& url)
{ {
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }
#endif
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
void UserManual::showEvent(QShowEvent *e) { void UserManual::showEvent(QShowEvent *e) {

View file

@ -1,8 +1,12 @@
#ifndef USERMANUAL_H #ifndef USERMANUAL_H
#define USERMANUAL_H #define USERMANUAL_H
#ifdef USE_WEBENGINE
#include <QWebEngineView>
#include <QWebEnginePage>
#else
#include <QWebView> #include <QWebView>
#endif
#include "ui_searchbar.h" #include "ui_searchbar.h"
class SearchBar : public QWidget{ class SearchBar : public QWidget{
@ -21,6 +25,27 @@ private:
Ui::SearchBar ui; Ui::SearchBar ui;
}; };
#ifdef USE_WEBENGINE
class MyQWebEnginePage : public QWebEnginePage
{
Q_OBJECT
public:
MyQWebEnginePage(QObject* parent = 0);
bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool);
};
class MyQWebEngineView : public QWebEngineView
{
Q_OBJECT
public:
MyQWebEngineView(QWidget* parent = 0);
MyQWebEnginePage* page() const;
};
#endif
class UserManual : public QWidget { class UserManual : public QWidget {
Q_OBJECT Q_OBJECT
@ -40,11 +65,18 @@ slots:
void searchTextChanged(const QString& s); void searchTextChanged(const QString& s);
void searchNext(); void searchNext();
void searchPrev(); void searchPrev();
#ifndef USE_WEBENGINE
void linkClickedSlot(const QUrl& url); void linkClickedSlot(const QUrl& url);
#endif
private: private:
QWebView *userManual;
SearchBar *searchBar; SearchBar *searchBar;
QString mLastText; QString mLastText;
#ifdef USE_WEBENGINE
QWebEngineView *userManual;
void search(QString, QWebEnginePage::FindFlags);
#else
QWebView *userManual;
void search(QString, QWebPage::FindFlags); void search(QString, QWebPage::FindFlags);
#endif
}; };
#endif // USERMANUAL_H #endif // USERMANUAL_H