mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
fix:single click on link,the emulated db click will still work on new page
This commit is contained in:
parent
9a4b119976
commit
850c7d66e8
|
@ -1119,6 +1119,10 @@ void ArticleView::linkClicked( QUrl const & url_ )
|
|||
openLink( url, ui.definition->url(), getCurrentArticle(), contexts );
|
||||
}
|
||||
|
||||
void ArticleView::linkClickedInHtml( QUrl const & url_ )
|
||||
{
|
||||
emit ui.definition->linkClickedInHtml(url_);
|
||||
}
|
||||
void ArticleView::openLink( QUrl const & url, QUrl const & ref,
|
||||
QString const & scrollTo,
|
||||
Contexts const & contexts_ )
|
||||
|
|
|
@ -285,7 +285,10 @@ public slots:
|
|||
|
||||
/// Selects an entire text of the current article
|
||||
void selectCurrentArticle();
|
||||
//receive signal from weburlinterceptor.
|
||||
void linkClicked( QUrl const & );
|
||||
//aim to receive signal from html. the fragment url click to navigation through page wil not be intecepted by weburlinteceptor
|
||||
Q_INVOKABLE void linkClickedInHtml( QUrl const & );
|
||||
private slots:
|
||||
|
||||
void loadFinished( bool ok );
|
||||
|
|
|
@ -38,27 +38,37 @@ bool ArticleWebView::event( QEvent * event )
|
|||
if (event->type() == QEvent::ChildAdded) {
|
||||
QChildEvent *child_ev = static_cast<QChildEvent *>(event);
|
||||
|
||||
//should restrict the child event type?
|
||||
// // there is also QObject child that should be ignored here;
|
||||
// // use only QOpenGLWidget child
|
||||
// QOpenGLWidget *w = static_cast<QOpenGLWidget*>(child_ev->child());
|
||||
|
||||
child_ev->child()->installEventFilter(this);
|
||||
}
|
||||
|
||||
return QWebEngineView::event(event);
|
||||
}
|
||||
|
||||
bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev) {
|
||||
void ArticleWebView::linkClickedInHtml(QUrl const& ){
|
||||
//disable single click to simulate dbclick action on the new loaded pages.
|
||||
singleClickToDbClick=false;
|
||||
}
|
||||
|
||||
bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev) {
|
||||
if (ev->type() == QEvent::MouseButtonDblClick) {
|
||||
singleClicked = false;
|
||||
dbClicked = true;
|
||||
QMouseEvent *pe = static_cast<QMouseEvent *>(ev);
|
||||
if (Qt::MouseEventSynthesizedByApplication != pe->source()) {
|
||||
singleClickToDbClick = false;
|
||||
dbClicked = true;
|
||||
}
|
||||
}
|
||||
if (ev->type()==QEvent::MouseMove) {
|
||||
singleClicked=false;
|
||||
singleClickToDbClick=false;
|
||||
}
|
||||
if (ev->type() == QEvent::MouseButtonPress) {
|
||||
QMouseEvent *pe = static_cast<QMouseEvent *>(ev);
|
||||
if(pe->button() == Qt::LeftButton)
|
||||
{
|
||||
singleClicked = true;
|
||||
singleClickToDbClick = true;
|
||||
dbClicked = false;
|
||||
QTimer::singleShot(QApplication::doubleClickInterval(),this,[=](){
|
||||
singleClickAction(pe);
|
||||
|
@ -92,9 +102,9 @@ void ArticleWebView::mousePressEvent(QMouseEvent *event)
|
|||
midButtonPressed = true;
|
||||
}
|
||||
|
||||
void ArticleWebView::singleClickAction(QMouseEvent * event )
|
||||
void ArticleWebView::singleClickAction(QMouseEvent *event )
|
||||
{
|
||||
if(!singleClicked)
|
||||
if(!singleClickToDbClick)
|
||||
return;
|
||||
|
||||
if (selectionBySingleClick) {
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QWebEngineView>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QPointer>
|
||||
|
||||
/// A thin wrapper around QWebEngineView to accommodate to some ArticleView's needs.
|
||||
/// Currently the only added features:
|
||||
|
@ -45,9 +47,6 @@ public:
|
|||
/// word, which gets selected by the view in response to double-click.
|
||||
void doubleClicked( QPoint pos );
|
||||
|
||||
//the linkClicked signal was removed from webengineview. add the signal to simulate.
|
||||
void linkClicked(QUrl const& url);
|
||||
|
||||
protected:
|
||||
|
||||
bool event( QEvent * event );
|
||||
|
@ -63,6 +62,7 @@ protected:
|
|||
private:
|
||||
|
||||
Config::Class * cfg;
|
||||
//QPointer<QOpenGLWidget> child_;
|
||||
|
||||
bool midButtonPressed;
|
||||
bool selectionBySingleClick;
|
||||
|
@ -70,8 +70,13 @@ private:
|
|||
|
||||
//MouseDbClickEvent will also emit MousePressEvent which conflict the single click event.
|
||||
//this variable used to distinguish the single click and real double click.
|
||||
bool singleClicked;
|
||||
bool singleClickToDbClick;
|
||||
bool dbClicked;
|
||||
|
||||
public slots:
|
||||
|
||||
//receive signal ,a link has been clicked.
|
||||
void linkClickedInHtml(QUrl const& url);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
$(function() {
|
||||
$("a").click(function(event) {
|
||||
var link = $(this).attr("href");
|
||||
emitClickedEvent(link);
|
||||
if(link.indexOf(":")>=0){
|
||||
return;
|
||||
}
|
||||
|
@ -41,3 +42,13 @@ function playSound(sound) {
|
|||
var a = new Audio(sound);
|
||||
a.play();
|
||||
}
|
||||
|
||||
function emitClickedEvent(link){
|
||||
try{
|
||||
articleview.linkClickedInHtml(link);
|
||||
}catch(error)
|
||||
{
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ WebUrlRequestInterceptor::WebUrlRequestInterceptor(QObject *p)
|
|||
void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info) {
|
||||
if (QWebEngineUrlRequestInfo::NavigationTypeLink == info.navigationType() && info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) {
|
||||
emit linkClicked(info.requestUrl());
|
||||
|
||||
info.block(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue