mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-18 07:24:07 +00:00
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:
parent
919e948ac7
commit
78bd94f965
|
@ -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()
|
||||||
|
|
|
@ -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() ) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue