PDFViewer: Update the page number when scrolling between pages

This commit is contained in:
FalseHonesty 2021-06-20 15:07:44 -04:00 committed by Ali Mohammad Pur
parent 395bee07e0
commit 4f0a75224c
3 changed files with 9 additions and 0 deletions

View file

@ -90,6 +90,8 @@ void PDFViewer::mousewheel_event(GUI::MouseEvent& event)
if (scrollbar.value() == scrollbar.max()) {
if (m_current_page_index < m_document->get_page_count() - 1) {
m_current_page_index++;
if (on_page_change)
on_page_change(m_current_page_index);
scrollbar.set_value(0);
}
} else {
@ -99,6 +101,8 @@ void PDFViewer::mousewheel_event(GUI::MouseEvent& event)
if (scrollbar.value() == 0) {
if (m_current_page_index > 0) {
m_current_page_index--;
if (on_page_change)
on_page_change(m_current_page_index);
scrollbar.set_value(scrollbar.max());
}
} else {

View file

@ -47,6 +47,8 @@ public:
ALWAYS_INLINE const RefPtr<PDF::Document>& document() const { return m_document; }
void set_document(RefPtr<PDF::Document>);
Function<void(u32 new_page)> on_page_change;
protected:
PDFViewer();

View file

@ -30,6 +30,9 @@ PDFViewerWidget::PDFViewerWidget()
m_sidebar->set_fixed_width(0);
m_viewer = splitter.add<PDFViewer>();
m_viewer->on_page_change = [&](auto new_page) {
m_page_text_box->set_current_number(new_page + 1);
};
}
void PDFViewerWidget::initialize_menubar(GUI::Menubar& menubar)