mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
double click and single click selection
This commit is contained in:
parent
8f4f3a3766
commit
5333b79222
|
@ -53,16 +53,17 @@ bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev)
|
|||
}
|
||||
if (ev->type() == QEvent::MouseButtonPress) {
|
||||
firstClicked=true;
|
||||
QMouseEvent *pe = static_cast<QMouseEvent *>(ev);
|
||||
mousePressEvent(pe);
|
||||
}
|
||||
if (ev->type() == QEvent::MouseButtonRelease) {
|
||||
QMouseEvent *pe = static_cast<QMouseEvent *>(ev);
|
||||
mouseReleaseEvent(pe);
|
||||
if(firstClicked){
|
||||
if (firstClicked) {
|
||||
QTimer::singleShot(QApplication::doubleClickInterval(),this,[=](){
|
||||
singleClickAction(pe);
|
||||
});
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
doubleClickAction(pe);
|
||||
}
|
||||
}
|
||||
|
@ -80,33 +81,37 @@ bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev)
|
|||
return QWebEngineView::eventFilter(obj, ev);
|
||||
}
|
||||
|
||||
void ArticleWebView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::MidButton)
|
||||
midButtonPressed = true;
|
||||
|
||||
//QWebEngineView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void ArticleWebView::singleClickAction( QMouseEvent * event )
|
||||
{
|
||||
if(!firstClicked)
|
||||
return;
|
||||
if ( event->buttons() & Qt::MidButton )
|
||||
midButtonPressed = true;
|
||||
|
||||
//QWebEngineView::mousePressEvent(event);
|
||||
|
||||
if (selectionBySingleClick && (event->button() & Qt::LeftButton)) {
|
||||
findText(""); // clear the selection first, if any
|
||||
page()->runJavaScript(QString(""
|
||||
" var s = window.getSelection(); "
|
||||
" var range = s.getRangeAt(0); "
|
||||
" var node = s.anchorNode; "
|
||||
" while (range.toString().indexOf(' ') != 0) { "
|
||||
" range.setStart(node, (range.startOffset - 1)); "
|
||||
" } "
|
||||
" range.setStart(node, range.startOffset + 1); "
|
||||
" do { "
|
||||
" range.setEnd(node, range.endOffset + 1); "
|
||||
" } "
|
||||
" while (range.toString().indexOf(' ') == -1 && range.toString().trim() != ''); "
|
||||
" var str = range.toString().trim(); "
|
||||
" console.log(str);"));
|
||||
// QMouseEvent ev( QEvent::MouseButtonDblClick, event->pos(), Qt::LeftButton, Qt::LeftButton, event->modifiers() );
|
||||
// QApplication::sendEvent(page(), &ev );
|
||||
if (selectionBySingleClick && (event->buttons() & Qt::LeftButton)) {
|
||||
// findText(""); // clear the selection first, if any
|
||||
page()->runJavaScript(QString(
|
||||
" var s = window.getSelection(); "
|
||||
" if(s.rangeCount>0){ "
|
||||
" var range = s.getRangeAt(0); "
|
||||
" var node = s.anchorNode; "
|
||||
" while (range.toString().indexOf(' ') != 0) { "
|
||||
" range.setStart(node, (range.startOffset - 1)); "
|
||||
" } "
|
||||
" range.setStart(node, range.startOffset + 1); "
|
||||
" do { "
|
||||
" range.setEnd(node, range.endOffset+1); "
|
||||
" } "
|
||||
" while (range.toString().indexOf(' ') == -1 && range.toString().trim() != ''); "
|
||||
" var str = range.toString().trim(); "
|
||||
" console.log(str);"
|
||||
" }"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ protected:
|
|||
|
||||
bool event( QEvent * event );
|
||||
void singleClickAction( QMouseEvent * event );
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent( QMouseEvent * event );
|
||||
void doubleClickAction( QMouseEvent * event );
|
||||
void focusInEvent( QFocusEvent * event );
|
||||
|
|
Loading…
Reference in a new issue