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 "articleview.hh"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
//#include <QWebHitTestResult>
|
#include "weburlrequestinterceptor.h"
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QWebEngineHistory>
|
#include <QWebEngineHistory>
|
||||||
|
@ -279,8 +279,11 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
|
||||||
|
|
||||||
ui.definition->setContextMenuPolicy( Qt::CustomContextMenu );
|
ui.definition->setContextMenuPolicy( Qt::CustomContextMenu );
|
||||||
|
|
||||||
//todo acceptNavigationRequest
|
//use acceptNavigationRequest method to simulate the linkclick signal
|
||||||
//ui.definition->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
|
//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) ),
|
connect( ui.definition, SIGNAL( loadFinished(bool) ),
|
||||||
this, SLOT( loadFinished(bool) ) );
|
this, SLOT( loadFinished(bool) ) );
|
||||||
|
|
|
@ -52,8 +52,11 @@ bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev)
|
||||||
firstClicked=false;
|
firstClicked=false;
|
||||||
}
|
}
|
||||||
if (ev->type() == QEvent::MouseButtonPress) {
|
if (ev->type() == QEvent::MouseButtonPress) {
|
||||||
firstClicked=true;
|
|
||||||
QMouseEvent *pe = static_cast<QMouseEvent *>(ev);
|
QMouseEvent *pe = static_cast<QMouseEvent *>(ev);
|
||||||
|
if(pe->buttons() & Qt::LeftButton)
|
||||||
|
{
|
||||||
|
firstClicked=true;
|
||||||
|
}
|
||||||
mousePressEvent(pe);
|
mousePressEvent(pe);
|
||||||
}
|
}
|
||||||
if (ev->type() == QEvent::MouseButtonRelease) {
|
if (ev->type() == QEvent::MouseButtonRelease) {
|
||||||
|
@ -94,7 +97,7 @@ void ArticleWebView::singleClickAction( QMouseEvent * event )
|
||||||
if(!firstClicked)
|
if(!firstClicked)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (selectionBySingleClick && (event->buttons() & Qt::LeftButton)) {
|
if (selectionBySingleClick) {
|
||||||
// findText(""); // clear the selection first, if any
|
// findText(""); // clear the selection first, if any
|
||||||
page()->runJavaScript(QString(
|
page()->runJavaScript(QString(
|
||||||
" var s = window.getSelection(); "
|
" var s = window.getSelection(); "
|
||||||
|
@ -109,12 +112,14 @@ void ArticleWebView::singleClickAction( QMouseEvent * event )
|
||||||
" range.setEnd(node, range.endOffset+1); "
|
" range.setEnd(node, range.endOffset+1); "
|
||||||
" } "
|
" } "
|
||||||
" while (range.toString().indexOf(' ') == -1 && range.toString().trim() != ''); "
|
" while (range.toString().indexOf(' ') == -1 && range.toString().trim() != ''); "
|
||||||
|
" range.setEnd(node,range.endOffset-1);"
|
||||||
" var str = range.toString().trim(); "
|
" var str = range.toString().trim(); "
|
||||||
" console.log(str);"
|
" console.log(str);"
|
||||||
" }"));
|
" }"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ArticleWebView::mouseReleaseEvent( QMouseEvent * event )
|
void ArticleWebView::mouseReleaseEvent( QMouseEvent * event )
|
||||||
{
|
{
|
||||||
bool noMidButton = !( event->buttons() & Qt::MidButton );
|
bool noMidButton = !( event->buttons() & Qt::MidButton );
|
||||||
|
|
|
@ -45,6 +45,9 @@ public:
|
||||||
/// word, which gets selected by the view in response to double-click.
|
/// word, which gets selected by the view in response to double-click.
|
||||||
void doubleClicked( QPoint pos );
|
void doubleClicked( QPoint pos );
|
||||||
|
|
||||||
|
//the linkClicked signal was removed from webengineview. add the signal to simulate.
|
||||||
|
void linkClicked(QUrl const& url);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool event( QEvent * event );
|
bool event( QEvent * event );
|
||||||
|
@ -55,6 +58,7 @@ protected:
|
||||||
void focusInEvent( QFocusEvent * event );
|
void focusInEvent( QFocusEvent * event );
|
||||||
void wheelEvent( QWheelEvent * event );
|
void wheelEvent( QWheelEvent * event );
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Config::Class * cfg;
|
Config::Class * cfg;
|
||||||
|
@ -63,6 +67,8 @@ private:
|
||||||
bool selectionBySingleClick;
|
bool selectionBySingleClick;
|
||||||
bool showInspectorDirectly;
|
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;
|
bool firstClicked;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -269,6 +269,7 @@ HEADERS += folding.hh \
|
||||||
btreeidx.hh \
|
btreeidx.hh \
|
||||||
stardict.hh \
|
stardict.hh \
|
||||||
chunkedstorage.hh \
|
chunkedstorage.hh \
|
||||||
|
weburlrequestinterceptor.h \
|
||||||
xdxf2html.hh \
|
xdxf2html.hh \
|
||||||
iconv.hh \
|
iconv.hh \
|
||||||
lsa.hh \
|
lsa.hh \
|
||||||
|
@ -405,6 +406,7 @@ SOURCES += folding.cc \
|
||||||
btreeidx.cc \
|
btreeidx.cc \
|
||||||
stardict.cc \
|
stardict.cc \
|
||||||
chunkedstorage.cc \
|
chunkedstorage.cc \
|
||||||
|
weburlrequestinterceptor.cpp \
|
||||||
xdxf2html.cc \
|
xdxf2html.cc \
|
||||||
iconv.cc \
|
iconv.cc \
|
||||||
lsa.cc \
|
lsa.cc \
|
||||||
|
|
2
main.cc
2
main.cc
|
@ -264,7 +264,7 @@ int main( int argc, char ** argv )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
QStringList localSchemes={"gdlookup","gdau","gico","qrcx","bres"};
|
QStringList localSchemes={"gdlookup","gdau","gico","qrcx","bres","bword"};
|
||||||
|
|
||||||
for (int i = 0; i < localSchemes.size(); ++i)
|
for (int i = 0; i < localSchemes.size(); ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -148,12 +148,17 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
|
|
||||||
LocalSchemeHandler *handler = new LocalSchemeHandler(articleNetMgr);
|
LocalSchemeHandler *handler = new LocalSchemeHandler(articleNetMgr);
|
||||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", handler);
|
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", handler);
|
||||||
|
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("bword", handler);
|
||||||
|
|
||||||
QStringList localSchemes={"gdau","gico","qrcx","bres"};
|
QStringList localSchemes={"gdau","gico","qrcx","bres"};
|
||||||
|
GicoSchemeHandler *h=new GicoSchemeHandler(articleNetMgr);
|
||||||
for(int i=0;i<localSchemes.size();i++){
|
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 >();
|
qRegisterMetaType< Config::InputPhrase >();
|
||||||
|
|
||||||
#ifndef NO_EPWING_SUPPORT
|
#ifndef NO_EPWING_SUPPORT
|
||||||
|
@ -1669,6 +1674,7 @@ ArticleView * MainWindow::createNewTab( bool switchToIt,
|
||||||
connect( view, SIGNAL( zoomIn()), this, SLOT( zoomin() ) );
|
connect( view, SIGNAL( zoomIn()), this, SLOT( zoomin() ) );
|
||||||
|
|
||||||
connect( view, SIGNAL( zoomOut()), this, SLOT( zoomout() ) );
|
connect( view, SIGNAL( zoomOut()), this, SLOT( zoomout() ) );
|
||||||
|
connect (wuri,SIGNAL(linkClicked(QUrl)),view,SLOT(linkClicked(QUrl)));
|
||||||
|
|
||||||
view->setSelectionBySingleClick( cfg.preferences.selectWordBySingleClick );
|
view->setSelectionBySingleClick( cfg.preferences.selectWordBySingleClick );
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "helpwindow.hh"
|
#include "helpwindow.hh"
|
||||||
|
|
||||||
#include "hotkeywrapper.hh"
|
#include "hotkeywrapper.hh"
|
||||||
|
#include "weburlrequestinterceptor.h"
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
#include <fixx11h.h>
|
#include <fixx11h.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,6 +100,8 @@ private:
|
||||||
|
|
||||||
QSystemTrayIcon * trayIcon;
|
QSystemTrayIcon * trayIcon;
|
||||||
|
|
||||||
|
WebUrlRequestInterceptor *wuri;
|
||||||
|
|
||||||
Ui::MainWindow ui;
|
Ui::MainWindow ui;
|
||||||
|
|
||||||
/// This widget is used as a title bar for the searchPane dock, and
|
/// 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