diff --git a/Userland/Applications/PDFViewer/PDFViewer.cpp b/Userland/Applications/PDFViewer/PDFViewer.cpp index 05b744b649..3fed2b229a 100644 --- a/Userland/Applications/PDFViewer/PDFViewer.cpp +++ b/Userland/Applications/PDFViewer/PDFViewer.cpp @@ -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 diff --git a/Userland/Applications/PDFViewer/PDFViewer.h b/Userland/Applications/PDFViewer/PDFViewer.h index ab6690b8fd..5b884b46c1 100644 --- a/Userland/Applications/PDFViewer/PDFViewer.h +++ b/Userland/Applications/PDFViewer/PDFViewer.h @@ -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>> m_rendered_page_list; u8 m_zoom_level { initial_zoom_level }; + + Gfx::IntPoint m_pan_starting_position; };