mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Merge pull request #456 from kiwix/open-external-link-from-menu
add "open link in web browser" action in context menu
This commit is contained in:
commit
13339b4772
@ -110,5 +110,6 @@
|
||||
"details":"Full article",
|
||||
"yes":"yes",
|
||||
"no":"no",
|
||||
"no-filter":"no filter"
|
||||
"no-filter":"no filter",
|
||||
"open-link-in-web-browser":"Open link in web browser"
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "webview.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <iostream>
|
||||
#include "kiwixapp.h"
|
||||
@ -71,6 +72,29 @@ void WebView::wheelEvent(QWheelEvent *event) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WebView::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
auto menu = this->page()->createStandardContextMenu();
|
||||
pageAction(QWebEnginePage::OpenLinkInNewWindow)->setVisible(false);
|
||||
if (!m_linkHovered.isEmpty()) {
|
||||
if (!m_linkHovered.startsWith("zim://")) {
|
||||
pageAction(QWebEnginePage::OpenLinkInNewTab)->setVisible(false);
|
||||
auto openLinkInWebBrowserAction = new QAction(gt("open-link-in-web-browser"));
|
||||
menu->insertAction(pageAction(QWebEnginePage::DownloadLinkToDisk) , openLinkInWebBrowserAction);
|
||||
connect(menu, &QObject::destroyed, openLinkInWebBrowserAction, &QObject::deleteLater);
|
||||
connect(openLinkInWebBrowserAction, &QAction::triggered, this, [=](bool checked) {
|
||||
Q_UNUSED(checked);
|
||||
QDesktopServices::openUrl(m_linkHovered);
|
||||
});
|
||||
} else {
|
||||
pageAction(QWebEnginePage::OpenLinkInNewTab)->setVisible(true);
|
||||
}
|
||||
}
|
||||
menu->exec(event->globalPos());
|
||||
}
|
||||
|
||||
|
||||
bool WebView::eventFilter(QObject *src, QEvent *e)
|
||||
{
|
||||
Q_UNUSED(src)
|
||||
|
@ -34,6 +34,7 @@ protected:
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
bool event(QEvent *event);
|
||||
bool eventFilter(QObject *src, QEvent *e);
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
QString m_currentZimId;
|
||||
QIcon m_icon;
|
||||
|
Loading…
x
Reference in New Issue
Block a user