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 <yifang.xiao@noreply.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2023-10-27 07:51:34 +08:00 committed by GitHub
parent 919e948ac7
commit 78bd94f965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 39 deletions

View file

@ -733,18 +733,8 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
} }
if ( obj == webview ) { if ( obj == webview ) {
if ( ev->type() == QEvent::MouseButtonPress ) {
auto event = static_cast< QMouseEvent * >( ev ); if ( ev->type() == QEvent::KeyPress ) {
if ( event->button() == Qt::XButton1 ) {
back();
return true;
}
if ( event->button() == Qt::XButton2 ) {
forward();
return true;
}
}
else if ( ev->type() == QEvent::KeyPress ) {
auto keyEvent = static_cast< QKeyEvent * >( ev ); auto keyEvent = static_cast< QKeyEvent * >( ev );
if ( keyEvent->modifiers() & ( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) ) if ( keyEvent->modifiers() & ( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) )
@ -1348,9 +1338,7 @@ void ArticleView::updateMutedContents()
bool ArticleView::canGoBack() bool ArticleView::canGoBack()
{ {
// First entry in a history is always an empty page, return webview->history()->canGoBack();
// so we skip it.
return webview->history()->currentItemIndex() > 1;
} }
bool ArticleView::canGoForward() bool ArticleView::canGoForward()

View file

@ -80,7 +80,8 @@ bool ArticleWebView::eventFilter( QObject * obj, QEvent * ev )
singleClickAction( pe ); singleClickAction( pe );
} ); } );
} }
mousePressEvent( pe ); if ( pe->buttons() & Qt::MiddleButton )
midButtonPressed = true;
} }
if ( ev->type() == QEvent::MouseButtonRelease ) { if ( ev->type() == QEvent::MouseButtonRelease ) {
auto pe = dynamic_cast< QMouseEvent * >( ev ); auto pe = dynamic_cast< QMouseEvent * >( ev );
@ -102,19 +103,6 @@ bool ArticleWebView::eventFilter( QObject * obj, QEvent * ev )
return QWebEngineView::eventFilter( obj, 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 ) void ArticleWebView::singleClickAction( QMouseEvent * event )
{ {
if ( !singleClickToDbClick ) 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 ) void ArticleWebView::doubleClickAction( QMouseEvent * event )
{ {
if ( Qt::MouseEventSynthesizedByApplication != event->source() ) { if ( Qt::MouseEventSynthesizedByApplication != event->source() ) {

View file

@ -55,8 +55,6 @@ protected:
bool event( QEvent * event ) override; bool event( QEvent * event ) override;
void singleClickAction( QMouseEvent * event ); void singleClickAction( QMouseEvent * event );
void sendCustomMouseEvent( QEvent::Type type ); void sendCustomMouseEvent( QEvent::Type type );
void mousePressEvent( QMouseEvent * event ) override;
void mouseReleaseEvent( QMouseEvent * event ) override;
void doubleClickAction( QMouseEvent * event ); void doubleClickAction( QMouseEvent * event );
void wheelEvent( QWheelEvent * event ) override; void wheelEvent( QWheelEvent * event ) override;