mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
VideoPlayer: Port to GML
This commit is contained in:
parent
f0a33b2a8e
commit
f63ecc2763
7 changed files with 95 additions and 42 deletions
|
@ -15,29 +15,28 @@
|
|||
#include <LibGUI/Toolbar.h>
|
||||
#include <LibGUI/ToolbarContainer.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <Userland/Applications/VideoPlayer/VideoPlayerWindowGML.h>
|
||||
|
||||
#include "VideoPlayerWidget.h"
|
||||
|
||||
namespace VideoPlayer {
|
||||
|
||||
VideoPlayerWidget::VideoPlayerWidget(GUI::Window& window)
|
||||
: m_window(window)
|
||||
ErrorOr<NonnullRefPtr<VideoPlayerWidget>> VideoPlayerWidget::try_create()
|
||||
{
|
||||
set_fill_with_background_color(true);
|
||||
auto main_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) VideoPlayerWidget()));
|
||||
TRY(main_widget->load_from_gml(videoplayer_window_gml));
|
||||
|
||||
set_layout<GUI::VerticalBoxLayout>();
|
||||
TRY(main_widget->setup_interface());
|
||||
|
||||
m_video_display = add<VideoFrameWidget>();
|
||||
m_video_display->set_auto_resize(false);
|
||||
return main_widget;
|
||||
}
|
||||
|
||||
ErrorOr<void> VideoPlayerWidget::setup_interface()
|
||||
{
|
||||
m_video_display = find_descendant_of_type_named<VideoPlayer::VideoFrameWidget>("video_frame");
|
||||
m_video_display->on_click = [&]() { toggle_pause(); };
|
||||
|
||||
auto& player_controls_widget = add<GUI::Widget>();
|
||||
player_controls_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
player_controls_widget.set_max_height(50);
|
||||
|
||||
m_seek_slider = player_controls_widget.add<GUI::HorizontalSlider>();
|
||||
m_seek_slider->set_fixed_height(20);
|
||||
m_seek_slider->set_enabled(false);
|
||||
m_seek_slider = find_descendant_of_type_named<GUI::HorizontalSlider>("seek_slider");
|
||||
m_seek_slider->on_change = [&](int value) {
|
||||
if (!m_playback_manager)
|
||||
return;
|
||||
|
@ -48,13 +47,9 @@ VideoPlayerWidget::VideoPlayerWidget(GUI::Window& window)
|
|||
set_current_timestamp(timestamp);
|
||||
m_playback_manager->seek_to_timestamp(timestamp);
|
||||
};
|
||||
m_seek_slider->set_jump_to_cursor(true);
|
||||
|
||||
auto& toolbar_container = player_controls_widget.add<GUI::ToolbarContainer>();
|
||||
m_toolbar = toolbar_container.add<GUI::Toolbar>();
|
||||
|
||||
m_play_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
m_pause_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
m_play_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png"sv));
|
||||
m_pause_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png"sv));
|
||||
|
||||
m_play_pause_action = GUI::Action::create("Play", { Key_Space }, m_play_icon, [&](auto&) {
|
||||
toggle_pause();
|
||||
|
@ -64,20 +59,12 @@ VideoPlayerWidget::VideoPlayerWidget(GUI::Window& window)
|
|||
cycle_sizing_modes();
|
||||
});
|
||||
|
||||
m_toolbar->add_action(*m_play_pause_action);
|
||||
m_toolbar->add<GUI::VerticalSeparator>();
|
||||
m_timestamp_label = m_toolbar->add<GUI::Label>();
|
||||
m_timestamp_label->set_autosize(true);
|
||||
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);
|
||||
|
||||
m_toolbar->add<GUI::Widget>(); // Filler widget
|
||||
|
||||
m_toolbar->add_action(*m_cycle_sizing_modes_action);
|
||||
|
||||
m_toolbar->add<GUI::VerticalSeparator>();
|
||||
m_volume_slider = m_toolbar->add<GUI::HorizontalSlider>();
|
||||
m_volume_slider->set_min(0);
|
||||
m_volume_slider->set_max(100);
|
||||
m_volume_slider->set_fixed_width(100);
|
||||
return {};
|
||||
}
|
||||
|
||||
void VideoPlayerWidget::close_file()
|
||||
|
@ -176,7 +163,7 @@ void VideoPlayerWidget::on_decoding_error(Video::DecoderError const& error)
|
|||
break;
|
||||
}
|
||||
|
||||
GUI::MessageBox::show(&m_window, DeprecatedString::formatted(text_format, error.string_literal()), "Video Player encountered an error"sv);
|
||||
GUI::MessageBox::show(window(), DeprecatedString::formatted(text_format, error.string_literal()), "Video Player encountered an error"sv);
|
||||
}
|
||||
|
||||
void VideoPlayerWidget::update_seek_slider_max()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue