2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2021-09-03 21:36:13 +03:00
|
|
|
* Copyright (c) 2021, Mohsan Ali <mohsan0073@gmail.com>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2021-05-14 19:37:08 +03:00
|
|
|
#include "ViewWidget.h"
|
2020-04-05 21:25:14 +03:00
|
|
|
#include <AK/URL.h>
|
2020-04-12 16:24:13 +03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2021-11-24 02:06:40 +03:00
|
|
|
#include <LibCore/System.h>
|
2021-03-12 15:25:38 +03:00
|
|
|
#include <LibDesktop/Launcher.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Action.h>
|
2021-12-29 18:37:04 +03:00
|
|
|
#include <LibGUI/ActionGroup.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Application.h>
|
|
|
|
#include <LibGUI/BoxLayout.h>
|
2020-09-05 17:53:30 +03:00
|
|
|
#include <LibGUI/Clipboard.h>
|
2020-06-18 00:25:57 +03:00
|
|
|
#include <LibGUI/Desktop.h>
|
2020-04-05 21:25:14 +03:00
|
|
|
#include <LibGUI/FilePicker.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Label.h>
|
|
|
|
#include <LibGUI/Menu.h>
|
2021-04-13 17:18:20 +03:00
|
|
|
#include <LibGUI/Menubar.h>
|
2020-04-12 16:40:05 +03:00
|
|
|
#include <LibGUI/MessageBox.h>
|
2021-04-13 17:18:20 +03:00
|
|
|
#include <LibGUI/Toolbar.h>
|
|
|
|
#include <LibGUI/ToolbarContainer.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Window.h>
|
2020-02-15 01:02:47 +03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-04-23 19:21:23 +03:00
|
|
|
#include <LibGfx/Palette.h>
|
2020-06-18 16:00:19 +03:00
|
|
|
#include <LibGfx/Rect.h>
|
2021-11-24 02:06:40 +03:00
|
|
|
#include <LibMain/Main.h>
|
2020-08-04 15:23:06 +03:00
|
|
|
#include <serenity.h>
|
2020-04-12 16:40:05 +03:00
|
|
|
#include <string.h>
|
2019-03-21 05:57:42 +03:00
|
|
|
|
2021-05-14 19:37:08 +03:00
|
|
|
using namespace ImageViewer;
|
|
|
|
|
2021-11-24 02:06:40 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2019-03-21 05:57:42 +03:00
|
|
|
{
|
2021-11-28 01:26:34 +03:00
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath unix thread"));
|
2020-01-12 04:02:44 +03:00
|
|
|
|
2021-11-24 02:06:40 +03:00
|
|
|
auto app = TRY(GUI::Application::try_create(arguments));
|
2019-03-21 05:57:42 +03:00
|
|
|
|
2021-11-24 02:23:00 +03:00
|
|
|
TRY(Desktop::Launcher::add_allowed_handler_with_any_url("/bin/ImageViewer"));
|
|
|
|
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/ImageViewer.md") }));
|
|
|
|
TRY(Desktop::Launcher::seal_allowlist());
|
2021-03-12 15:25:38 +03:00
|
|
|
|
2020-11-02 22:30:17 +03:00
|
|
|
auto app_icon = GUI::Icon::default_icon("filetype-image");
|
|
|
|
|
2020-04-12 16:24:13 +03:00
|
|
|
const char* path = nullptr;
|
|
|
|
Core::ArgsParser args_parser;
|
|
|
|
args_parser.add_positional_argument(path, "The image file to be displayed.", "file", Core::ArgsParser::Required::No);
|
2021-11-24 02:06:40 +03:00
|
|
|
args_parser.parse(arguments);
|
2019-03-21 05:57:42 +03:00
|
|
|
|
2021-11-24 02:06:40 +03:00
|
|
|
auto window = TRY(GUI::Window::try_create());
|
2020-04-05 21:25:14 +03:00
|
|
|
window->set_double_buffering_enabled(true);
|
2020-08-01 01:12:11 +03:00
|
|
|
window->resize(300, 200);
|
2020-11-02 22:30:17 +03:00
|
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
2021-05-14 19:34:44 +03:00
|
|
|
window->set_title("Image Viewer");
|
2020-04-05 21:25:14 +03:00
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
auto root_widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
|
|
|
root_widget->set_fill_with_background_color(true);
|
|
|
|
root_widget->set_layout<GUI::VerticalBoxLayout>();
|
|
|
|
root_widget->layout()->set_spacing(2);
|
2019-03-21 15:31:47 +03:00
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
auto toolbar_container = TRY(root_widget->try_add<GUI::ToolbarContainer>());
|
|
|
|
auto main_toolbar = TRY(toolbar_container->try_add<GUI::Toolbar>());
|
2020-04-12 17:40:34 +03:00
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
auto widget = TRY(root_widget->try_add<ViewWidget>());
|
2021-09-03 21:36:13 +03:00
|
|
|
if (path) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->set_path(path);
|
2021-09-03 21:36:13 +03:00
|
|
|
}
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->on_scale_change = [&](float scale) {
|
|
|
|
if (!widget->bitmap()) {
|
2021-05-14 19:34:44 +03:00
|
|
|
window->set_title("Image Viewer");
|
2020-06-18 16:00:19 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
window->set_title(String::formatted("{} {} {}% - Image Viewer", widget->path(), widget->bitmap()->size().to_string(), (int)(scale * 100)));
|
2020-06-18 16:00:19 +03:00
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
if (scale == 100 && !widget->scaled_for_first_image()) {
|
|
|
|
widget->set_scaled_for_first_image(true);
|
|
|
|
widget->resize_window();
|
2021-07-08 01:04:50 +03:00
|
|
|
}
|
2019-06-23 17:35:43 +03:00
|
|
|
};
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->on_drop = [&](auto& event) {
|
2021-03-12 15:25:38 +03:00
|
|
|
if (!event.mime_data().has_urls())
|
|
|
|
return;
|
2020-04-05 21:25:14 +03:00
|
|
|
|
2021-03-12 15:25:38 +03:00
|
|
|
auto urls = event.mime_data().urls();
|
2020-04-05 21:25:14 +03:00
|
|
|
|
2021-03-12 15:25:38 +03:00
|
|
|
if (urls.is_empty())
|
|
|
|
return;
|
|
|
|
|
2021-07-12 18:58:33 +03:00
|
|
|
window->move_to_front();
|
2021-09-03 21:36:13 +03:00
|
|
|
|
|
|
|
auto path = urls.first().path();
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->set_path(path);
|
|
|
|
widget->load_from_file(path);
|
2021-03-12 15:25:38 +03:00
|
|
|
|
|
|
|
for (size_t i = 1; i < urls.size(); ++i) {
|
2021-05-14 19:34:44 +03:00
|
|
|
Desktop::Launcher::open(URL::create_with_file_protocol(urls[i].path().characters()), "/bin/ImageViewer");
|
2020-04-05 21:25:14 +03:00
|
|
|
}
|
|
|
|
};
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->on_doubleclick = [&] {
|
2020-06-16 10:47:47 +03:00
|
|
|
window->set_fullscreen(!window->is_fullscreen());
|
2021-12-30 00:19:48 +03:00
|
|
|
toolbar_container->set_visible(!window->is_fullscreen());
|
|
|
|
widget->set_frame_thickness(window->is_fullscreen() ? 0 : 2);
|
2020-06-16 10:47:47 +03:00
|
|
|
};
|
2020-04-05 21:25:14 +03:00
|
|
|
|
2020-04-12 14:35:15 +03:00
|
|
|
// Actions
|
2020-04-12 16:40:05 +03:00
|
|
|
auto open_action = GUI::CommonActions::make_open_action(
|
|
|
|
[&](auto&) {
|
2021-04-10 15:58:35 +03:00
|
|
|
auto path = GUI::FilePicker::get_open_filepath(window, "Open Image");
|
2020-04-12 16:40:05 +03:00
|
|
|
if (path.has_value()) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->set_path(path.value());
|
|
|
|
widget->load_from_file(path.value());
|
2020-04-12 16:40:05 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
auto delete_action = GUI::CommonActions::make_delete_action(
|
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
auto path = widget->path();
|
2020-04-12 17:40:34 +03:00
|
|
|
if (path.is_empty())
|
2020-04-12 16:40:05 +03:00
|
|
|
return;
|
|
|
|
|
2020-07-16 05:45:11 +03:00
|
|
|
auto msgbox_result = GUI::MessageBox::show(window,
|
2021-09-04 02:11:28 +03:00
|
|
|
String::formatted("Are you sure you want to delete {}?", path),
|
2020-04-12 16:40:05 +03:00
|
|
|
"Confirm deletion",
|
|
|
|
GUI::MessageBox::Type::Warning,
|
2020-07-16 05:45:11 +03:00
|
|
|
GUI::MessageBox::InputType::OKCancel);
|
2020-04-12 16:40:05 +03:00
|
|
|
|
|
|
|
if (msgbox_result == GUI::MessageBox::ExecCancel)
|
|
|
|
return;
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
auto unlinked_or_error = Core::System::unlink(widget->path());
|
2021-12-29 23:47:38 +03:00
|
|
|
if (unlinked_or_error.is_error()) {
|
2020-07-16 05:45:11 +03:00
|
|
|
GUI::MessageBox::show(window,
|
2021-12-29 23:47:38 +03:00
|
|
|
String::formatted("unlink({}) failed: {}", path, unlinked_or_error.error()),
|
2020-04-12 16:40:05 +03:00
|
|
|
"Delete failed",
|
2020-07-16 05:45:11 +03:00
|
|
|
GUI::MessageBox::Type::Error);
|
2020-04-12 16:40:05 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->clear();
|
2020-04-12 16:40:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
auto quit_action = GUI::CommonActions::make_quit_action(
|
|
|
|
[&](auto&) {
|
2020-07-04 15:05:19 +03:00
|
|
|
app->quit();
|
2020-04-12 16:40:05 +03:00
|
|
|
});
|
|
|
|
|
2021-04-10 15:58:35 +03:00
|
|
|
auto rotate_left_action = GUI::Action::create("Rotate &Left", { Mod_None, Key_L },
|
2020-04-12 16:03:31 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->rotate(Gfx::RotationDirection::CounterClockwise);
|
2020-04-12 16:03:31 +03:00
|
|
|
});
|
|
|
|
|
2021-04-10 15:58:35 +03:00
|
|
|
auto rotate_right_action = GUI::Action::create("Rotate &Right", { Mod_None, Key_R },
|
2020-04-12 16:03:31 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->rotate(Gfx::RotationDirection::Clockwise);
|
2020-04-12 16:03:31 +03:00
|
|
|
});
|
|
|
|
|
2021-04-10 15:58:35 +03:00
|
|
|
auto vertical_flip_action = GUI::Action::create("Flip &Vertically", { Mod_None, Key_V },
|
2020-04-12 16:03:31 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->flip(Gfx::Orientation::Vertical);
|
2020-04-12 16:03:31 +03:00
|
|
|
});
|
|
|
|
|
2021-04-10 15:58:35 +03:00
|
|
|
auto horizontal_flip_action = GUI::Action::create("Flip &Horizontally", { Mod_None, Key_H },
|
2020-04-12 16:03:31 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->flip(Gfx::Orientation::Horizontal);
|
2020-04-12 16:03:31 +03:00
|
|
|
});
|
|
|
|
|
2021-04-10 15:58:35 +03:00
|
|
|
auto desktop_wallpaper_action = GUI::Action::create("Set as Desktop &Wallpaper",
|
2020-06-18 00:25:57 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:07:30 +03:00
|
|
|
auto could_set_wallpaper = GUI::Desktop::the().set_wallpaper(widget->path());
|
|
|
|
if (!could_set_wallpaper) {
|
|
|
|
GUI::MessageBox::show(window,
|
|
|
|
String::formatted("set_wallpaper({}) failed", widget->path()),
|
|
|
|
"Could not set wallpaper",
|
|
|
|
GUI::MessageBox::Type::Error);
|
|
|
|
}
|
2020-06-18 00:25:57 +03:00
|
|
|
});
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
auto go_first_action = GUI::Action::create("&Go to First", { Mod_None, Key_Home }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-first.png")),
|
2020-04-12 14:35:15 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->navigate(ViewWidget::Directions::First);
|
2020-04-12 14:35:15 +03:00
|
|
|
});
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
auto go_back_action = GUI::Action::create("Go &Back", { Mod_None, Key_Left }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png")),
|
2020-04-12 14:35:15 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->navigate(ViewWidget::Directions::Back);
|
2020-04-12 14:35:15 +03:00
|
|
|
});
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
auto go_forward_action = GUI::Action::create("Go &Forward", { Mod_None, Key_Right }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png")),
|
2020-04-12 14:35:15 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->navigate(ViewWidget::Directions::Forward);
|
2020-04-12 14:35:15 +03:00
|
|
|
});
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
auto go_last_action = GUI::Action::create("Go to &Last", { Mod_None, Key_End }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-last.png")),
|
2020-04-12 14:35:15 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->navigate(ViewWidget::Directions::Last);
|
2020-04-12 14:35:15 +03:00
|
|
|
});
|
|
|
|
|
2021-05-16 11:01:29 +03:00
|
|
|
auto full_screen_action = GUI::CommonActions::make_fullscreen_action(
|
2020-04-12 16:24:31 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->on_doubleclick();
|
2020-04-12 16:24:31 +03:00
|
|
|
});
|
|
|
|
|
2021-05-15 21:35:52 +03:00
|
|
|
auto zoom_in_action = GUI::CommonActions::make_zoom_in_action(
|
2020-04-12 16:24:31 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->set_scale(widget->scale() * 1.44f);
|
2021-05-15 21:35:52 +03:00
|
|
|
},
|
|
|
|
window);
|
2020-04-12 16:24:31 +03:00
|
|
|
|
2021-05-15 21:35:52 +03:00
|
|
|
auto reset_zoom_action = GUI::CommonActions::make_reset_zoom_action(
|
2020-04-12 16:24:31 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->set_scale(1.f);
|
2021-05-15 21:35:52 +03:00
|
|
|
},
|
|
|
|
window);
|
2020-04-12 16:24:31 +03:00
|
|
|
|
2021-05-15 21:35:52 +03:00
|
|
|
auto zoom_out_action = GUI::CommonActions::make_zoom_out_action(
|
2020-04-12 16:24:31 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->set_scale(widget->scale() / 1.44f);
|
2021-05-15 21:35:52 +03:00
|
|
|
},
|
|
|
|
window);
|
2020-04-12 17:59:24 +03:00
|
|
|
|
2021-04-10 15:58:35 +03:00
|
|
|
auto hide_show_toolbar_action = GUI::Action::create("Hide/Show &Toolbar", { Mod_Ctrl, Key_T },
|
2020-04-12 17:40:34 +03:00
|
|
|
[&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
toolbar_container->set_visible(!toolbar_container->is_visible());
|
2020-04-12 17:40:34 +03:00
|
|
|
});
|
|
|
|
|
2020-09-05 17:53:30 +03:00
|
|
|
auto copy_action = GUI::CommonActions::make_copy_action([&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
if (widget->bitmap())
|
|
|
|
GUI::Clipboard::the().set_bitmap(*widget->bitmap());
|
2020-09-05 17:53:30 +03:00
|
|
|
});
|
2021-12-29 18:37:04 +03:00
|
|
|
|
|
|
|
auto nearest_neighbor_action = GUI::Action::create_checkable("&Nearest Neighbor", [&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->set_scaling_mode(Gfx::Painter::ScalingMode::NearestNeighbor);
|
2021-12-29 18:37:04 +03:00
|
|
|
});
|
|
|
|
nearest_neighbor_action->set_checked(true);
|
|
|
|
|
|
|
|
auto bilinear_action = GUI::Action::create_checkable("&Bilinear", [&](auto&) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->set_scaling_mode(Gfx::Painter::ScalingMode::BilinearBlend);
|
2021-12-29 18:37:04 +03:00
|
|
|
});
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->on_image_change = [&](const Gfx::Bitmap* bitmap) {
|
2021-05-16 11:01:29 +03:00
|
|
|
bool should_enable_image_actions = (bitmap != nullptr);
|
2021-12-30 00:19:48 +03:00
|
|
|
bool should_enable_forward_actions = (widget->is_next_available() && should_enable_image_actions);
|
|
|
|
bool should_enable_backward_actions = (widget->is_previous_available() && should_enable_image_actions);
|
2021-05-16 11:01:29 +03:00
|
|
|
delete_action->set_enabled(should_enable_image_actions);
|
|
|
|
rotate_left_action->set_enabled(should_enable_image_actions);
|
|
|
|
rotate_right_action->set_enabled(should_enable_image_actions);
|
|
|
|
vertical_flip_action->set_enabled(should_enable_image_actions);
|
|
|
|
horizontal_flip_action->set_enabled(should_enable_image_actions);
|
|
|
|
desktop_wallpaper_action->set_enabled(should_enable_image_actions);
|
2021-09-03 21:36:13 +03:00
|
|
|
|
|
|
|
go_first_action->set_enabled(should_enable_backward_actions);
|
|
|
|
go_back_action->set_enabled(should_enable_backward_actions);
|
|
|
|
go_forward_action->set_enabled(should_enable_forward_actions);
|
|
|
|
go_last_action->set_enabled(should_enable_forward_actions);
|
|
|
|
|
2021-05-16 11:01:29 +03:00
|
|
|
zoom_in_action->set_enabled(should_enable_image_actions);
|
|
|
|
reset_zoom_action->set_enabled(should_enable_image_actions);
|
|
|
|
zoom_out_action->set_enabled(should_enable_image_actions);
|
|
|
|
if (!should_enable_image_actions) {
|
|
|
|
window->set_title("Image Viewer");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
(void)TRY(main_toolbar->try_add_action(open_action));
|
|
|
|
(void)TRY(main_toolbar->try_add_action(delete_action));
|
|
|
|
(void)TRY(main_toolbar->try_add_separator());
|
|
|
|
(void)TRY(main_toolbar->try_add_action(go_first_action));
|
|
|
|
(void)TRY(main_toolbar->try_add_action(go_back_action));
|
|
|
|
(void)TRY(main_toolbar->try_add_action(go_forward_action));
|
|
|
|
(void)TRY(main_toolbar->try_add_action(go_last_action));
|
|
|
|
(void)TRY(main_toolbar->try_add_separator());
|
|
|
|
(void)TRY(main_toolbar->try_add_action(zoom_in_action));
|
|
|
|
(void)TRY(main_toolbar->try_add_action(reset_zoom_action));
|
|
|
|
(void)TRY(main_toolbar->try_add_action(zoom_out_action));
|
|
|
|
|
|
|
|
auto file_menu = TRY(window->try_add_menu("&File"));
|
|
|
|
TRY(file_menu->try_add_action(open_action));
|
|
|
|
TRY(file_menu->try_add_action(delete_action));
|
|
|
|
TRY(file_menu->try_add_separator());
|
|
|
|
TRY(file_menu->try_add_action(quit_action));
|
|
|
|
|
|
|
|
auto image_menu = TRY(window->try_add_menu("&Image"));
|
|
|
|
TRY(image_menu->try_add_action(rotate_left_action));
|
|
|
|
TRY(image_menu->try_add_action(rotate_right_action));
|
|
|
|
TRY(image_menu->try_add_action(vertical_flip_action));
|
|
|
|
TRY(image_menu->try_add_action(horizontal_flip_action));
|
|
|
|
TRY(image_menu->try_add_separator());
|
|
|
|
TRY(image_menu->try_add_action(desktop_wallpaper_action));
|
|
|
|
|
|
|
|
auto navigate_menu = TRY(window->try_add_menu("&Navigate"));
|
|
|
|
TRY(navigate_menu->try_add_action(go_first_action));
|
|
|
|
TRY(navigate_menu->try_add_action(go_back_action));
|
|
|
|
TRY(navigate_menu->try_add_action(go_forward_action));
|
|
|
|
TRY(navigate_menu->try_add_action(go_last_action));
|
|
|
|
|
|
|
|
auto view_menu = TRY(window->try_add_menu("&View"));
|
|
|
|
TRY(view_menu->try_add_action(full_screen_action));
|
|
|
|
TRY(view_menu->try_add_separator());
|
|
|
|
TRY(view_menu->try_add_action(zoom_in_action));
|
|
|
|
TRY(view_menu->try_add_action(reset_zoom_action));
|
|
|
|
TRY(view_menu->try_add_action(zoom_out_action));
|
|
|
|
TRY(view_menu->try_add_separator());
|
|
|
|
|
|
|
|
auto scaling_mode_menu = TRY(view_menu->try_add_submenu("&Scaling Mode"));
|
2021-12-29 18:37:04 +03:00
|
|
|
|
|
|
|
auto scaling_mode_group = make<GUI::ActionGroup>();
|
|
|
|
scaling_mode_group->set_exclusive(true);
|
|
|
|
scaling_mode_group->add_action(*nearest_neighbor_action);
|
|
|
|
scaling_mode_group->add_action(*bilinear_action);
|
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
TRY(scaling_mode_menu->try_add_action(nearest_neighbor_action));
|
|
|
|
TRY(scaling_mode_menu->try_add_action(bilinear_action));
|
2021-12-29 18:37:04 +03:00
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
TRY(view_menu->try_add_separator());
|
|
|
|
TRY(view_menu->try_add_action(hide_show_toolbar_action));
|
2020-04-12 16:24:31 +03:00
|
|
|
|
2021-12-30 00:19:48 +03:00
|
|
|
auto help_menu = TRY(window->try_add_menu("&Help"));
|
|
|
|
TRY(help_menu->try_add_action(GUI::CommonActions::make_help_action([](auto&) {
|
2021-05-14 19:34:44 +03:00
|
|
|
Desktop::Launcher::open(URL::create_with_file_protocol("/usr/share/man/man1/ImageViewer.md"), "/bin/Help");
|
2021-12-30 00:19:48 +03:00
|
|
|
})));
|
|
|
|
TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Image Viewer", app_icon, window)));
|
2020-04-05 21:25:14 +03:00
|
|
|
|
2020-04-12 16:24:13 +03:00
|
|
|
if (path != nullptr) {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->load_from_file(path);
|
2021-05-16 11:01:29 +03:00
|
|
|
} else {
|
2021-12-30 00:19:48 +03:00
|
|
|
widget->clear();
|
2020-04-12 16:24:13 +03:00
|
|
|
}
|
|
|
|
|
2019-03-21 05:57:42 +03:00
|
|
|
window->show();
|
|
|
|
|
2020-07-04 15:05:19 +03:00
|
|
|
return app->exec();
|
2019-03-21 05:57:42 +03:00
|
|
|
}
|