From 3a1efbb9e4e599e20050cd21324eb83ccc73a2c5 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sun, 5 Feb 2023 19:20:03 -0600 Subject: [PATCH] SoundPlayer: Remove AutoSlider for the seek bar in favor of Slider --- Userland/Applications/SoundPlayer/Common.h | 50 ------------------- .../SoundPlayerWidgetAdvancedView.cpp | 15 +++--- .../SoundPlayerWidgetAdvancedView.h | 4 +- 3 files changed, 11 insertions(+), 58 deletions(-) delete mode 100644 Userland/Applications/SoundPlayer/Common.h diff --git a/Userland/Applications/SoundPlayer/Common.h b/Userland/Applications/SoundPlayer/Common.h deleted file mode 100644 index 06c5309e2b8..00000000000 --- a/Userland/Applications/SoundPlayer/Common.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021, Cesar Torres - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include - -class AutoSlider final : public GUI::Slider { - C_OBJECT(AutoSlider) -public: - ~AutoSlider() override = default; - Function 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 8e26933c5e8..2192d0e50f5 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 @@ -50,12 +49,16 @@ SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window m_visualization = m_player_view->add(); - m_playback_progress_slider = m_player_view->add(Orientation::Horizontal); + m_playback_progress_slider = m_player_view->add(); 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(); @@ -219,8 +222,8 @@ void SoundPlayerWidgetAdvancedView::sound_buffer_played(FixedArrayset_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 e17fb0f4eda..e86528994fc 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 #include #include +#include #include #include @@ -77,7 +77,7 @@ private: RefPtr m_back_action; RefPtr m_next_action; - RefPtr m_playback_progress_slider; + RefPtr m_playback_progress_slider; RefPtr m_volume_label; RefPtr m_volume_slider; RefPtr m_timestamp_label;