From 60908adcbe2afd611233957bb3126f736eb18e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Oppeb=C3=B8en?= Date: Tue, 28 Feb 2023 22:52:43 +0100 Subject: [PATCH] SoundPlayer: Add action with icon for toggling mute This adds a button on the menubar next to the volume slider to indicate mute state and allow toggling the mute. Pressing the M key will still toggle the mute, as before. When muted, the volume scroll bar now gets disabled. --- .../SoundPlayerWidgetAdvancedView.cpp | 17 ++++++++++++----- .../SoundPlayer/SoundPlayerWidgetAdvancedView.h | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp index 2192d0e50f..c3fe2f1f19 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp @@ -46,6 +46,8 @@ SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window m_stop_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/stop.png"sv).release_value_but_fixme_should_propagate_errors(); m_back_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"sv).release_value_but_fixme_should_propagate_errors(); m_next_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"sv).release_value_but_fixme_should_propagate_errors(); + m_volume_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/audio-volume-medium.png"sv).release_value_but_fixme_should_propagate_errors(); + m_muted_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/audio-volume-muted.png"sv).release_value_but_fixme_should_propagate_errors(); m_visualization = m_player_view->add(); @@ -98,6 +100,12 @@ SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window menubar.add_separator(); + m_mute_action = GUI::Action::create("Mute", { Key_M }, m_volume_icon, [&](auto&) { + toggle_mute(); + }); + m_mute_action->set_enabled(true); + menubar.add_action(*m_mute_action); + m_volume_label = &menubar.add(); m_volume_label->set_fixed_width(30); @@ -145,9 +153,6 @@ void SoundPlayerWidgetAdvancedView::drop_event(GUI::DropEvent& event) void SoundPlayerWidgetAdvancedView::keydown_event(GUI::KeyEvent& event) { - if (event.key() == Key_M) - toggle_mute(); - if (event.key() == Key_Up) m_volume_slider->increase_slider_by_page_steps(1); @@ -184,9 +189,11 @@ void SoundPlayerWidgetAdvancedView::loop_mode_changed(Player::LoopMode) { } -void SoundPlayerWidgetAdvancedView::mute_changed(bool) +void SoundPlayerWidgetAdvancedView::mute_changed(bool muted) { - // FIXME: Update the volume slider when player is muted + m_mute_action->set_text(muted ? "Unmute"sv : "Mute"sv); + m_mute_action->set_icon(muted ? m_muted_icon : m_volume_icon); + m_volume_slider->set_enabled(!muted); } void SoundPlayerWidgetAdvancedView::sync_previous_next_actions() diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h index e86528994f..eb00456f5b 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h @@ -71,11 +71,14 @@ private: RefPtr m_stop_icon; RefPtr m_back_icon; RefPtr m_next_icon; + RefPtr m_volume_icon; + RefPtr m_muted_icon; RefPtr m_play_action; RefPtr m_stop_action; RefPtr m_back_action; RefPtr m_next_action; + RefPtr m_mute_action; RefPtr m_playback_progress_slider; RefPtr m_volume_label;