PDFViewer: Enable panning with middle mouse button

Enable the use of the middle mouse button for panning in PDFViewer.
This commit is contained in:
Marcus Nilsson 2022-01-02 23:30:13 +01:00 committed by Andreas Kling
parent 3af71c406d
commit 56bec4968c
Notes: sideshowbarker 2024-07-17 21:32:24 +09:00
2 changed files with 28 additions and 0 deletions

View file

@ -113,6 +113,29 @@ void PDFViewer::mousewheel_event(GUI::MouseEvent& event)
}
}
void PDFViewer::mousedown_event(GUI::MouseEvent& event)
{
if (event.button() == GUI::MouseButton::Middle) {
m_pan_starting_position = to_content_position(event.position());
set_override_cursor(Gfx::StandardCursor::Drag);
}
}
void PDFViewer::mouseup_event(GUI::MouseEvent&)
{
set_override_cursor(Gfx::StandardCursor::None);
}
void PDFViewer::mousemove_event(GUI::MouseEvent& event)
{
if (event.buttons() & GUI::MouseButton::Middle) {
auto delta = to_content_position(event.position()) - m_pan_starting_position;
horizontal_scrollbar().decrease_slider_by(delta.x());
vertical_scrollbar().decrease_slider_by(delta.y());
update();
}
}
void PDFViewer::timer_event(Core::TimerEvent&)
{
// Clear the bitmap vector of all pages except the current page

View file

@ -58,6 +58,9 @@ protected:
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousewheel_event(GUI::MouseEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void mouseup_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void timer_event(Core::TimerEvent&) override;
private:
@ -69,4 +72,6 @@ private:
Vector<HashMap<u32, RefPtr<Gfx::Bitmap>>> m_rendered_page_list;
u8 m_zoom_level { initial_zoom_level };
Gfx::IntPoint m_pan_starting_position;
};