mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
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:
parent
aaa210e6db
commit
d739877807
Notes:
sideshowbarker
2024-07-17 05:19:06 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/d739877807 Pull-request: https://github.com/SerenityOS/serenity/pull/16550
@ -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());
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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>();
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user