diff options
author | timre13 <itorteli13@gmail.com> | 2023-02-24 18:18:01 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-24 19:16:46 +0100 |
commit | d7f348ab50f10bc06cfe2420bf0b10616ecc3c2a (patch) | |
tree | e301606243a1c46a16d18731aab6c1ef8c359251 /Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp | |
parent | 137972074277f0e782728d98267970dd5247cab1 (diff) | |
download | serenity-d7f348ab50f10bc06cfe2420bf0b10616ecc3c2a.zip |
VideoPlayer: Add button and menu item to toggle fullscreen
Add a button to the bottom toolbar and a menu item to toggle fullscreen.
Also implement toggling fullscreen mode by double-clicking the video.
Diffstat (limited to 'Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp')
-rw-r--r-- | Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp index 57e7ffe51d..ec17ebd676 100644 --- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp +++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp @@ -35,6 +35,7 @@ ErrorOr<void> VideoPlayerWidget::setup_interface() { m_video_display = find_descendant_of_type_named<VideoPlayer::VideoFrameWidget>("video_frame"); m_video_display->on_click = [&]() { toggle_pause(); }; + m_video_display->on_doubleclick = [&]() { toggle_fullscreen(); }; m_seek_slider = find_descendant_of_type_named<GUI::HorizontalSlider>("seek_slider"); m_seek_slider->on_drag_start = [&]() { @@ -72,10 +73,15 @@ ErrorOr<void> VideoPlayerWidget::setup_interface() cycle_sizing_modes(); }); + m_toggle_fullscreen_action = GUI::CommonActions::make_fullscreen_action([&](auto&) { + toggle_fullscreen(); + }); + m_timestamp_label = find_descendant_of_type_named<GUI::Label>("timestamp"); m_volume_slider = find_descendant_of_type_named<GUI::HorizontalSlider>("volume_slider"); find_descendant_of_type_named<GUI::Button>("playback")->set_action(*m_play_pause_action); find_descendant_of_type_named<GUI::Button>("sizing")->set_action(*m_cycle_sizing_modes_action); + find_descendant_of_type_named<GUI::Button>("fullscreen")->set_action(*m_toggle_fullscreen_action); return {}; } @@ -250,6 +256,16 @@ void VideoPlayerWidget::cycle_sizing_modes() m_video_display->update(); } +void VideoPlayerWidget::toggle_fullscreen() +{ + auto* parent_window = window(); + parent_window->set_fullscreen(!parent_window->is_fullscreen()); + auto* bottom_container = find_descendant_of_type_named<GUI::Widget>("bottom_container"); + bottom_container->set_visible(!parent_window->is_fullscreen()); + auto* video_frame = find_descendant_of_type_named<VideoFrameWidget>("video_frame"); + video_frame->set_frame_thickness(parent_window->is_fullscreen() ? 0 : 2); +} + void VideoPlayerWidget::update_title() { StringBuilder string_builder; @@ -298,6 +314,10 @@ ErrorOr<void> VideoPlayerWidget::initialize_menubar(GUI::Window& window) TRY(playback_menu->try_add_action(*m_use_fast_seeking)); set_seek_mode(Video::PlaybackManager::DEFAULT_SEEK_MODE); + // View menu + auto view_menu = TRY(window.try_add_menu("&View")); + TRY(view_menu->try_add_action(*m_toggle_fullscreen_action)); + // Help menu auto help_menu = TRY(window.try_add_menu("&Help")); TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Video Player", TRY(GUI::Icon::try_create_default_icon("app-video-player"sv)), &window))); |