From ccced92ac2213e852df9903b6746f5e1d0cca6ea Mon Sep 17 00:00:00 2001 From: Elyse Date: Sat, 30 Oct 2021 21:49:46 -0500 Subject: [PATCH] SoundPlayer: Make 'volume_slider' a member variable This change will allow us to modify the volume slider from any event inside the widget. --- .../SoundPlayer/SoundPlayerWidgetAdvancedView.cpp | 12 ++++++------ .../SoundPlayer/SoundPlayerWidgetAdvancedView.h | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp index a66654b364..68b7694092 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp @@ -102,13 +102,13 @@ SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window m_volume_label = &menubar.add(); m_volume_label->set_fixed_width(30); - auto& volume_slider = menubar.add(); - volume_slider.set_fixed_width(95); - volume_slider.set_min(0); - volume_slider.set_max(150); - volume_slider.set_value(100); + m_volume_slider = &menubar.add(); + m_volume_slider->set_fixed_width(95); + m_volume_slider->set_min(0); + m_volume_slider->set_max(150); + m_volume_slider->set_value(100); - volume_slider.on_change = [&](int value) { + m_volume_slider->on_change = [&](int value) { double volume = m_nonlinear_volume_slider ? (double)(value * value) / (100 * 100) : value / 100.; set_volume(volume); }; diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h index e8198f7eca..f73297c113 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h @@ -73,6 +73,7 @@ private: RefPtr m_next_button; RefPtr m_playback_progress_slider; RefPtr m_volume_label; + RefPtr m_volume_slider; RefPtr m_timestamp_label; bool m_nonlinear_volume_slider;