mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
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.
This commit is contained in:
parent
1379720742
commit
d7f348ab50
5 changed files with 42 additions and 0 deletions
|
@ -45,6 +45,12 @@ void VideoFrameWidget::mousedown_event(GUI::MouseEvent&)
|
||||||
on_click();
|
on_click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoFrameWidget::doubleclick_event(GUI::MouseEvent&)
|
||||||
|
{
|
||||||
|
if (on_doubleclick)
|
||||||
|
on_doubleclick();
|
||||||
|
}
|
||||||
|
|
||||||
void VideoFrameWidget::paint_event(GUI::PaintEvent& event)
|
void VideoFrameWidget::paint_event(GUI::PaintEvent& event)
|
||||||
{
|
{
|
||||||
Frame::paint_event(event);
|
Frame::paint_event(event);
|
||||||
|
|
|
@ -35,11 +35,13 @@ public:
|
||||||
bool auto_resize() const { return m_auto_resize; }
|
bool auto_resize() const { return m_auto_resize; }
|
||||||
|
|
||||||
Function<void()> on_click;
|
Function<void()> on_click;
|
||||||
|
Function<void()> on_doubleclick;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit VideoFrameWidget();
|
explicit VideoFrameWidget();
|
||||||
|
|
||||||
virtual void mousedown_event(GUI::MouseEvent&) override;
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||||
|
virtual void doubleclick_event(GUI::MouseEvent&) override;
|
||||||
virtual void paint_event(GUI::PaintEvent&) override;
|
virtual void paint_event(GUI::PaintEvent&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -35,6 +35,7 @@ ErrorOr<void> VideoPlayerWidget::setup_interface()
|
||||||
{
|
{
|
||||||
m_video_display = find_descendant_of_type_named<VideoPlayer::VideoFrameWidget>("video_frame");
|
m_video_display = find_descendant_of_type_named<VideoPlayer::VideoFrameWidget>("video_frame");
|
||||||
m_video_display->on_click = [&]() { toggle_pause(); };
|
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 = find_descendant_of_type_named<GUI::HorizontalSlider>("seek_slider");
|
||||||
m_seek_slider->on_drag_start = [&]() {
|
m_seek_slider->on_drag_start = [&]() {
|
||||||
|
@ -72,10 +73,15 @@ ErrorOr<void> VideoPlayerWidget::setup_interface()
|
||||||
cycle_sizing_modes();
|
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_timestamp_label = find_descendant_of_type_named<GUI::Label>("timestamp");
|
||||||
m_volume_slider = find_descendant_of_type_named<GUI::HorizontalSlider>("volume_slider");
|
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>("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>("sizing")->set_action(*m_cycle_sizing_modes_action);
|
||||||
|
find_descendant_of_type_named<GUI::Button>("fullscreen")->set_action(*m_toggle_fullscreen_action);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -250,6 +256,16 @@ void VideoPlayerWidget::cycle_sizing_modes()
|
||||||
m_video_display->update();
|
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()
|
void VideoPlayerWidget::update_title()
|
||||||
{
|
{
|
||||||
StringBuilder string_builder;
|
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));
|
TRY(playback_menu->try_add_action(*m_use_fast_seeking));
|
||||||
set_seek_mode(Video::PlaybackManager::DEFAULT_SEEK_MODE);
|
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
|
// Help menu
|
||||||
auto help_menu = TRY(window.try_add_menu("&Help"));
|
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)));
|
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)));
|
||||||
|
|
|
@ -49,6 +49,8 @@ private:
|
||||||
|
|
||||||
void cycle_sizing_modes();
|
void cycle_sizing_modes();
|
||||||
|
|
||||||
|
void toggle_fullscreen();
|
||||||
|
|
||||||
void event(Core::Event&) override;
|
void event(Core::Event&) override;
|
||||||
|
|
||||||
DeprecatedString m_path;
|
DeprecatedString m_path;
|
||||||
|
@ -66,6 +68,8 @@ private:
|
||||||
|
|
||||||
RefPtr<GUI::Action> m_use_fast_seeking;
|
RefPtr<GUI::Action> m_use_fast_seeking;
|
||||||
|
|
||||||
|
RefPtr<GUI::Action> m_toggle_fullscreen_action;
|
||||||
|
|
||||||
OwnPtr<Video::PlaybackManager> m_playback_manager;
|
OwnPtr<Video::PlaybackManager> m_playback_manager;
|
||||||
|
|
||||||
bool m_was_playing_before_seek { false };
|
bool m_was_playing_before_seek { false };
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::Widget {
|
@GUI::Widget {
|
||||||
|
name: "bottom_container"
|
||||||
max_height: 50
|
max_height: 50
|
||||||
layout: @GUI::VerticalBoxLayout {}
|
layout: @GUI::VerticalBoxLayout {}
|
||||||
|
|
||||||
|
@ -53,6 +54,15 @@
|
||||||
max: 100
|
max: 100
|
||||||
fixed_width: 100
|
fixed_width: 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GUI::VerticalSeparator {}
|
||||||
|
|
||||||
|
@GUI::Button {
|
||||||
|
name: "fullscreen"
|
||||||
|
icon: "/res/icons/16x16/fullscreen.png"
|
||||||
|
fixed_width: 24
|
||||||
|
button_style: "Coolbar"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue