summaryrefslogtreecommitdiff
path: root/src/plugins/bineditor
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2016-11-24 16:32:30 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2016-11-25 08:39:18 +0000
commit224fda31dff76d61644a71f5e0b499b9daf72719 (patch)
treed12fa6f4a7473200aaae9f774901e8edb3d1661a /src/plugins/bineditor
parent4c22f3a76c59635368d51e9da096a076bd387ddf (diff)
downloadqt-creator-224fda31dff76d61644a71f5e0b499b9daf72719.tar.gz
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>
Diffstat (limited to 'src/plugins/bineditor')
-rw-r--r--src/plugins/bineditor/bineditorwidget.cpp41
-rw-r--r--src/plugins/bineditor/bineditorwidget.h3
2 files changed, 28 insertions, 16 deletions
diff --git a/src/plugins/bineditor/bineditorwidget.cpp b/src/plugins/bineditor/bineditorwidget.cpp
index 830243df6e..ae75a56135 100644
--- a/src/plugins/bineditor/bineditorwidget.cpp
+++ b/src/plugins/bineditor/bineditorwidget.cpp
@@ -31,10 +31,12 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
+#include <texteditor/behaviorsettings.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
+#include <utils/fadingindicator.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
@@ -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 de8d78462c..6794a77d38 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,