diff options
author | Robert C. Helling <helling@atdotde.de> | 2016-08-09 00:12:12 +0200 |
---|---|---|
committer | Robert C. Helling <helling@atdotde.de> | 2016-12-30 19:43:00 +0100 |
commit | 529a4d499b8dad35de6cd43e3004017ccfd288aa (patch) | |
tree | fb0f163c32c029134a849ac49183849870b3c0ae /desktop-widgets/usermanual.cpp | |
parent | 10b8bda6626fe1de602e38da34de419972031755 (diff) | |
download | subsurface-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/usermanual.cpp')
-rw-r--r-- | desktop-widgets/usermanual.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/desktop-widgets/usermanual.cpp b/desktop-widgets/usermanual.cpp index 690307961..8e75b432f 100644 --- a/desktop-widgets/usermanual.cpp +++ b/desktop-widgets/usermanual.cpp @@ -34,6 +34,27 @@ void SearchBar::enableButtons(const QString &s) 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) { 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")); setWindowIcon(QIcon(":/subsurface-icon")); +#ifdef USE_WEBENGINE + userManual = new MyQWebEngineView(this); + MyQWebEnginePage *page = new MyQWebEnginePage(); + userManual->setPage(page); +#else userManual = new QWebView(this); +#endif QString colorBack = palette().highlight().color().name(QColor::HexRgb); QString colorText = palette().highlightedText().color().name(QColor::HexRgb); userManual->setStyleSheet(QString("QWebView { selection-background-color: %1; selection-color: %2; }") .arg(colorBack).arg(colorText)); +#ifndef USE_WEBENGINE userManual->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); +#endif QString searchPath = getSubsurfaceDataPath("Documentation"); if (searchPath.size()) { // look for localized versions of the manual first @@ -84,7 +113,9 @@ UserManual::UserManual(QWidget *parent) : QWidget(parent) searchBar->hide(); connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show())); connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide())); +#ifndef USE_WEBENGINE connect(userManual, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl))); +#endif connect(searchBar, SIGNAL(searchTextChanged(QString)), this, SLOT(searchTextChanged(QString))); connect(searchBar, SIGNAL(searchNext()), this, SLOT(searchNext())); connect(searchBar, SIGNAL(searchPrev()), this, SLOT(searchPrev())); @@ -96,6 +127,13 @@ UserManual::UserManual(QWidget *parent) : QWidget(parent) 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) { 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;}"); } } +#endif void UserManual::searchTextChanged(const QString& text) { @@ -118,13 +157,19 @@ void UserManual::searchNext() void UserManual::searchPrev() { +#ifdef USE_WEBENGINE + search(mLastText, QWebEnginePage::FindBackward); +#else search(mLastText, QWebPage::FindBackward); +#endif } +#ifndef USE_WEBENGINE void UserManual::linkClickedSlot(const QUrl& url) { QDesktopServices::openUrl(url); } +#endif #ifdef Q_OS_MAC void UserManual::showEvent(QShowEvent *e) { |