diff --git a/Userland/Applications/PDFViewer/PDFViewer.cpp b/Userland/Applications/PDFViewer/PDFViewer.cpp index 72abb439d82..253db28c8b7 100644 --- a/Userland/Applications/PDFViewer/PDFViewer.cpp +++ b/Userland/Applications/PDFViewer/PDFViewer.cpp @@ -48,6 +48,7 @@ PDFViewer::PDFViewer() m_page_view_mode = static_cast(Config::read_i32("PDFViewer"sv, "Display"sv, "PageMode"sv, 0)); m_rendering_preferences.show_clipping_paths = Config::read_bool("PDFViewer"sv, "Rendering"sv, "ShowClippingPaths"sv, false); m_rendering_preferences.show_images = Config::read_bool("PDFViewer"sv, "Rendering"sv, "ShowImages"sv, true); + m_rendering_preferences.show_diagnostics = Config::read_bool("PDFViewer"sv, "Rendering"sv, "ShowDiagnostics"sv, false); m_rendering_preferences.clip_images = Config::read_bool("PDFViewer"sv, "Rendering"sv, "ClipImages"sv, true); m_rendering_preferences.clip_paths = Config::read_bool("PDFViewer"sv, "Rendering"sv, "ClipPaths"sv, true); m_rendering_preferences.clip_text = Config::read_bool("PDFViewer"sv, "Rendering"sv, "ClipText"sv, true); @@ -170,6 +171,13 @@ void PDFViewer::set_current_page(u32 current_page) update(); } +void PDFViewer::set_show_rendering_diagnostics(bool show_diagnostics) +{ + m_rendering_preferences.show_diagnostics = show_diagnostics; + Config::write_bool("PDFViewer"sv, "Rendering"sv, "ShowDiagnostics"sv, show_diagnostics); + update(); +} + void PDFViewer::set_show_clipping_paths(bool show_clipping_paths) { m_rendering_preferences.show_clipping_paths = show_clipping_paths; diff --git a/Userland/Applications/PDFViewer/PDFViewer.h b/Userland/Applications/PDFViewer/PDFViewer.h index 0459713593a..6434d4382f8 100644 --- a/Userland/Applications/PDFViewer/PDFViewer.h +++ b/Userland/Applications/PDFViewer/PDFViewer.h @@ -62,6 +62,8 @@ public: PageViewMode page_view_mode() const { return m_page_view_mode; } void set_page_view_mode(PageViewMode); + bool show_rendering_diagnostics() const { return m_rendering_preferences.show_diagnostics; } + void set_show_rendering_diagnostics(bool); bool show_clipping_paths() const { return m_rendering_preferences.show_clipping_paths; } void set_show_clipping_paths(bool); bool show_images() const { return m_rendering_preferences.show_images; } diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index 9b914e61b1d..0f6086a4207 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -182,10 +182,10 @@ PDFViewerWidget::PDFViewerWidget() m_viewer->set_current_page(page); }; - auto& v_splitter = h_splitter.add(); - v_splitter.layout()->set_spacing(4); + m_vertical_splitter = h_splitter.add(); + m_vertical_splitter->layout()->set_spacing(4); - m_viewer = v_splitter.add(); + m_viewer = m_vertical_splitter->add(); m_viewer->on_page_change = [&](auto new_page) { m_page_text_box->set_value(new_page + 1, GUI::AllowCallback::No); m_go_to_prev_page_action->set_enabled(new_page > 0); @@ -195,7 +195,7 @@ PDFViewerWidget::PDFViewerWidget() verify_cast(m_paged_errors_model.ptr())->add_errors(page, errors); }; - m_errors_tree_view = v_splitter.add(); + m_errors_tree_view = GUI::TreeView::construct(); m_errors_tree_view->set_preferred_height(10); m_errors_tree_view->column_header().set_visible(true); m_errors_tree_view->set_should_fill_selected_rows(true); @@ -203,6 +203,10 @@ PDFViewerWidget::PDFViewerWidget() m_errors_tree_view->set_model(MUST(GUI::SortingProxyModel::create(m_paged_errors_model))); m_errors_tree_view->set_key_column(0); + if (m_viewer->show_rendering_diagnostics()) { + m_vertical_splitter->add_child(*m_errors_tree_view); + } + initialize_toolbar(toolbar); } @@ -247,6 +251,16 @@ ErrorOr PDFViewerWidget::initialize_menubar(GUI::Window& window) })); auto debug_menu = window.add_menu("&Debug"_string); + auto toggle_show_diagnostics = GUI::Action::create_checkable("Show Rendering &Diagnostics", [&](auto& action) { + if (action.is_checked()) { + m_vertical_splitter->add_child(*m_errors_tree_view); + } else { + m_vertical_splitter->remove_child(*m_errors_tree_view); + } + m_viewer->set_show_rendering_diagnostics(action.is_checked()); + }); + toggle_show_diagnostics->set_checked(m_viewer->show_rendering_diagnostics()); + debug_menu->add_action(toggle_show_diagnostics); auto toggle_show_clipping_paths = GUI::Action::create_checkable("Show &Clipping Paths", [&](auto& action) { m_viewer->set_show_clipping_paths(action.is_checked()); }); diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.h b/Userland/Applications/PDFViewer/PDFViewerWidget.h index 70fafaa7001..9260117b797 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.h +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.h @@ -14,6 +14,7 @@ #include #include #include +#include #include class PDFViewer; @@ -39,6 +40,7 @@ private: RefPtr m_viewer; RefPtr m_sidebar; NonnullRefPtr m_paged_errors_model; + RefPtr m_vertical_splitter; RefPtr m_errors_tree_view; RefPtr m_page_text_box; RefPtr m_total_page_label; diff --git a/Userland/Libraries/LibPDF/Renderer.h b/Userland/Libraries/LibPDF/Renderer.h index bb45d00ae78..23f66a68797 100644 --- a/Userland/Libraries/LibPDF/Renderer.h +++ b/Userland/Libraries/LibPDF/Renderer.h @@ -89,6 +89,7 @@ struct GraphicsState { struct RenderingPreferences { bool show_clipping_paths { false }; bool show_images { true }; + bool show_diagnostics { false }; bool clip_images { true }; bool clip_paths { true };