summaryrefslogtreecommitdiff
path: root/Applications/QuickShow/QSWidget.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-30 15:01:35 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-30 15:01:35 +0200
commit038f99eeff8326112a23003e170966640b0feba2 (patch)
tree706de2249e383efdeefcbf6a54572cf7e75fac81 /Applications/QuickShow/QSWidget.cpp
parente7ce4514ec65c4a76fbd740383efc4e9e9f29630 (diff)
downloadserenity-038f99eeff8326112a23003e170966640b0feba2.zip
QuickShow: When zooming with the mouse wheel, keep image centered at cursor.
Diffstat (limited to 'Applications/QuickShow/QSWidget.cpp')
-rw-r--r--Applications/QuickShow/QSWidget.cpp7
1 files changed, 7 insertions, 0 deletions
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);