mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
10b8bda662
commit
529a4d499b
8 changed files with 159 additions and 7 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue