mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
PDFViewer: Add a tab bar with outlines and thumbnails
Outlines are in theory implemented (though I'm having trouble finding a simple PDF with outlines to test it on), and thumbnails are not.
This commit is contained in:
parent
67b65dffa8
commit
cea7dbce42
7 changed files with 250 additions and 7 deletions
|
@ -6,23 +6,24 @@
|
|||
|
||||
#include "PDFViewerWidget.h"
|
||||
#include <LibCore/File.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/FilePicker.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/Menubar.h>
|
||||
#include <LibGUI/Splitter.h>
|
||||
|
||||
PDFViewerWidget::PDFViewerWidget()
|
||||
{
|
||||
set_fill_with_background_color(true);
|
||||
set_layout<GUI::VerticalBoxLayout>();
|
||||
|
||||
m_viewer = add<PDFViewer>();
|
||||
}
|
||||
auto& splitter = add<GUI::HorizontalSplitter>();
|
||||
|
||||
PDFViewerWidget::~PDFViewerWidget()
|
||||
{
|
||||
m_sidebar = splitter.add<SidebarWidget>();
|
||||
m_sidebar->set_fixed_width(0);
|
||||
|
||||
m_viewer = splitter.add<PDFViewer>();
|
||||
}
|
||||
|
||||
void PDFViewerWidget::initialize_menubar(GUI::Menubar& menubar)
|
||||
|
@ -36,6 +37,21 @@ void PDFViewerWidget::initialize_menubar(GUI::Menubar& menubar)
|
|||
file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
||||
GUI::Application::the()->quit();
|
||||
}));
|
||||
|
||||
auto& view_menu = menubar.add_menu("&View");
|
||||
|
||||
auto open_sidebar_action = GUI::Action::create(
|
||||
"Open &Sidebar", { Mod_Ctrl, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/sidebar.png"), [&](auto& action) {
|
||||
m_sidebar_open = !m_sidebar_open;
|
||||
m_sidebar->set_fixed_width(m_sidebar_open ? 0 : 200);
|
||||
action.set_text(m_sidebar_open ? "Open &Sidebar" : "Close &Sidebar");
|
||||
},
|
||||
nullptr);
|
||||
open_sidebar_action->set_enabled(false);
|
||||
|
||||
view_menu.add_action(open_sidebar_action);
|
||||
|
||||
m_open_outline_action = open_sidebar_action;
|
||||
}
|
||||
|
||||
void PDFViewerWidget::open_file(const String& path)
|
||||
|
@ -44,5 +60,19 @@ void PDFViewerWidget::open_file(const String& path)
|
|||
auto file_result = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||
VERIFY(!file_result.is_error());
|
||||
m_buffer = file_result.value()->read_all();
|
||||
m_viewer->set_document(adopt_ref(*new PDF::Document(m_buffer)));
|
||||
auto document = adopt_ref(*new PDF::Document(m_buffer));
|
||||
m_viewer->set_document(document);
|
||||
|
||||
if (document->outline()) {
|
||||
auto outline = document->outline();
|
||||
m_sidebar->set_outline(outline.release_nonnull());
|
||||
m_sidebar->set_fixed_width(200);
|
||||
m_sidebar_open = true;
|
||||
m_open_outline_action->set_enabled(true);
|
||||
} else {
|
||||
m_sidebar->set_outline({});
|
||||
m_sidebar->set_fixed_width(0);
|
||||
m_sidebar_open = false;
|
||||
m_open_outline_action->set_enabled(false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue