mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
bword link in Hunspell dictionary.
This commit is contained in:
parent
5333b79222
commit
cb5ac438fe
|
@ -4,7 +4,7 @@
|
|||
#include "articleview.hh"
|
||||
#include <map>
|
||||
#include <QMessageBox>
|
||||
//#include <QWebHitTestResult>
|
||||
#include "weburlrequestinterceptor.h"
|
||||
#include <QMenu>
|
||||
#include <QDesktopServices>
|
||||
#include <QWebEngineHistory>
|
||||
|
@ -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) ) );
|
||||
|
|
|
@ -52,8 +52,11 @@ bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev)
|
|||
firstClicked=false;
|
||||
}
|
||||
if (ev->type() == QEvent::MouseButtonPress) {
|
||||
firstClicked=true;
|
||||
QMouseEvent *pe = static_cast<QMouseEvent *>(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 );
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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 \
|
||||
|
|
2
main.cc
2
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)
|
||||
{
|
||||
|
|
|
@ -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;i<localSchemes.size();i++){
|
||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(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 );
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "helpwindow.hh"
|
||||
|
||||
#include "hotkeywrapper.hh"
|
||||
#include "weburlrequestinterceptor.h"
|
||||
#ifdef HAVE_X11
|
||||
#include <fixx11h.h>
|
||||
#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
|
||||
|
|
13
weburlrequestinterceptor.cpp
Normal file
13
weburlrequestinterceptor.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "weburlrequestinterceptor.h"
|
||||
#include <QDebug>
|
||||
|
||||
WebUrlRequestInterceptor::WebUrlRequestInterceptor(QObject *p)
|
||||
:QWebEngineUrlRequestInterceptor(p)
|
||||
{
|
||||
|
||||
}
|
||||
void WebUrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) {
|
||||
if(QWebEngineUrlRequestInfo::NavigationTypeLink==info.navigationType ()&&info.resourceType ()==QWebEngineUrlRequestInfo::ResourceTypeMainFrame)
|
||||
emit linkClicked(info.requestUrl ());
|
||||
|
||||
}
|
17
weburlrequestinterceptor.h
Normal file
17
weburlrequestinterceptor.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef WEBURLREQUESTINTERCEPTOR_H
|
||||
#define WEBURLREQUESTINTERCEPTOR_H
|
||||
|
||||
#include <QWebEngineUrlRequestInterceptor>
|
||||
|
||||
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
|
Loading…
Reference in a new issue