summaryrefslogtreecommitdiff
path: root/Applications/SoundPlayer/SoundPlayerWidget.h
diff options
context:
space:
mode:
authorTill Mayer <till.mayer@web.de>2019-11-04 19:45:19 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-04 20:55:46 +0100
commit77f3c12dc98d68c04e4b87efe35ad05ecd40ef8e (patch)
tree615ac96aedd446ee54a04c678d7e0f22b62b1b10 /Applications/SoundPlayer/SoundPlayerWidget.h
parent2f13517a1adb262dbda8e12cb0aeb7383bf0c812 (diff)
downloadserenity-77f3c12dc98d68c04e4b87efe35ad05ecd40ef8e.zip
SoundPlayer: Added playback controls
The playback of a file can now be paused, stopped, continued and the user can seek to any part of the file.
Diffstat (limited to 'Applications/SoundPlayer/SoundPlayerWidget.h')
-rw-r--r--Applications/SoundPlayer/SoundPlayerWidget.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/Applications/SoundPlayer/SoundPlayerWidget.h b/Applications/SoundPlayer/SoundPlayerWidget.h
new file mode 100644
index 0000000000..65a6dc36e4
--- /dev/null
+++ b/Applications/SoundPlayer/SoundPlayerWidget.h
@@ -0,0 +1,59 @@
+#pragma once
+
+#include "PlaybackManager.h"
+#include "SampleWidget.h"
+#include <LibGUI/GButton.h>
+#include <LibGUI/GLabel.h>
+#include <LibGUI/GSlider.h>
+#include <LibGUI/GWidget.h>
+
+class SoundPlayerWidget final : public GWidget {
+ C_OBJECT(SoundPlayerWidget)
+public:
+ virtual ~SoundPlayerWidget() override;
+
+private:
+ explicit SoundPlayerWidget(NonnullRefPtr<AClientConnection>, AWavLoader&);
+
+ void update_position(const int position);
+ void update_ui();
+ int normalize_rate(int) const;
+ int denormalize_rate(int) const;
+
+ class Slider final : public GSlider {
+ C_OBJECT(Slider)
+ public:
+ virtual ~Slider() override;
+ Function<void(int)> on_knob_released;
+ void set_value(int value)
+ {
+ if (!knob_dragging())
+ GSlider::set_value(value);
+ }
+
+ protected:
+ Slider(Orientation orientation, GWidget* parent)
+ : GSlider(orientation, parent)
+ {
+ }
+
+ virtual void mouseup_event(GMouseEvent& event) override
+ {
+ if (on_knob_released && is_enabled())
+ on_knob_released(value());
+
+ GSlider::mouseup_event(event);
+ }
+ };
+
+ PlaybackManager m_manager;
+ float m_sample_ratio;
+ RefPtr<GLabel> m_status;
+ RefPtr<GLabel> m_elapsed;
+ RefPtr<GLabel> m_remaining;
+ RefPtr<Slider> m_slider;
+ RefPtr<SampleWidget> m_sample_widget;
+ RefPtr<GraphicsBitmap> m_play_icon { GraphicsBitmap::load_from_file("/res/icons/16x16/play.png") };
+ RefPtr<GraphicsBitmap> m_pause_icon { GraphicsBitmap::load_from_file("/res/icons/16x16/pause.png") };
+ RefPtr<GButton> m_play;
+};