mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
opt:use acceptNavigationRequest instead of weburlinterceptor
This commit is contained in:
parent
459b684e5b
commit
a7ba9e4b36
|
@ -262,6 +262,7 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au
|
|||
|
||||
connect(ui.definition, SIGNAL(loadProgress(int)), this,
|
||||
SLOT(loadProgress(int)));
|
||||
connect( ui.definition, SIGNAL( linkClicked( QUrl ) ), this, SLOT( linkClicked( QUrl ) ) );
|
||||
|
||||
connect( ui.definition->page(), SIGNAL( titleChanged( QString ) ),
|
||||
this, SLOT( handleTitleChanged( QString ) ) );
|
||||
|
|
15
articlewebpage.cpp
Normal file
15
articlewebpage.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "articlewebpage.h"
|
||||
|
||||
ArticleWebPage::ArticleWebPage(QObject *parent)
|
||||
: QWebEnginePage{parent}
|
||||
{
|
||||
}
|
||||
bool ArticleWebPage::acceptNavigationRequest( const QUrl & url, NavigationType type, bool isMainFrame )
|
||||
{
|
||||
if( type == QWebEnginePage::NavigationTypeLinkClicked )
|
||||
{
|
||||
emit linkClicked( url );
|
||||
return true;
|
||||
}
|
||||
return QWebEnginePage::acceptNavigationRequest( url, type, isMainFrame );
|
||||
}
|
17
articlewebpage.h
Normal file
17
articlewebpage.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef ARTICLEWEBPAGE_H
|
||||
#define ARTICLEWEBPAGE_H
|
||||
|
||||
#include <QWebEnginePage>
|
||||
|
||||
class ArticleWebPage : public QWebEnginePage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ArticleWebPage( QObject * parent = nullptr );
|
||||
signals:
|
||||
void linkClicked( const QUrl & url );
|
||||
protected:
|
||||
virtual bool acceptNavigationRequest( const QUrl & url, NavigationType type, bool isMainFrame );
|
||||
};
|
||||
|
||||
#endif // ARTICLEWEBPAGE_H
|
|
@ -1,6 +1,7 @@
|
|||
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#include "articlewebpage.h"
|
||||
#include "articlewebview.hh"
|
||||
#include <QMouseEvent>
|
||||
#include <QWebEngineView>
|
||||
|
@ -18,6 +19,9 @@ ArticleWebView::ArticleWebView( QWidget *parent ):
|
|||
midButtonPressed( false ),
|
||||
selectionBySingleClick( false )
|
||||
{
|
||||
auto page = new ArticleWebPage( this );
|
||||
connect( page, &ArticleWebPage::linkClicked, this, &ArticleWebView::linkClicked );
|
||||
this->setPage( page );
|
||||
}
|
||||
|
||||
ArticleWebView::~ArticleWebView()
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
/// word, which gets selected by the view in response to double-click.
|
||||
void doubleClicked( QPoint pos );
|
||||
|
||||
void linkClicked( const QUrl & url );
|
||||
|
||||
protected:
|
||||
QWebEngineView *createWindow(QWebEnginePage::WebWindowType type);
|
||||
bool event( QEvent * event );
|
||||
|
|
|
@ -225,6 +225,7 @@ DEFINES += PROGRAM_VERSION=\\\"$$VERSION\\\"
|
|||
# Input
|
||||
HEADERS += folding.hh \
|
||||
article_inspect.h \
|
||||
articlewebpage.h \
|
||||
globalbroadcaster.h \
|
||||
iframeschemehandler.h \
|
||||
inc_case_folding.hh \
|
||||
|
@ -365,6 +366,7 @@ FORMS += groups.ui \
|
|||
|
||||
SOURCES += folding.cc \
|
||||
article_inspect.cpp \
|
||||
articlewebpage.cpp \
|
||||
globalbroadcaster.cpp \
|
||||
iframeschemehandler.cpp \
|
||||
main.cc \
|
||||
|
|
|
@ -162,7 +162,6 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
|
||||
wuri = new WebUrlRequestInterceptor();
|
||||
QWebEngineProfile::defaultProfile()->setUrlRequestInterceptor( wuri );
|
||||
connect( wuri, &WebUrlRequestInterceptor::linkClicked, this, &MainWindow::viewLinkClicked );
|
||||
|
||||
if(!cfg.preferences.hideGoldenDictHeader){
|
||||
QWebEngineProfile::defaultProfile()->setHttpUserAgent(QWebEngineProfile::defaultProfile()->httpUserAgent()+" GoldenDict/webengine");
|
||||
|
@ -3600,21 +3599,6 @@ void MainWindow::unzoom()
|
|||
applyZoomFactor();
|
||||
}
|
||||
|
||||
void MainWindow::viewLinkClicked( const QUrl & url )
|
||||
{
|
||||
if( scanPopup.get() && scanPopup->isActiveWindow() )
|
||||
{
|
||||
QString word = Utils::Url::getWordFromUrl( url );
|
||||
if( !word.isEmpty() )
|
||||
{
|
||||
scanPopup->translateWord( word );
|
||||
return;
|
||||
}
|
||||
}
|
||||
ArticleView * view = getCurrentArticleView();
|
||||
view->linkClicked( url );
|
||||
}
|
||||
|
||||
void MainWindow::applyZoomFactor()
|
||||
{
|
||||
// Always call this function synchronously to potentially disable a zoom action,
|
||||
|
|
|
@ -344,8 +344,6 @@ private slots:
|
|||
void zoomout();
|
||||
void unzoom();
|
||||
|
||||
void viewLinkClicked( const QUrl & url );
|
||||
|
||||
void scaleArticlesByCurrentZoomFactor();
|
||||
|
||||
void doWordsZoomIn();
|
||||
|
|
|
@ -39,7 +39,7 @@ void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info)
|
|||
{
|
||||
return;
|
||||
}
|
||||
emit linkClicked( info.requestUrl() );
|
||||
info.block(true);
|
||||
// emit linkClicked( info.requestUrl() );
|
||||
// info.block(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,8 @@ class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
|
|||
public:
|
||||
WebUrlRequestInterceptor(QObject *p = Q_NULLPTR);
|
||||
void interceptRequest(QWebEngineUrlRequestInfo &info);
|
||||
signals:
|
||||
void linkClicked(const QUrl& url) ;
|
||||
|
||||
signals:
|
||||
void linkClicked( const QUrl & url );
|
||||
};
|
||||
|
||||
#endif // WEBURLREQUESTINTERCEPTOR_H
|
||||
|
|
Loading…
Reference in a new issue