diff --git a/articleview.cc b/articleview.cc index 4efbf78d..b8a64aeb 100644 --- a/articleview.cc +++ b/articleview.cc @@ -4,7 +4,7 @@ #include "articleview.hh" #include #include -//#include +#include "weburlrequestinterceptor.h" #include #include #include @@ -279,8 +279,11 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, ui.definition->setContextMenuPolicy( Qt::CustomContextMenu ); - //todo acceptNavigationRequest - //ui.definition->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); + //use acceptNavigationRequest method to simulate the linkclick signal + //connect( ui.definition, SIGNAL( linkClicked(QUrl) ),this,SLOT( linkClicked(QUrl ) ) ); +// WebUrlRequestInterceptor *wuri = new WebUrlRequestInterceptor(); +// ui.definition->page ()->profile ()->setUrlRequestInterceptor(wuri); +// connect( wuri, SIGNAL( linkClicked(QUrl) ),this,SLOT( linkClicked(QUrl ) ) ); connect( ui.definition, SIGNAL( loadFinished(bool) ), this, SLOT( loadFinished(bool) ) ); diff --git a/articlewebview.cc b/articlewebview.cc index 3848494e..49745506 100644 --- a/articlewebview.cc +++ b/articlewebview.cc @@ -52,8 +52,11 @@ bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev) firstClicked=false; } if (ev->type() == QEvent::MouseButtonPress) { - firstClicked=true; QMouseEvent *pe = static_cast(ev); + if(pe->buttons() & Qt::LeftButton) + { + firstClicked=true; + } mousePressEvent(pe); } if (ev->type() == QEvent::MouseButtonRelease) { @@ -94,7 +97,7 @@ void ArticleWebView::singleClickAction( QMouseEvent * event ) if(!firstClicked) return; - if (selectionBySingleClick && (event->buttons() & Qt::LeftButton)) { + if (selectionBySingleClick) { // findText(""); // clear the selection first, if any page()->runJavaScript(QString( " var s = window.getSelection(); " @@ -109,12 +112,14 @@ void ArticleWebView::singleClickAction( QMouseEvent * event ) " range.setEnd(node, range.endOffset+1); " " } " " while (range.toString().indexOf(' ') == -1 && range.toString().trim() != ''); " + " range.setEnd(node,range.endOffset-1);" " var str = range.toString().trim(); " " console.log(str);" " }")); } } + void ArticleWebView::mouseReleaseEvent( QMouseEvent * event ) { bool noMidButton = !( event->buttons() & Qt::MidButton ); diff --git a/articlewebview.hh b/articlewebview.hh index 84ae8a99..7099e463 100644 --- a/articlewebview.hh +++ b/articlewebview.hh @@ -45,6 +45,9 @@ 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 ); @@ -55,6 +58,7 @@ protected: void focusInEvent( QFocusEvent * event ); void wheelEvent( QWheelEvent * event ); + private: Config::Class * cfg; @@ -63,6 +67,8 @@ private: bool selectionBySingleClick; bool showInspectorDirectly; + //MouseDbClickEvent will also emit MousePressEvent which conflict the single click event. + //this variable used to distinguish the single click and real double click. bool firstClicked; }; diff --git a/goldendict.pro b/goldendict.pro index 20cbfc94..7658b265 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -269,6 +269,7 @@ HEADERS += folding.hh \ btreeidx.hh \ stardict.hh \ chunkedstorage.hh \ + weburlrequestinterceptor.h \ xdxf2html.hh \ iconv.hh \ lsa.hh \ @@ -405,6 +406,7 @@ SOURCES += folding.cc \ btreeidx.cc \ stardict.cc \ chunkedstorage.cc \ + weburlrequestinterceptor.cpp \ xdxf2html.cc \ iconv.cc \ lsa.cc \ diff --git a/main.cc b/main.cc index 2255c7ab..765a7561 100644 --- a/main.cc +++ b/main.cc @@ -264,7 +264,7 @@ int main( int argc, char ** argv ) #endif - QStringList localSchemes={"gdlookup","gdau","gico","qrcx","bres"}; + QStringList localSchemes={"gdlookup","gdau","gico","qrcx","bres","bword"}; for (int i = 0; i < localSchemes.size(); ++i) { diff --git a/mainwindow.cc b/mainwindow.cc index 82b46748..91b99ea0 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -148,12 +148,17 @@ MainWindow::MainWindow( Config::Class & cfg_ ): LocalSchemeHandler *handler = new LocalSchemeHandler(articleNetMgr); QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", handler); + QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("bword", handler); QStringList localSchemes={"gdau","gico","qrcx","bres"}; + GicoSchemeHandler *h=new GicoSchemeHandler(articleNetMgr); for(int i=0;iinstallUrlSchemeHandler(localSchemes.at(i).toLatin1(), new GicoSchemeHandler(articleNetMgr)); + QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(localSchemes.at(i).toLatin1(), h); } + wuri = new WebUrlRequestInterceptor(); + QWebEngineProfile::defaultProfile()->setUrlRequestInterceptor(wuri); + qRegisterMetaType< Config::InputPhrase >(); #ifndef NO_EPWING_SUPPORT @@ -1669,6 +1674,7 @@ ArticleView * MainWindow::createNewTab( bool switchToIt, connect( view, SIGNAL( zoomIn()), this, SLOT( zoomin() ) ); connect( view, SIGNAL( zoomOut()), this, SLOT( zoomout() ) ); + connect (wuri,SIGNAL(linkClicked(QUrl)),view,SLOT(linkClicked(QUrl))); view->setSelectionBySingleClick( cfg.preferences.selectWordBySingleClick ); diff --git a/mainwindow.hh b/mainwindow.hh index 87cd959d..36392790 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -32,6 +32,7 @@ #include "helpwindow.hh" #include "hotkeywrapper.hh" +#include "weburlrequestinterceptor.h" #ifdef HAVE_X11 #include #endif @@ -99,6 +100,8 @@ private: QSystemTrayIcon * trayIcon; + WebUrlRequestInterceptor *wuri; + Ui::MainWindow ui; /// This widget is used as a title bar for the searchPane dock, and diff --git a/weburlrequestinterceptor.cpp b/weburlrequestinterceptor.cpp new file mode 100644 index 00000000..6afec740 --- /dev/null +++ b/weburlrequestinterceptor.cpp @@ -0,0 +1,13 @@ +#include "weburlrequestinterceptor.h" +#include + +WebUrlRequestInterceptor::WebUrlRequestInterceptor(QObject *p) + :QWebEngineUrlRequestInterceptor(p) +{ + +} +void WebUrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) { + if(QWebEngineUrlRequestInfo::NavigationTypeLink==info.navigationType ()&&info.resourceType ()==QWebEngineUrlRequestInfo::ResourceTypeMainFrame) + emit linkClicked(info.requestUrl ()); + +} diff --git a/weburlrequestinterceptor.h b/weburlrequestinterceptor.h new file mode 100644 index 00000000..e3fdf63e --- /dev/null +++ b/weburlrequestinterceptor.h @@ -0,0 +1,17 @@ +#ifndef WEBURLREQUESTINTERCEPTOR_H +#define WEBURLREQUESTINTERCEPTOR_H + +#include + +class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor +{ + Q_OBJECT +public: + WebUrlRequestInterceptor(QObject *p = Q_NULLPTR); + void interceptRequest(QWebEngineUrlRequestInfo &info); +signals: + void linkClicked(const QUrl& url) ; + +}; + +#endif // WEBURLREQUESTINTERCEPTOR_H