From 5e817e7d4024ab441567b6ec23bf3f1195d56c16 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Mon, 10 Jan 2022 22:13:31 +0800 Subject: [PATCH] fix:single click to select improvement. --- articlewebview.cc | 29 ++++++++++++++++------------- articlewebview.hh | 3 ++- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/articlewebview.cc b/articlewebview.cc index 0f8b1e51..1219edd1 100644 --- a/articlewebview.cc +++ b/articlewebview.cc @@ -45,28 +45,32 @@ bool ArticleWebView::event( QEvent * event ) return QWebEngineView::event(event); } -bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev) -{ +bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev) { + if (ev->type() == QEvent::MouseButtonDblClick) { - //QMouseEvent *pe = static_cast(ev); - firstClicked=false; + singleClicked = false; + dbClicked = true; + } + if (ev->type()==QEvent::MouseMove) { + singleClicked=false; } if (ev->type() == QEvent::MouseButtonPress) { QMouseEvent *pe = static_cast(ev); - if(pe->buttons() & Qt::LeftButton) + if(pe->button() == Qt::LeftButton) { - firstClicked=true; + singleClicked = true; + dbClicked = false; + QTimer::singleShot(QApplication::doubleClickInterval(),this,[=](){ + singleClickAction(pe); + }); } mousePressEvent(pe); } if (ev->type() == QEvent::MouseButtonRelease) { QMouseEvent *pe = static_cast(ev); mouseReleaseEvent(pe); - if (firstClicked) { - QTimer::singleShot(QApplication::doubleClickInterval(),this,[=](){ - singleClickAction(pe); - }); - } else { + if (dbClicked) { + //emit the signal after button release.emit earlier(in MouseButtonDblClick event) can not get selected text; doubleClickAction(pe); } } @@ -90,7 +94,7 @@ void ArticleWebView::mousePressEvent(QMouseEvent *event) void ArticleWebView::singleClickAction(QMouseEvent * event ) { - if(!firstClicked) + if(!singleClicked) return; if (selectionBySingleClick) { @@ -120,7 +124,6 @@ void ArticleWebView::mouseReleaseEvent(QMouseEvent *event) { } void ArticleWebView::doubleClickAction(QMouseEvent *event) { - // emit the signal only if we are not double-clicking on scrollbars if (Qt::MouseEventSynthesizedByApplication != event->source()) { emit doubleClicked(event->pos()); } diff --git a/articlewebview.hh b/articlewebview.hh index 9d39f4a9..aaca0045 100644 --- a/articlewebview.hh +++ b/articlewebview.hh @@ -70,7 +70,8 @@ private: //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 singleClicked; + bool dbClicked; }; #endif