mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
Ctrl + Click and middle click on external link don't open a new empty tab
Connect the &QWebEnginePage::linkHovered signal to set the m_linkHovered member. The Ctrl + Click and middle click events are intercepted to directly open the m_linkHovered variable if it's an external link
This commit is contained in:
parent
df9db1317a
commit
285417a2d8
@ -1,5 +1,6 @@
|
||||
#include "webview.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QAction>
|
||||
#include <iostream>
|
||||
#include "kiwixapp.h"
|
||||
@ -12,6 +13,9 @@ WebView::WebView(QWidget *parent)
|
||||
{
|
||||
setPage(new WebPage(this));
|
||||
QObject::connect(this, &QWebEngineView::urlChanged, this, &WebView::onUrlChanged);
|
||||
connect(this->page(), &QWebEnginePage::linkHovered, this, [=] (const QString& url) {
|
||||
m_linkHovered = url;
|
||||
});
|
||||
}
|
||||
|
||||
WebView::~WebView()
|
||||
@ -75,6 +79,15 @@ bool WebView::eventFilter(QObject *src, QEvent *e)
|
||||
if (we->modifiers() == Qt::ControlModifier)
|
||||
return true;
|
||||
}
|
||||
if (e->type() == QEvent::MouseButtonRelease) {
|
||||
auto me = static_cast<QMouseEvent *>(e);
|
||||
if (!m_linkHovered.startsWith("zim://")
|
||||
&& (me->modifiers() == Qt::ControlModifier || me->button() == Qt::MiddleButton))
|
||||
{
|
||||
QDesktopServices::openUrl(m_linkHovered);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ protected:
|
||||
|
||||
QString m_currentZimId;
|
||||
QIcon m_icon;
|
||||
QString m_linkHovered;
|
||||
};
|
||||
|
||||
#endif // WEBVIEW_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user