summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Applications/PDFViewer/CMakeLists.txt2
-rw-r--r--Userland/Applications/PDFViewer/PDFViewer.cpp10
-rw-r--r--Userland/Applications/PDFViewer/PDFViewer.h4
-rw-r--r--Userland/Applications/PDFViewer/PDFViewerWidget.cpp37
-rw-r--r--Userland/Applications/PDFViewer/PDFViewerWidget.h7
-rw-r--r--Userland/Applications/PDFViewer/main.cpp5
6 files changed, 54 insertions, 11 deletions
diff --git a/Userland/Applications/PDFViewer/CMakeLists.txt b/Userland/Applications/PDFViewer/CMakeLists.txt
index 4a7ea55350..364861b4a1 100644
--- a/Userland/Applications/PDFViewer/CMakeLists.txt
+++ b/Userland/Applications/PDFViewer/CMakeLists.txt
@@ -13,4 +13,4 @@ set(SOURCES
)
serenity_app(PDFViewer ICON app-pdf-viewer)
-target_link_libraries(PDFViewer LibGUI LibPDF LibFileSystemAccessClient LibMain)
+target_link_libraries(PDFViewer LibGUI LibPDF LibFileSystemAccessClient LibConfig LibMain)
diff --git a/Userland/Applications/PDFViewer/PDFViewer.cpp b/Userland/Applications/PDFViewer/PDFViewer.cpp
index 049447baab..2437e1fec1 100644
--- a/Userland/Applications/PDFViewer/PDFViewer.cpp
+++ b/Userland/Applications/PDFViewer/PDFViewer.cpp
@@ -7,6 +7,7 @@
#include "PDFViewer.h"
#include <AK/Array.h>
+#include <LibConfig/Client.h>
#include <LibGUI/Action.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
@@ -41,6 +42,8 @@ PDFViewer::PDFViewer()
set_scrollbars_enabled(true);
start_timer(30'000);
+
+ m_page_view_mode = static_cast<PageViewMode>(Config::read_i32("PDFViewer", "Display", "PageMode", 0));
}
void PDFViewer::set_document(RefPtr<PDF::Document> document)
@@ -211,6 +214,13 @@ void PDFViewer::rotate(int degrees)
update();
}
+void PDFViewer::set_page_view_mode(PageViewMode mode)
+{
+ m_page_view_mode = mode;
+ Config::write_i32("PDFViewer", "Display", "PageMode", static_cast<i32>(mode));
+ update();
+}
+
PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> PDFViewer::render_page(const PDF::Page& page)
{
auto zoom_scale_factor = static_cast<float>(zoom_levels[m_zoom_level]) / 100.0f;
diff --git a/Userland/Applications/PDFViewer/PDFViewer.h b/Userland/Applications/PDFViewer/PDFViewer.h
index 374bbfb790..7d18e04195 100644
--- a/Userland/Applications/PDFViewer/PDFViewer.h
+++ b/Userland/Applications/PDFViewer/PDFViewer.h
@@ -38,6 +38,9 @@ public:
void reset_zoom();
void rotate(int degrees);
+ PageViewMode page_view_mode() const { return m_page_view_mode; }
+ void set_page_view_mode(PageViewMode);
+
protected:
PDFViewer();
@@ -63,6 +66,7 @@ private:
Vector<HashMap<u32, RenderedPage>> m_rendered_page_list;
u8 m_zoom_level { initial_zoom_level };
+ PageViewMode m_page_view_mode;
Gfx::IntPoint m_pan_starting_position;
int m_rotations { 0 };
diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp
index 3357a6bff0..b86e9a12ac 100644
--- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp
+++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp
@@ -24,7 +24,8 @@ PDFViewerWidget::PDFViewerWidget()
set_fill_with_background_color(true);
set_layout<GUI::VerticalBoxLayout>();
- create_toolbar();
+ auto& toolbar_container = add<GUI::ToolbarContainer>();
+ auto& toolbar = toolbar_container.add<GUI::Toolbar>();
auto& splitter = add<GUI::HorizontalSplitter>();
@@ -35,6 +36,8 @@ PDFViewerWidget::PDFViewerWidget()
m_viewer->on_page_change = [&](auto new_page) {
m_page_text_box->set_current_number(new_page + 1);
};
+
+ initialize_toolbar(toolbar);
}
void PDFViewerWidget::initialize_menubar(GUI::Window& window)
@@ -42,9 +45,8 @@ void PDFViewerWidget::initialize_menubar(GUI::Window& window)
auto& file_menu = window.add_menu("&File");
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
auto response = FileSystemAccessClient::Client::the().try_open_file(&window);
- if (response.is_error())
- return;
- open_file(*response.value());
+ if (!response.is_error())
+ open_file(*response.value());
}));
file_menu.add_separator();
file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
@@ -54,6 +56,10 @@ void PDFViewerWidget::initialize_menubar(GUI::Window& window)
auto& view_menu = window.add_menu("&View");
view_menu.add_action(*m_toggle_sidebar_action);
view_menu.add_separator();
+ auto& view_mode_menu = view_menu.add_submenu("View &Mode");
+ view_mode_menu.add_action(*m_page_view_mode_single);
+ view_mode_menu.add_action(*m_page_view_mode_multiple);
+ view_menu.add_separator();
view_menu.add_action(*m_zoom_in_action);
view_menu.add_action(*m_zoom_out_action);
view_menu.add_action(*m_reset_zoom_action);
@@ -62,11 +68,8 @@ void PDFViewerWidget::initialize_menubar(GUI::Window& window)
help_menu.add_action(GUI::CommonActions::make_about_action("PDF Viewer", GUI::Icon::default_icon("app-pdf-viewer"), &window));
}
-void PDFViewerWidget::create_toolbar()
+void PDFViewerWidget::initialize_toolbar(GUI::Toolbar& toolbar)
{
- auto& toolbar_container = add<GUI::ToolbarContainer>();
- auto& toolbar = toolbar_container.add<GUI::Toolbar>();
-
auto open_outline_action = GUI::Action::create(
"Toggle &Sidebar", { Mod_Ctrl, Key_S }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/sidebar.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
m_sidebar_open = !m_sidebar_open;
@@ -139,6 +142,24 @@ void PDFViewerWidget::create_toolbar()
m_rotate_counterclockwise_action->set_enabled(false);
m_rotate_clockwise_action->set_enabled(false);
+ m_page_view_mode_single = GUI::Action::create_checkable("Single", [&](auto&) {
+ m_viewer->set_page_view_mode(PDFViewer::PageViewMode::Single);
+ });
+
+ m_page_view_mode_multiple = GUI::Action::create_checkable("Multiple", [&](auto&) {
+ m_viewer->set_page_view_mode(PDFViewer::PageViewMode::Multiple);
+ });
+
+ if (m_viewer->page_view_mode() == PDFViewer::PageViewMode::Single) {
+ m_page_view_mode_single->set_checked(true);
+ } else {
+ m_page_view_mode_multiple->set_checked(true);
+ }
+
+ m_page_view_action_group.add_action(*m_page_view_mode_single);
+ m_page_view_action_group.add_action(*m_page_view_mode_multiple);
+ m_page_view_action_group.set_exclusive(true);
+
toolbar.add_action(*m_zoom_in_action);
toolbar.add_action(*m_zoom_out_action);
toolbar.add_action(*m_reset_zoom_action);
diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.h b/Userland/Applications/PDFViewer/PDFViewerWidget.h
index 3bf3a7d42a..f3a520bee3 100644
--- a/Userland/Applications/PDFViewer/PDFViewerWidget.h
+++ b/Userland/Applications/PDFViewer/PDFViewerWidget.h
@@ -10,6 +10,7 @@
#include "PDFViewer.h"
#include "SidebarWidget.h"
#include <LibGUI/Action.h>
+#include <LibGUI/ActionGroup.h>
#include <LibGUI/TextBox.h>
#include <LibGUI/Widget.h>
@@ -22,12 +23,13 @@ public:
~PDFViewerWidget() override = default;
void initialize_menubar(GUI::Window&);
- void create_toolbar();
void open_file(Core::File&);
private:
PDFViewerWidget();
+ void initialize_toolbar(GUI::Toolbar&);
+
RefPtr<PDFViewer> m_viewer;
RefPtr<SidebarWidget> m_sidebar;
RefPtr<NumericInput> m_page_text_box;
@@ -40,6 +42,9 @@ private:
RefPtr<GUI::Action> m_reset_zoom_action;
RefPtr<GUI::Action> m_rotate_counterclockwise_action;
RefPtr<GUI::Action> m_rotate_clockwise_action;
+ GUI::ActionGroup m_page_view_action_group;
+ RefPtr<GUI::Action> m_page_view_mode_single;
+ RefPtr<GUI::Action> m_page_view_mode_multiple;
bool m_sidebar_open { false };
ByteBuffer m_buffer;
diff --git a/Userland/Applications/PDFViewer/main.cpp b/Userland/Applications/PDFViewer/main.cpp
index 831c5b78b5..240194c5c4 100644
--- a/Userland/Applications/PDFViewer/main.cpp
+++ b/Userland/Applications/PDFViewer/main.cpp
@@ -6,6 +6,7 @@
*/
#include "PDFViewerWidget.h"
+#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibFileSystemAccessClient/Client.h>
@@ -25,7 +26,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
auto app_icon = GUI::Icon::default_icon("app-pdf-viewer");
- auto window = GUI::Window::construct();
+ Config::pledge_domain("PDFViewer");
+
+ auto window = TRY(GUI::Window::try_create());
window->set_title("PDF Viewer");
window->resize(640, 400);