From f81ac16fa6de515331bd2d107ba1a6760a220e3c Mon Sep 17 00:00:00 2001 From: yifang Date: Fri, 18 Feb 2022 00:39:24 +0800 Subject: [PATCH] fix: mouse scroll zoom in out --- articleview.cc | 15 +++++++++++++++ articleview.hh | 5 +++-- articlewebview.cc | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/articleview.cc b/articleview.cc index 5c302356..4b1ac891 100644 --- a/articleview.cc +++ b/articleview.cc @@ -925,6 +925,21 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev ) return true; } } + else if( ev->type() == QEvent::Wheel ) + { + QWheelEvent * pe = static_cast< QWheelEvent * >( ev ); + if( pe->modifiers().testFlag( Qt::ControlModifier ) ) + { + if( pe->angleDelta().y() > 0 ) + { + zoomIn(); + } + else + { + zoomOut(); + } + } + } } else return QFrame::eventFilter( obj, ev ); diff --git a/articleview.hh b/articleview.hh index 9e3ea0d4..521756b8 100644 --- a/articleview.hh +++ b/articleview.hh @@ -182,8 +182,9 @@ public: void setZoomFactor( qreal factor ) { - if(ui.definition->zoomFactor()!=factor){ - qDebug()<<"set zoom factor:"<zoomFactor(); + if(!qFuzzyCompare(existedFactor,factor)){ + qDebug()<<"zoom factor ,existed:"<setZoomFactor( factor ); ui.definition->page()->setZoomFactor(factor); } diff --git a/articlewebview.cc b/articlewebview.cc index 392d4b01..fe127fa7 100644 --- a/articlewebview.cc +++ b/articlewebview.cc @@ -26,6 +26,7 @@ ArticleWebView::~ArticleWebView() void ArticleWebView::setUp( Config::Class * cfg ) { this->cfg = cfg; + setZoomFactor(cfg->preferences.zoomFactor); } void ArticleWebView::triggerPageAction( QWebEnginePage::WebAction action, bool checked ) @@ -87,6 +88,11 @@ bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev) { if (ev->type() == QEvent::Wheel) { QWheelEvent *pe = static_cast(ev); wheelEvent(pe); + + if ( pe->modifiers().testFlag( Qt::ControlModifier ) ) + { + return true; + } } if (ev->type() == QEvent::FocusIn) { QFocusEvent *pe = static_cast(ev);