mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-15 02:40:38 +00:00
SoundPlayer: Remove AutoSlider for the seek bar in favor of Slider
This commit is contained in:
parent
9e61e48b31
commit
3a1efbb9e4
Notes:
sideshowbarker
2024-07-17 00:43:06 +09:00
Author: https://github.com/Zaggy1024 Commit: https://github.com/SerenityOS/serenity/commit/3a1efbb9e4 Pull-request: https://github.com/SerenityOS/serenity/pull/17342 Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 11 additions and 58 deletions
|
@ -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 };
|
||||
};
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue