-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebView: Port to Qt WebEngine (fixes Windows build)
For displaying web pages, qolibri was using the Qt WebKit library, which was removed years ago with Qt 5.6. These days it's pretty much only still available on GNU/Linux and the BSDs, where distros maintain it to keep old apps working for now. This change ports to Qt WebKit's Chromium-based successor Qt WebEngine. Among other things, this fixes Windows builds (only tested with official prebuilt Qt 5.11.2 on Windows 10 x64 with VS2017 compiler).
- Loading branch information
Showing
6 changed files
with
142 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "webpage.h" | ||
|
||
#include <QMenu> | ||
#include <QWebEngineContextMenuData> | ||
#include <QWebEngineHistory> | ||
|
||
WebPage::WebPage(QObject* parent) | ||
: QWebEnginePage(parent) | ||
, delegateLinks(false) | ||
{ | ||
} | ||
|
||
bool WebPage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) | ||
{ | ||
Q_UNUSED(isMainFrame); | ||
if (type == NavigationTypeLinkClicked && delegateLinks) { | ||
emit linkClicked(url); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
// Stripped-down version of QWebEnginePage::createStandardContextMenu to | ||
// have consistent menus across platforms and Qt versions and to only | ||
// offer options that are actually supported | ||
QMenu *WebPage::createContextMenu() const | ||
{ | ||
const QWebEngineContextMenuData &cmdata = contextMenuData(); | ||
if (!cmdata.isValid()) | ||
return 0; | ||
|
||
QWidget *const view = this->view(); | ||
QMenu *const menu = new QMenu(view); | ||
|
||
if (cmdata.selectedText().isEmpty()) { | ||
QAction *action = new QAction(QIcon::fromTheme(QStringLiteral("go-previous")), tr("&Back"), menu); | ||
connect(action, SIGNAL(triggered()), view, SLOT(back())); | ||
action->setEnabled(history()->canGoBack()); | ||
menu->addAction(action); | ||
|
||
action = new QAction(QIcon::fromTheme(QStringLiteral("go-next")), tr("&Forward"), menu); | ||
connect(action, SIGNAL(triggered()), view, SLOT(forward())); | ||
action->setEnabled(history()->canGoForward()); | ||
menu->addAction(action); | ||
|
||
action = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), tr("&Reload"), menu); | ||
connect(action, SIGNAL(triggered()), view, SLOT(reload())); | ||
menu->addAction(action); | ||
} else { | ||
menu->addAction(action(Copy)); | ||
menu->addAction(action(Unselect)); | ||
} | ||
|
||
if (!cmdata.linkText().isEmpty()) { | ||
menu->addAction(action(OpenLinkInNewWindow)); | ||
menu->addAction(action(CopyLinkToClipboard)); | ||
} | ||
|
||
if (cmdata.mediaUrl().isValid()) { | ||
switch (cmdata.mediaType()) { | ||
case QWebEngineContextMenuData::MediaTypeImage: | ||
menu->addAction(action(CopyImageUrlToClipboard)); | ||
menu->addAction(action(CopyImageToClipboard)); | ||
break; | ||
case QWebEngineContextMenuData::MediaTypeAudio: | ||
case QWebEngineContextMenuData::MediaTypeVideo: | ||
menu->addAction(action(CopyMediaUrlToClipboard)); | ||
menu->addAction(action(ToggleMediaPlayPause)); | ||
menu->addAction(action(ToggleMediaLoop)); | ||
menu->addAction(action(ToggleMediaMute)); | ||
break; | ||
default: | ||
break; | ||
} | ||
} else if (cmdata.mediaType() == QWebEngineContextMenuData::MediaTypeCanvas) { | ||
menu->addAction(action(CopyImageToClipboard)); | ||
} | ||
|
||
menu->setAttribute(Qt::WA_DeleteOnClose, true); | ||
return menu; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef WEBPAGE_H | ||
#define WEBPAGE_H | ||
|
||
#include <QWebEnginePage> | ||
|
||
class WebPage : public QWebEnginePage | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit WebPage(QObject* parent = 0); | ||
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame); | ||
QMenu *createContextMenu() const; | ||
void setDelegateLinks(bool enable) { delegateLinks = enable; } | ||
signals: | ||
void linkClicked(const QUrl &url); | ||
private: | ||
bool delegateLinks; | ||
}; | ||
|
||
#endif // WEBPAGE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters