From 78bd94f965340ff008d724fe61cf6c288957f7a7 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Fri, 27 Oct 2023 07:51:34 +0800 Subject: [PATCH] fix: mouse xbutton1(&2) back and forward event (#1258) * fix: mouse xbutton1(&2) back and forward event * [autofix.ci] apply automated fixes * fix: mouse xbutton1&2 back and forward triggered twice. --------- Co-authored-by: YiFang Xiao Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/ui/articleview.cc | 18 +++--------------- src/ui/articlewebview.cc | 24 ++---------------------- src/ui/articlewebview.hh | 2 -- 3 files changed, 5 insertions(+), 39 deletions(-) diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index f410daa4..61927bcf 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -733,18 +733,8 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev ) } if ( obj == webview ) { - if ( ev->type() == QEvent::MouseButtonPress ) { - auto event = static_cast< QMouseEvent * >( ev ); - if ( event->button() == Qt::XButton1 ) { - back(); - return true; - } - if ( event->button() == Qt::XButton2 ) { - forward(); - return true; - } - } - else if ( ev->type() == QEvent::KeyPress ) { + + if ( ev->type() == QEvent::KeyPress ) { auto keyEvent = static_cast< QKeyEvent * >( ev ); if ( keyEvent->modifiers() & ( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) ) @@ -1348,9 +1338,7 @@ void ArticleView::updateMutedContents() bool ArticleView::canGoBack() { - // First entry in a history is always an empty page, - // so we skip it. - return webview->history()->currentItemIndex() > 1; + return webview->history()->canGoBack(); } bool ArticleView::canGoForward() diff --git a/src/ui/articlewebview.cc b/src/ui/articlewebview.cc index 038be525..f2cc18f9 100644 --- a/src/ui/articlewebview.cc +++ b/src/ui/articlewebview.cc @@ -80,7 +80,8 @@ bool ArticleWebView::eventFilter( QObject * obj, QEvent * ev ) singleClickAction( pe ); } ); } - mousePressEvent( pe ); + if ( pe->buttons() & Qt::MiddleButton ) + midButtonPressed = true; } if ( ev->type() == QEvent::MouseButtonRelease ) { auto pe = dynamic_cast< QMouseEvent * >( ev ); @@ -102,19 +103,6 @@ bool ArticleWebView::eventFilter( QObject * obj, QEvent * ev ) return QWebEngineView::eventFilter( obj, ev ); } -void ArticleWebView::mousePressEvent( QMouseEvent * event ) -{ - if ( event->buttons() & Qt::MiddleButton ) - midButtonPressed = true; - - if ( event->buttons() & Qt::XButton1 ) { - back(); - } - if ( event->buttons() & Qt::XButton2 ) { - forward(); - } -} - void ArticleWebView::singleClickAction( QMouseEvent * event ) { if ( !singleClickToDbClick ) @@ -146,14 +134,6 @@ void ArticleWebView::sendCustomMouseEvent( QEvent::Type type ) } } -void ArticleWebView::mouseReleaseEvent( QMouseEvent * event ) -{ - bool noMidButton = !( event->buttons() & Qt::MiddleButton ); - - // if ( midButtonPressed & noMidButton ) - // midButtonPressed = false; -} - void ArticleWebView::doubleClickAction( QMouseEvent * event ) { if ( Qt::MouseEventSynthesizedByApplication != event->source() ) { diff --git a/src/ui/articlewebview.hh b/src/ui/articlewebview.hh index f65ebf83..f60296d1 100644 --- a/src/ui/articlewebview.hh +++ b/src/ui/articlewebview.hh @@ -55,8 +55,6 @@ protected: bool event( QEvent * event ) override; void singleClickAction( QMouseEvent * event ); void sendCustomMouseEvent( QEvent::Type type ); - void mousePressEvent( QMouseEvent * event ) override; - void mouseReleaseEvent( QMouseEvent * event ) override; void doubleClickAction( QMouseEvent * event ); void wheelEvent( QWheelEvent * event ) override;