mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:32:44 +00:00 
			
		
		
		
	VideoPlayer: Create submenu to set sizing mode
Also add icon to the sizing mode cycling button.
This commit is contained in:
		
							parent
							
								
									b33b950e45
								
							
						
					
					
						commit
						eef07a411b
					
				
					 5 changed files with 74 additions and 6 deletions
				
			
		|  | @ -31,6 +31,15 @@ void VideoFrameWidget::set_bitmap(Gfx::Bitmap const* bitmap) | ||||||
|     update(); |     update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void VideoFrameWidget::set_sizing_mode(VideoSizingMode value) | ||||||
|  | { | ||||||
|  |     if (value == m_sizing_mode) | ||||||
|  |         return; | ||||||
|  |     m_sizing_mode = value; | ||||||
|  | 
 | ||||||
|  |     update(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void VideoFrameWidget::set_auto_resize(bool value) | void VideoFrameWidget::set_auto_resize(bool value) | ||||||
| { | { | ||||||
|     m_auto_resize = value; |     m_auto_resize = value; | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ public: | ||||||
|     void set_bitmap(Gfx::Bitmap const*); |     void set_bitmap(Gfx::Bitmap const*); | ||||||
|     Gfx::Bitmap const* bitmap() const { return m_bitmap.ptr(); } |     Gfx::Bitmap const* bitmap() const { return m_bitmap.ptr(); } | ||||||
| 
 | 
 | ||||||
|     void set_sizing_mode(VideoSizingMode value) { m_sizing_mode = value; } |     void set_sizing_mode(VideoSizingMode value); | ||||||
|     VideoSizingMode sizing_mode() const { return m_sizing_mode; } |     VideoSizingMode sizing_mode() const { return m_sizing_mode; } | ||||||
| 
 | 
 | ||||||
|     void set_auto_resize(bool value); |     void set_auto_resize(bool value); | ||||||
|  |  | ||||||
|  | @ -69,9 +69,10 @@ ErrorOr<void> VideoPlayerWidget::setup_interface() | ||||||
|         toggle_pause(); |         toggle_pause(); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     m_cycle_sizing_modes_action = GUI::Action::create("Sizing", [&](auto&) { |     m_cycle_sizing_modes_action = GUI::Action::create( | ||||||
|         cycle_sizing_modes(); |         "Sizing", TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/fit-image-to-view.png"sv)), [&](auto&) { | ||||||
|     }); |             cycle_sizing_modes(); | ||||||
|  |         }); | ||||||
| 
 | 
 | ||||||
|     m_toggle_fullscreen_action = GUI::CommonActions::make_fullscreen_action([&](auto&) { |     m_toggle_fullscreen_action = GUI::CommonActions::make_fullscreen_action([&](auto&) { | ||||||
|         toggle_fullscreen(); |         toggle_fullscreen(); | ||||||
|  | @ -83,6 +84,22 @@ ErrorOr<void> VideoPlayerWidget::setup_interface() | ||||||
|     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); |     find_descendant_of_type_named<GUI::Button>("fullscreen")->set_action(*m_toggle_fullscreen_action); | ||||||
| 
 | 
 | ||||||
|  |     m_size_fit_action = GUI::Action::create_checkable("&Fit", [&](auto&) { | ||||||
|  |         m_video_display->set_sizing_mode(VideoSizingMode::Fit); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     m_size_fill_action = GUI::Action::create_checkable("Fi&ll", [&](auto&) { | ||||||
|  |         m_video_display->set_sizing_mode(VideoSizingMode::Fill); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     m_size_stretch_action = GUI::Action::create_checkable("&Stretch", [&](auto&) { | ||||||
|  |         m_video_display->set_sizing_mode(VideoSizingMode::Stretch); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     m_size_fullsize_action = GUI::Action::create_checkable("F&ull Size", [&](auto&) { | ||||||
|  |         m_video_display->set_sizing_mode(VideoSizingMode::FullSize); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -253,7 +270,27 @@ void VideoPlayerWidget::cycle_sizing_modes() | ||||||
|     auto sizing_mode = m_video_display->sizing_mode(); |     auto sizing_mode = m_video_display->sizing_mode(); | ||||||
|     sizing_mode = static_cast<VideoSizingMode>((to_underlying(sizing_mode) + 1) % to_underlying(VideoSizingMode::Sentinel)); |     sizing_mode = static_cast<VideoSizingMode>((to_underlying(sizing_mode) + 1) % to_underlying(VideoSizingMode::Sentinel)); | ||||||
|     m_video_display->set_sizing_mode(sizing_mode); |     m_video_display->set_sizing_mode(sizing_mode); | ||||||
|     m_video_display->update(); | 
 | ||||||
|  |     switch (sizing_mode) { | ||||||
|  |     case VideoSizingMode::Fit: | ||||||
|  |         m_size_fit_action->set_checked(true); | ||||||
|  |         break; | ||||||
|  | 
 | ||||||
|  |     case VideoSizingMode::Fill: | ||||||
|  |         m_size_fill_action->set_checked(true); | ||||||
|  |         break; | ||||||
|  | 
 | ||||||
|  |     case VideoSizingMode::Stretch: | ||||||
|  |         m_size_stretch_action->set_checked(true); | ||||||
|  |         break; | ||||||
|  | 
 | ||||||
|  |     case VideoSizingMode::FullSize: | ||||||
|  |         m_size_fullsize_action->set_checked(true); | ||||||
|  |         break; | ||||||
|  | 
 | ||||||
|  |     case VideoSizingMode::Sentinel: | ||||||
|  |         break; | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void VideoPlayerWidget::toggle_fullscreen() | void VideoPlayerWidget::toggle_fullscreen() | ||||||
|  | @ -318,6 +355,22 @@ ErrorOr<void> VideoPlayerWidget::initialize_menubar(GUI::Window& window) | ||||||
|     auto view_menu = TRY(window.try_add_menu("&View")); |     auto view_menu = TRY(window.try_add_menu("&View")); | ||||||
|     TRY(view_menu->try_add_action(*m_toggle_fullscreen_action)); |     TRY(view_menu->try_add_action(*m_toggle_fullscreen_action)); | ||||||
| 
 | 
 | ||||||
|  |     auto sizing_mode_menu = TRY(view_menu->try_add_submenu("&Sizing mode")); | ||||||
|  |     sizing_mode_menu->set_icon(TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/fit-image-to-view.png"sv))); | ||||||
|  | 
 | ||||||
|  |     m_sizing_mode_group = make<GUI::ActionGroup>(); | ||||||
|  |     m_sizing_mode_group->set_exclusive(true); | ||||||
|  |     m_sizing_mode_group->add_action(*m_size_fit_action); | ||||||
|  |     m_sizing_mode_group->add_action(*m_size_fill_action); | ||||||
|  |     m_sizing_mode_group->add_action(*m_size_stretch_action); | ||||||
|  |     m_sizing_mode_group->add_action(*m_size_fullsize_action); | ||||||
|  |     m_size_fit_action->set_checked(true); | ||||||
|  | 
 | ||||||
|  |     TRY(sizing_mode_menu->try_add_action(*m_size_fit_action)); | ||||||
|  |     TRY(sizing_mode_menu->try_add_action(*m_size_fill_action)); | ||||||
|  |     TRY(sizing_mode_menu->try_add_action(*m_size_stretch_action)); | ||||||
|  |     TRY(sizing_mode_menu->try_add_action(*m_size_fullsize_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))); | ||||||
|  |  | ||||||
|  | @ -70,6 +70,12 @@ private: | ||||||
| 
 | 
 | ||||||
|     RefPtr<GUI::Action> m_toggle_fullscreen_action; |     RefPtr<GUI::Action> m_toggle_fullscreen_action; | ||||||
| 
 | 
 | ||||||
|  |     OwnPtr<GUI::ActionGroup> m_sizing_mode_group; | ||||||
|  |     RefPtr<GUI::Action> m_size_fit_action; | ||||||
|  |     RefPtr<GUI::Action> m_size_fill_action; | ||||||
|  |     RefPtr<GUI::Action> m_size_stretch_action; | ||||||
|  |     RefPtr<GUI::Action> m_size_fullsize_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 }; | ||||||
|  |  | ||||||
|  | @ -41,7 +41,7 @@ | ||||||
| 
 | 
 | ||||||
|                 @GUI::Button { |                 @GUI::Button { | ||||||
|                     name: "sizing" |                     name: "sizing" | ||||||
|                     text: "..." |                     icon: "/res/icons/16x16/fit-image-to-view.png" | ||||||
|                     fixed_width: 24 |                     fixed_width: 24 | ||||||
|                     button_style: "Coolbar" |                     button_style: "Coolbar" | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 timre13
						timre13