diff --git a/Userland/Applications/VideoPlayer/CMakeLists.txt b/Userland/Applications/VideoPlayer/CMakeLists.txt index ab6d043e17..86844c266d 100644 --- a/Userland/Applications/VideoPlayer/CMakeLists.txt +++ b/Userland/Applications/VideoPlayer/CMakeLists.txt @@ -4,11 +4,17 @@ serenity_component( DEPENDS AudioServer ) +compile_gml(VideoPlayerWindow.gml VideoPlayerWindowGML.h videoplayer_window_gml) + set(SOURCES main.cpp VideoFrameWidget.cpp VideoPlayerWidget.cpp ) +set(GENERATED_SOURCES + VideoPlayerWindowGML.h +) + serenity_app(VideoPlayer ICON app-video-player) target_link_libraries(VideoPlayer PRIVATE LibVideo LibAudio LibCore LibGfx LibGUI LibMain) diff --git a/Userland/Applications/VideoPlayer/VideoFrameWidget.cpp b/Userland/Applications/VideoPlayer/VideoFrameWidget.cpp index 25e68f59f6..a1602c1e9e 100644 --- a/Userland/Applications/VideoPlayer/VideoFrameWidget.cpp +++ b/Userland/Applications/VideoPlayer/VideoFrameWidget.cpp @@ -9,10 +9,13 @@ #include "VideoFrameWidget.h" +REGISTER_WIDGET(VideoPlayer, VideoFrameWidget); + namespace VideoPlayer { VideoFrameWidget::VideoFrameWidget() { + REGISTER_BOOL_PROPERTY("auto_resize", auto_resize, set_auto_resize); set_auto_resize(true); } diff --git a/Userland/Applications/VideoPlayer/VideoFrameWidget.h b/Userland/Applications/VideoPlayer/VideoFrameWidget.h index 608c9eeeab..77e9cef746 100644 --- a/Userland/Applications/VideoPlayer/VideoFrameWidget.h +++ b/Userland/Applications/VideoPlayer/VideoFrameWidget.h @@ -20,7 +20,7 @@ enum class VideoSizingMode : u8 { Sentinel }; -class VideoFrameWidget : public GUI::Frame { +class VideoFrameWidget final : public GUI::Frame { C_OBJECT(VideoFrameWidget) public: virtual ~VideoFrameWidget() override = default; diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp index 0901b9e836..09f193a7b4 100644 --- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp +++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp @@ -15,29 +15,28 @@ #include #include #include +#include #include "VideoPlayerWidget.h" namespace VideoPlayer { -VideoPlayerWidget::VideoPlayerWidget(GUI::Window& window) - : m_window(window) +ErrorOr> 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(); + TRY(main_widget->setup_interface()); - m_video_display = add(); - m_video_display->set_auto_resize(false); + return main_widget; +} + +ErrorOr VideoPlayerWidget::setup_interface() +{ + m_video_display = find_descendant_of_type_named("video_frame"); m_video_display->on_click = [&]() { toggle_pause(); }; - auto& player_controls_widget = add(); - player_controls_widget.set_layout(); - player_controls_widget.set_max_height(50); - - m_seek_slider = player_controls_widget.add(); - m_seek_slider->set_fixed_height(20); - m_seek_slider->set_enabled(false); + m_seek_slider = find_descendant_of_type_named("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(); - m_toolbar = toolbar_container.add(); - - 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(); - m_timestamp_label = m_toolbar->add(); - m_timestamp_label->set_autosize(true); + m_timestamp_label = find_descendant_of_type_named("timestamp"); + m_volume_slider = find_descendant_of_type_named("volume_slider"); + find_descendant_of_type_named("playback")->set_action(*m_play_pause_action); + find_descendant_of_type_named("sizing")->set_action(*m_cycle_sizing_modes_action); - m_toolbar->add(); // Filler widget - - m_toolbar->add_action(*m_cycle_sizing_modes_action); - - m_toolbar->add(); - m_volume_slider = m_toolbar->add(); - 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() diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h index a21a93a046..eb98bb87dd 100644 --- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h +++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h @@ -20,9 +20,11 @@ namespace VideoPlayer { class VideoPlayerWidget final : public GUI::Widget { - C_OBJECT(VideoPlayerWidget) + C_OBJECT_ABSTRACT(VideoPlayerWidget) public: + static ErrorOr> try_create(); + virtual ~VideoPlayerWidget() override = default; void close_file(); void open_file(StringView filename); void resume_playback(); @@ -37,8 +39,8 @@ public: ErrorOr initialize_menubar(GUI::Window&); private: - VideoPlayerWidget(GUI::Window&); - + VideoPlayerWidget() = default; + ErrorOr setup_interface(); void update_play_pause_icon(); void update_seek_slider_max(); void set_current_timestamp(Time); @@ -51,15 +53,11 @@ private: void event(Core::Event&) override; - GUI::Window& m_window; - DeprecatedString m_path; RefPtr m_video_display; RefPtr m_seek_slider; - RefPtr m_toolbar; - RefPtr m_play_icon; RefPtr m_pause_icon; diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWindow.gml b/Userland/Applications/VideoPlayer/VideoPlayerWindow.gml new file mode 100644 index 0000000000..cf38f5307c --- /dev/null +++ b/Userland/Applications/VideoPlayer/VideoPlayerWindow.gml @@ -0,0 +1,59 @@ +@GUI::Widget { + fill_with_background_color: true + layout: @GUI::VerticalBoxLayout {} + + @VideoPlayer::VideoFrameWidget { + name: "video_frame" + auto_resize: false + } + + @GUI::Widget { + max_height: 50 + layout: @GUI::VerticalBoxLayout {} + + @GUI::HorizontalSlider { + name: "seek_slider" + fixed_height: 20 + enabled: false + jump_to_cursor: true + } + + @GUI::ToolbarContainer { + @GUI::Toolbar { + name: "toolbar" + + @GUI::Button { + name: "playback" + icon: "/res/icons/16x16/play.png" + fixed_width: 24 + button_style: "Coolbar" + } + + @GUI::VerticalSeparator {} + + @GUI::Label { + name: "timestamp" + autosize: true + } + + @GUI::Layout::Spacer {} + + @GUI::Button { + name: "sizing" + text: "..." + fixed_width: 24 + button_style: "Coolbar" + } + + @GUI::VerticalSeparator {} + + @GUI::HorizontalSlider { + name: "volume_slider" + min: 0 + max: 100 + fixed_width: 100 + } + } + } + } +} diff --git a/Userland/Applications/VideoPlayer/main.cpp b/Userland/Applications/VideoPlayer/main.cpp index f09733a2d6..27e2a45adb 100644 --- a/Userland/Applications/VideoPlayer/main.cpp +++ b/Userland/Applications/VideoPlayer/main.cpp @@ -24,7 +24,7 @@ ErrorOr serenity_main(Main::Arguments arguments) window->resize(640, 480); window->set_resizable(true); - auto main_widget = TRY(window->set_main_widget(window)); + auto main_widget = TRY(window->set_main_widget()); main_widget->update_title(); TRY(main_widget->initialize_menubar(window));