Keep bineditor zoom in sync with global settings

The code is basically copied from TextEditorWidget.

Change-Id: I5a88814d59ee991be030b15840e1aff08f20a25b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2016-11-24 16:32:30 +01:00
parent 4c22f3a76c
commit 224fda31df
2 changed files with 28 additions and 16 deletions

View File

@@ -31,10 +31,12 @@
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <texteditor/behaviorsettings.h>
#include <texteditor/fontsettings.h> #include <texteditor/fontsettings.h>
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h> #include <texteditor/texteditorsettings.h>
#include <utils/fadingindicator.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -516,11 +518,16 @@ void BinEditorWidget::changeEvent(QEvent *e)
void BinEditorWidget::wheelEvent(QWheelEvent *e) void BinEditorWidget::wheelEvent(QWheelEvent *e)
{ {
if (e->modifiers() & Qt::ControlModifier) { if (e->modifiers() & Qt::ControlModifier) {
const int delta = e->delta(); if (!TextEditor::TextEditorSettings::behaviorSettings().m_scrollWheelZooming) {
if (delta < 0) // When the setting is disabled globally,
zoomOut(); // we have to skip calling QAbstractScrollArea::wheelEvent()
else if (delta > 0) // that changes zoom in it.
zoomIn(); return;
}
const float delta = e->angleDelta().y() / 120.f;
if (delta != 0)
zoomF(delta);
return; return;
} }
QAbstractScrollArea::wheelEvent(e); QAbstractScrollArea::wheelEvent(e);
@@ -1419,19 +1426,25 @@ void BinEditorWidget::keyPressEvent(QKeyEvent *e)
e->accept(); e->accept();
} }
void BinEditorWidget::zoomIn(int range) static void showZoomIndicator(QWidget *editor, const int newZoom)
{ {
QFont f = font(); Utils::FadingIndicator::showText(editor,
const int newSize = f.pointSize() + range; QCoreApplication::translate("BinEditorWidget::TextEditorWidget",
if (newSize <= 0) "Zoom: %1%").arg(newZoom),
return; Utils::FadingIndicator::SmallText);
f.setPointSize(newSize);
setFont(f);
} }
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) void BinEditorWidget::copy(bool raw)

View File

@@ -78,8 +78,7 @@ public:
void updateContents(); void updateContents();
bool save(QString *errorString, const QString &oldFileName, const QString &newFileName); bool save(QString *errorString, const QString &oldFileName, const QString &newFileName);
void zoomIn(int range = 1); void zoomF(float delta);
void zoomOut(int range = 1);
enum MoveMode { enum MoveMode {
MoveAnchor, MoveAnchor,