summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorRodrigo Tobar <rtobar@icrar.org>2022-12-17 13:39:27 +0800
committerAndreas Kling <kling@serenityos.org>2022-12-17 19:40:52 +0100
commitaaa210e6db0a068c8f16643ad56e0b2665449bde (patch)
tree7fb9a232640816311b7bd14a484060fc7079db26 /Userland
parentc76564b5330a93e699cd40a0b85146fa2711a146 (diff)
downloadserenity-aaa210e6db0a068c8f16643ad56e0b2665449bde.zip
PDFViewer: Show page numbers in Outline TreeView
This is a nice addition to the outline view, which previously simply displayed the titles of each section. Pages are shown in the first column, but the tree is expanded via the second column, where the title is.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/PDFViewer/OutlineModel.cpp41
-rw-r--r--Userland/Applications/PDFViewer/OutlineModel.h1
-rw-r--r--Userland/Applications/PDFViewer/SidebarWidget.cpp2
3 files changed, 42 insertions, 2 deletions
diff --git a/Userland/Applications/PDFViewer/OutlineModel.cpp b/Userland/Applications/PDFViewer/OutlineModel.cpp
index 75ee83da4c..f38b450d0d 100644
--- a/Userland/Applications/PDFViewer/OutlineModel.cpp
+++ b/Userland/Applications/PDFViewer/OutlineModel.cpp
@@ -5,8 +5,17 @@
*/
#include "OutlineModel.h"
+#include <AK/Assertions.h>
#include <AK/NonnullRefPtrVector.h>
+#include <LibGUI/ModelRole.h>
#include <LibGfx/Font/FontDatabase.h>
+#include <LibGfx/TextAlignment.h>
+
+enum Columns {
+ Page,
+ Title,
+ _Count
+};
ErrorOr<NonnullRefPtr<OutlineModel>> OutlineModel::create(NonnullRefPtr<PDF::OutlineDict> const& outline)
{
@@ -41,9 +50,14 @@ int OutlineModel::row_count(const GUI::ModelIndex& index) const
return static_cast<int>(outline_item->children.size());
}
+int OutlineModel::tree_column() const
+{
+ return Columns::Title;
+}
+
int OutlineModel::column_count(const GUI::ModelIndex&) const
{
- return 1;
+ return Columns::_Count;
}
GUI::Variant OutlineModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
@@ -53,13 +67,36 @@ GUI::Variant OutlineModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
switch (role) {
case GUI::ModelRole::Display:
- return outline_item->title;
+ switch (index.column()) {
+ case Columns::Title:
+ return outline_item->title;
+ case Columns::Page: {
+ auto maybe_page_number = outline_item->dest.page;
+ if (maybe_page_number.has_value()) {
+ return maybe_page_number.release_value();
+ }
+ return {};
+ }
+ default:
+ VERIFY_NOT_REACHED();
+ }
+
case GUI::ModelRole::Icon:
if (m_open_outline_items.contains(outline_item))
return m_open_item_icon;
return m_closed_item_icon;
default:
return {};
+
+ case GUI::ModelRole::TextAlignment:
+ switch (index.column()) {
+ case Columns::Title:
+ return Gfx::TextAlignment::CenterLeft;
+ case Columns::Page:
+ return Gfx::TextAlignment::CenterRight;
+ default:
+ VERIFY_NOT_REACHED();
+ }
}
}
diff --git a/Userland/Applications/PDFViewer/OutlineModel.h b/Userland/Applications/PDFViewer/OutlineModel.h
index 3ecb57f6f7..ec55357142 100644
--- a/Userland/Applications/PDFViewer/OutlineModel.h
+++ b/Userland/Applications/PDFViewer/OutlineModel.h
@@ -18,6 +18,7 @@ public:
virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override;
+ virtual int tree_column() const override;
virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex&) const override;
diff --git a/Userland/Applications/PDFViewer/SidebarWidget.cpp b/Userland/Applications/PDFViewer/SidebarWidget.cpp
index a2740f3036..ad97d83cab 100644
--- a/Userland/Applications/PDFViewer/SidebarWidget.cpp
+++ b/Userland/Applications/PDFViewer/SidebarWidget.cpp
@@ -22,6 +22,8 @@ SidebarWidget::SidebarWidget()
m_outline_tree_view = outline_container.add<GUI::TreeView>();
m_outline_tree_view->set_activates_on_selection(true);
+ m_outline_tree_view->set_should_fill_selected_rows(true);
+ m_outline_tree_view->set_selection_behavior(GUI::AbstractView::SelectionBehavior::SelectRows);
auto& thumbnails_container = tab_bar.add_tab<GUI::Widget>("Thumbnails");
thumbnails_container.set_layout<GUI::VerticalBoxLayout>();