diff --git a/articleview.cc b/articleview.cc index cc437500..a7e7c8e3 100644 --- a/articleview.cc +++ b/articleview.cc @@ -1115,6 +1115,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_ ) diff --git a/articleview.hh b/articleview.hh index 169ea01f..a0f0dd74 100644 --- a/articleview.hh +++ b/articleview.hh @@ -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 ); diff --git a/articlewebview.cc b/articlewebview.cc index 1219edd1..126f2890 100644 --- a/articlewebview.cc +++ b/articlewebview.cc @@ -38,27 +38,37 @@ bool ArticleWebView::event( QEvent * event ) if (event->type() == QEvent::ChildAdded) { QChildEvent *child_ev = static_cast(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(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(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(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) { diff --git a/articlewebview.hh b/articlewebview.hh index aaca0045..18ddd8f7 100644 --- a/articlewebview.hh +++ b/articlewebview.hh @@ -8,6 +8,8 @@ #include #include #include +#include +#include /// 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 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 diff --git a/resources/gd_custom.js b/resources/gd_custom.js index 18ba1c68..bc42ea5c 100644 --- a/resources/gd_custom.js +++ b/resources/gd_custom.js @@ -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); + } + +} diff --git a/weburlrequestinterceptor.cpp b/weburlrequestinterceptor.cpp index d0af0b5b..42b6d538 100644 --- a/weburlrequestinterceptor.cpp +++ b/weburlrequestinterceptor.cpp @@ -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); } }