diff --git a/src/plugins/bineditor/bineditorwidget.cpp b/src/plugins/bineditor/bineditorwidget.cpp index 830243df6e0..ae75a56135b 100644 --- a/src/plugins/bineditor/bineditorwidget.cpp +++ b/src/plugins/bineditor/bineditorwidget.cpp @@ -31,10 +31,12 @@ #include #include +#include #include #include #include +#include #include #include @@ -516,11 +518,16 @@ void BinEditorWidget::changeEvent(QEvent *e) void BinEditorWidget::wheelEvent(QWheelEvent *e) { if (e->modifiers() & Qt::ControlModifier) { - const int delta = e->delta(); - if (delta < 0) - zoomOut(); - else if (delta > 0) - zoomIn(); + if (!TextEditor::TextEditorSettings::behaviorSettings().m_scrollWheelZooming) { + // When the setting is disabled globally, + // we have to skip calling QAbstractScrollArea::wheelEvent() + // that changes zoom in it. + return; + } + + const float delta = e->angleDelta().y() / 120.f; + if (delta != 0) + zoomF(delta); return; } QAbstractScrollArea::wheelEvent(e); @@ -1419,19 +1426,25 @@ void BinEditorWidget::keyPressEvent(QKeyEvent *e) e->accept(); } -void BinEditorWidget::zoomIn(int range) +static void showZoomIndicator(QWidget *editor, const int newZoom) { - QFont f = font(); - const int newSize = f.pointSize() + range; - if (newSize <= 0) - return; - f.setPointSize(newSize); - setFont(f); + Utils::FadingIndicator::showText(editor, + QCoreApplication::translate("BinEditorWidget::TextEditorWidget", + "Zoom: %1%").arg(newZoom), + Utils::FadingIndicator::SmallText); } -void BinEditorWidget::zoomOut(int range) +void BinEditorWidget::zoomF(float delta) { - zoomIn(-range); + float step = 10.f * delta; + // Ensure we always zoom a minimal step in-case the resolution is more than 16x + if (step > 0 && step < 1) + step = 1; + else if (step < 0 && step > -1) + step = -1; + + const int newZoom = TextEditor::TextEditorSettings::instance()->increaseFontZoom(int(step)); + showZoomIndicator(this, newZoom); } void BinEditorWidget::copy(bool raw) diff --git a/src/plugins/bineditor/bineditorwidget.h b/src/plugins/bineditor/bineditorwidget.h index de8d78462c4..6794a77d387 100644 --- a/src/plugins/bineditor/bineditorwidget.h +++ b/src/plugins/bineditor/bineditorwidget.h @@ -78,8 +78,7 @@ public: void updateContents(); bool save(QString *errorString, const QString &oldFileName, const QString &newFileName); - void zoomIn(int range = 1); - void zoomOut(int range = 1); + void zoomF(float delta); enum MoveMode { MoveAnchor,