PDFViewer: Inform about selections on Outline view

Selecting an Outline Item from the Outline view informs via callback the
corresponding Destination that has been selected. This will be used to
move the application to the corresponding page/section/etc.
This commit is contained in:
Rodrigo Tobar 2022-12-17 20:36:54 +08:00 committed by Andreas Kling
parent aaa210e6db
commit d739877807
4 changed files with 21 additions and 0 deletions

View file

@ -10,6 +10,7 @@
#include <LibGUI/ModelRole.h>
#include <LibGfx/Font/FontDatabase.h>
#include <LibGfx/TextAlignment.h>
#include <LibPDF/Document.h>
enum Columns {
Page,
@ -60,6 +61,12 @@ int OutlineModel::column_count(const GUI::ModelIndex&) const
return Columns::_Count;
}
PDF::Destination const& OutlineModel::get_destination(GUI::ModelIndex const& index)
{
auto* outline_item = static_cast<PDF::OutlineItem*>(index.internal_data());
return outline_item->dest;
}
GUI::Variant OutlineModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
{
VERIFY(index.is_valid());

View file

@ -23,6 +23,8 @@ public:
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex&) const override;
static PDF::Destination const& get_destination(GUI::ModelIndex const&);
private:
OutlineModel(NonnullRefPtr<PDF::OutlineDict> const& outline);

View file

@ -5,6 +5,7 @@
*/
#include "SidebarWidget.h"
#include "OutlineModel.h"
#include <LibGUI/BoxLayout.h>
#include <LibGUI/TabWidget.h>
@ -24,6 +25,13 @@ SidebarWidget::SidebarWidget()
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);
m_outline_tree_view->on_selection_change = [this]() {
auto& selection = m_outline_tree_view->selection();
if (selection.is_empty())
return;
auto destination = OutlineModel::get_destination(selection.first());
on_destination_selected(destination);
};
auto& thumbnails_container = tab_bar.add_tab<GUI::Widget>("Thumbnails");
thumbnails_container.set_layout<GUI::VerticalBoxLayout>();

View file

@ -6,6 +6,8 @@
#pragma once
#include "LibGUI/ModelIndex.h"
#include "LibPDF/Document.h"
#include "OutlineModel.h"
#include <LibGUI/TreeView.h>
#include <LibGUI/Widget.h>
@ -16,6 +18,8 @@ class SidebarWidget final : public GUI::Widget {
public:
~SidebarWidget() override = default;
Function<void(PDF::Destination const&)> on_destination_selected;
ErrorOr<void> set_outline(RefPtr<PDF::OutlineDict> outline)
{
if (outline) {