forked from qt-creator/qt-creator
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:
@@ -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)
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user