diff options
author | Matthew Olsson <matthewcolsson@gmail.com> | 2022-03-31 18:01:07 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-04 14:59:37 +0200 |
commit | baac720e13640f3809499b46227f2d281905279a (patch) | |
tree | 6aba70194af784302ee9a4746561cc40980b9c5d | |
parent | 3ecb41b7d9a2e5361ee5e6421d44dd1cbe944580 (diff) | |
download | serenity-baac720e13640f3809499b46227f2d281905279a.zip |
PDFViewer: Respect page navigation features in multi-page mode
This includes the text box and the page up/down arrows.
-rw-r--r-- | Userland/Applications/PDFViewer/NumericInput.cpp | 8 | ||||
-rw-r--r-- | Userland/Applications/PDFViewer/NumericInput.h | 2 | ||||
-rw-r--r-- | Userland/Applications/PDFViewer/PDFViewer.cpp | 7 | ||||
-rw-r--r-- | Userland/Applications/PDFViewer/PDFViewer.h | 2 | ||||
-rw-r--r-- | Userland/Applications/PDFViewer/PDFViewerWidget.cpp | 5 |
5 files changed, 15 insertions, 9 deletions
diff --git a/Userland/Applications/PDFViewer/NumericInput.cpp b/Userland/Applications/PDFViewer/NumericInput.cpp index a11e38795f..dbd3654c4d 100644 --- a/Userland/Applications/PDFViewer/NumericInput.cpp +++ b/Userland/Applications/PDFViewer/NumericInput.cpp @@ -14,7 +14,7 @@ NumericInput::NumericInput() on_change = [&] { auto number_opt = text().to_int(); if (number_opt.has_value()) { - set_current_number(number_opt.value(), false); + set_current_number(number_opt.value(), GUI::AllowCallback::No); return; } @@ -36,7 +36,7 @@ NumericInput::NumericInput() } set_text(builder.to_string()); - set_current_number(new_number_opt.value(), false); + set_current_number(new_number_opt.value(), GUI::AllowCallback::No); }; on_up_pressed = [&] { @@ -78,13 +78,13 @@ void NumericInput::on_focus_lost() on_number_changed(m_current_number); } -void NumericInput::set_current_number(i32 number, bool call_change_handler) +void NumericInput::set_current_number(i32 number, GUI::AllowCallback allow_callback) { if (number == m_current_number) return; m_current_number = clamp(number, m_min_number, m_max_number); set_text(String::number(m_current_number)); - if (on_number_changed && call_change_handler) + if (on_number_changed && allow_callback == GUI::AllowCallback::Yes) on_number_changed(m_current_number); } diff --git a/Userland/Applications/PDFViewer/NumericInput.h b/Userland/Applications/PDFViewer/NumericInput.h index 2e9a53540d..8be85d7754 100644 --- a/Userland/Applications/PDFViewer/NumericInput.h +++ b/Userland/Applications/PDFViewer/NumericInput.h @@ -18,7 +18,7 @@ public: void set_min_number(i32 number); void set_max_number(i32 number); - void set_current_number(i32 number, bool call_change_handler = true); + void set_current_number(i32 number, GUI::AllowCallback allow_callback = GUI::AllowCallback::Yes); private: NumericInput(); diff --git a/Userland/Applications/PDFViewer/PDFViewer.cpp b/Userland/Applications/PDFViewer/PDFViewer.cpp index fc7d8670c2..84fe8611e6 100644 --- a/Userland/Applications/PDFViewer/PDFViewer.cpp +++ b/Userland/Applications/PDFViewer/PDFViewer.cpp @@ -155,6 +155,13 @@ void PDFViewer::paint_event(GUI::PaintEvent& event) } } +void PDFViewer::set_current_page(u32 current_page) +{ + m_current_page_index = current_page; + vertical_scrollbar().set_value(m_page_dimension_cache.render_info[current_page].total_height_before_this_page); + update(); +} + void PDFViewer::resize_event(GUI::ResizeEvent&) { for (auto& map : m_rendered_page_list) diff --git a/Userland/Applications/PDFViewer/PDFViewer.h b/Userland/Applications/PDFViewer/PDFViewer.h index b93f753933..040da7c6d3 100644 --- a/Userland/Applications/PDFViewer/PDFViewer.h +++ b/Userland/Applications/PDFViewer/PDFViewer.h @@ -46,7 +46,7 @@ public: virtual ~PDFViewer() override = default; ALWAYS_INLINE u32 current_page() const { return m_current_page_index; } - ALWAYS_INLINE void set_current_page(u32 current_page) { m_current_page_index = current_page; } + void set_current_page(u32 current_page); ALWAYS_INLINE RefPtr<PDF::Document> const& document() const { return m_document; } PDF::PDFErrorOr<void> set_document(RefPtr<PDF::Document>); diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index ef5baadb1f..2dd8719421 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -34,7 +34,7 @@ PDFViewerWidget::PDFViewerWidget() m_viewer = splitter.add<PDFViewer>(); m_viewer->on_page_change = [&](auto new_page) { - m_page_text_box->set_current_number(new_page + 1); + m_page_text_box->set_current_number(new_page + 1, GUI::AllowCallback::No); }; initialize_toolbar(toolbar); @@ -107,7 +107,6 @@ void PDFViewerWidget::initialize_toolbar(GUI::Toolbar& toolbar) auto new_page_number = static_cast<u32>(number); VERIFY(new_page_number >= 1 && new_page_number <= page_count); m_viewer->set_current_page(new_page_number - 1); - m_viewer->update(); m_go_to_prev_page_action->set_enabled(new_page_number > 1); m_go_to_next_page_action->set_enabled(new_page_number < page_count); }; @@ -201,7 +200,7 @@ void PDFViewerWidget::open_file(Core::File& file) m_total_page_label->set_text(String::formatted("of {}", document->get_page_count())); m_page_text_box->set_enabled(true); - m_page_text_box->set_current_number(1, false); + m_page_text_box->set_current_number(1, GUI::AllowCallback::No); m_page_text_box->set_max_number(document->get_page_count()); m_go_to_prev_page_action->set_enabled(false); m_go_to_next_page_action->set_enabled(document->get_page_count() > 1); |