diff options
author | Zaggy1024 <zaggy1024@gmail.com> | 2023-02-05 19:20:03 -0600 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2023-02-07 14:36:58 +0000 |
commit | 3a1efbb9e4e599e20050cd21324eb83ccc73a2c5 (patch) | |
tree | fc1319bc9e9eefb0c1c9864ea802ea1d3be7744f /Userland/Applications | |
parent | 9e61e48b318d53f85865b5206f4bb0e545f00990 (diff) | |
download | serenity-3a1efbb9e4e599e20050cd21324eb83ccc73a2c5.zip |
SoundPlayer: Remove AutoSlider for the seek bar in favor of Slider
Diffstat (limited to 'Userland/Applications')
3 files changed, 11 insertions, 58 deletions
diff --git a/Userland/Applications/SoundPlayer/Common.h b/Userland/Applications/SoundPlayer/Common.h deleted file mode 100644 index 06c5309e2b..0000000000 --- a/Userland/Applications/SoundPlayer/Common.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021, Cesar Torres <shortanemoia@protonmail.com> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <LibGUI/Slider.h> - -class AutoSlider final : public GUI::Slider { - C_OBJECT(AutoSlider) -public: - ~AutoSlider() override = default; - Function<void(int)> on_knob_released; - virtual void set_value(int value, GUI::AllowCallback allow_callback = GUI::AllowCallback::Yes, DoClamp do_clamp = DoClamp::Yes) override - { - m_in_drag_value = value; - if (!knob_dragging() && !mouse_is_down()) - GUI::Slider::set_value(value, allow_callback, do_clamp); - } - - bool mouse_is_down() const { return m_mouse_is_down; } - -private: - AutoSlider(Orientation orientation) - : GUI::Slider(orientation) - { - } - - virtual void mousedown_event(GUI::MouseEvent& event) override - { - m_mouse_is_down = true; - GUI::Slider::mousedown_event(event); - } - - virtual void mouseup_event(GUI::MouseEvent& event) override - { - m_mouse_is_down = false; - set_value(m_in_drag_value); - if (on_knob_released && is_enabled()) - on_knob_released(value()); - - GUI::Slider::mouseup_event(event); - } - - bool m_mouse_is_down { false }; - // Keeps track of the value while we're dragging - int m_in_drag_value { 0 }; -}; diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp index 8e26933c5e..2192d0e50f 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp @@ -7,7 +7,6 @@ #include "SoundPlayerWidgetAdvancedView.h" #include "BarsVisualizationWidget.h" -#include "Common.h" #include "M3UParser.h" #include "PlaybackManager.h" #include <AK/LexicalPath.h> @@ -50,12 +49,16 @@ SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window m_visualization = m_player_view->add<BarsVisualizationWidget>(); - m_playback_progress_slider = m_player_view->add<AutoSlider>(Orientation::Horizontal); + m_playback_progress_slider = m_player_view->add<GUI::HorizontalSlider>(); m_playback_progress_slider->set_fixed_height(20); m_playback_progress_slider->set_jump_to_cursor(true); m_playback_progress_slider->set_min(0); - m_playback_progress_slider->on_knob_released = [&](int value) { - seek(value); + m_playback_progress_slider->on_change = [&](int value) { + if (!m_playback_progress_slider->knob_dragging()) + seek(value); + }; + m_playback_progress_slider->on_drag_end = [&]() { + seek(m_playback_progress_slider->value()); }; auto& toolbar_container = m_player_view->add<GUI::ToolbarContainer>(); @@ -219,8 +222,8 @@ void SoundPlayerWidgetAdvancedView::sound_buffer_played(FixedArray<Audio::Sample m_visualization->set_buffer(buffer); m_visualization->set_samplerate(sample_rate); // If the user is currently dragging the slider, don't interfere. - if (!m_playback_progress_slider->mouse_is_down()) - m_playback_progress_slider->set_value(samples_played); + if (!m_playback_progress_slider->knob_dragging()) + m_playback_progress_slider->set_value(samples_played, GUI::AllowCallback::No); } void SoundPlayerWidgetAdvancedView::volume_changed(double volume) diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h index e17fb0f4ed..e86528994f 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h @@ -7,13 +7,13 @@ #pragma once -#include "Common.h" #include "PlaybackManager.h" #include "Player.h" #include "VisualizationWidget.h" #include <AK/FixedArray.h> #include <AK/NonnullRefPtr.h> #include <LibAudio/ConnectionToServer.h> +#include <LibGUI/Slider.h> #include <LibGUI/Splitter.h> #include <LibGUI/Widget.h> @@ -77,7 +77,7 @@ private: RefPtr<GUI::Action> m_back_action; RefPtr<GUI::Action> m_next_action; - RefPtr<AutoSlider> m_playback_progress_slider; + RefPtr<GUI::HorizontalSlider> m_playback_progress_slider; RefPtr<GUI::Label> m_volume_label; RefPtr<GUI::HorizontalSlider> m_volume_slider; RefPtr<GUI::Label> m_timestamp_label; |