fix: mouse scroll zoom in out

This commit is contained in:
yifang 2022-02-18 00:39:24 +08:00
parent b9d364e861
commit f81ac16fa6
3 changed files with 24 additions and 2 deletions

View file

@ -925,6 +925,21 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
return true; 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 else
return QFrame::eventFilter( obj, ev ); return QFrame::eventFilter( obj, ev );

View file

@ -182,8 +182,9 @@ public:
void setZoomFactor( qreal factor ) void setZoomFactor( qreal factor )
{ {
if(ui.definition->zoomFactor()!=factor){ qreal existedFactor = ui.definition->zoomFactor();
qDebug()<<"set zoom factor:"<<factor; if(!qFuzzyCompare(existedFactor,factor)){
qDebug()<<"zoom factor ,existed:"<<existedFactor<<"set:"<<factor;
ui.definition->setZoomFactor( factor ); ui.definition->setZoomFactor( factor );
ui.definition->page()->setZoomFactor(factor); ui.definition->page()->setZoomFactor(factor);
} }

View file

@ -26,6 +26,7 @@ ArticleWebView::~ArticleWebView()
void ArticleWebView::setUp( Config::Class * cfg ) void ArticleWebView::setUp( Config::Class * cfg )
{ {
this->cfg = cfg; this->cfg = cfg;
setZoomFactor(cfg->preferences.zoomFactor);
} }
void ArticleWebView::triggerPageAction( QWebEnginePage::WebAction action, bool checked ) void ArticleWebView::triggerPageAction( QWebEnginePage::WebAction action, bool checked )
@ -87,6 +88,11 @@ bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev) {
if (ev->type() == QEvent::Wheel) { if (ev->type() == QEvent::Wheel) {
QWheelEvent *pe = static_cast<QWheelEvent *>(ev); QWheelEvent *pe = static_cast<QWheelEvent *>(ev);
wheelEvent(pe); wheelEvent(pe);
if ( pe->modifiers().testFlag( Qt::ControlModifier ) )
{
return true;
}
} }
if (ev->type() == QEvent::FocusIn) { if (ev->type() == QEvent::FocusIn) {
QFocusEvent *pe = static_cast<QFocusEvent *>(ev); QFocusEvent *pe = static_cast<QFocusEvent *>(ev);