From 038f99eeff8326112a23003e170966640b0feba2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 30 Jun 2019 15:01:35 +0200 Subject: QuickShow: When zooming with the mouse wheel, keep image centered at cursor. --- Applications/QuickShow/QSWidget.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Applications/QuickShow/QSWidget.cpp') diff --git a/Applications/QuickShow/QSWidget.cpp b/Applications/QuickShow/QSWidget.cpp index 1aa667d03b..a7cda20ef8 100644 --- a/Applications/QuickShow/QSWidget.cpp +++ b/Applications/QuickShow/QSWidget.cpp @@ -72,12 +72,19 @@ void QSWidget::mousemove_event(GMouseEvent& event) void QSWidget::mousewheel_event(GMouseEvent& event) { auto old_scale = m_scale; + auto old_scale_factor = (float)m_scale / 100.0f; + auto zoom_point = event.position().translated(-m_bitmap_rect.location()); + zoom_point.set_x((float)zoom_point.x() / old_scale_factor); + zoom_point.set_y((float)zoom_point.y() / old_scale_factor); m_scale += -event.wheel_delta() * 10; if (m_scale < 10) m_scale = 10; if (m_scale > 1000) m_scale = 1000; relayout(); + auto new_scale_factor = (float)m_scale / 100.0f; + auto scale_factor_change = new_scale_factor - old_scale_factor; + m_bitmap_rect.move_by(-Point((float)zoom_point.x() * scale_factor_change, (float)zoom_point.y() * scale_factor_change)); if (old_scale != m_scale) { if (on_scale_change) on_scale_change(m_scale); -- cgit v1.2.3