mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:47:34 +00:00
SoundPlayer: Replace regular buttons with action-based toolbar buttons
This looks nicer in every way imaginable.
This commit is contained in:
parent
bf5caf254f
commit
1940363e0b
2 changed files with 35 additions and 41 deletions
|
@ -62,42 +62,35 @@ SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window
|
||||||
auto& toolbar_container = m_player_view->add<GUI::ToolbarContainer>();
|
auto& toolbar_container = m_player_view->add<GUI::ToolbarContainer>();
|
||||||
auto& menubar = toolbar_container.add<GUI::Toolbar>();
|
auto& menubar = toolbar_container.add<GUI::Toolbar>();
|
||||||
|
|
||||||
m_play_button = menubar.add<GUI::Button>();
|
m_play_action = GUI::Action::create("Play", m_play_icon, [&](auto&) {
|
||||||
m_play_button->set_icon(*m_play_icon);
|
|
||||||
m_play_button->set_fixed_width(50);
|
|
||||||
m_play_button->set_enabled(false);
|
|
||||||
m_play_button->on_click = [&](unsigned) {
|
|
||||||
toggle_pause();
|
toggle_pause();
|
||||||
};
|
});
|
||||||
|
m_play_action->set_enabled(false);
|
||||||
|
menubar.add_action(*m_play_action);
|
||||||
|
|
||||||
m_stop_button = menubar.add<GUI::Button>();
|
m_stop_action = GUI::Action::create("Stop", m_stop_icon, [&](auto&) {
|
||||||
m_stop_button->set_icon(*m_stop_icon);
|
|
||||||
m_stop_button->set_fixed_width(50);
|
|
||||||
m_stop_button->set_enabled(false);
|
|
||||||
m_stop_button->on_click = [&](unsigned) {
|
|
||||||
stop();
|
stop();
|
||||||
};
|
});
|
||||||
|
m_stop_action->set_enabled(false);
|
||||||
|
menubar.add_action(*m_stop_action);
|
||||||
|
|
||||||
m_timestamp_label = menubar.add<GUI::Label>();
|
m_timestamp_label = menubar.add<GUI::Label>();
|
||||||
m_timestamp_label->set_fixed_width(110);
|
m_timestamp_label->set_fixed_width(110);
|
||||||
|
|
||||||
// filler_label
|
// Filler label
|
||||||
menubar.add<GUI::Label>();
|
menubar.add<GUI::Label>();
|
||||||
m_back_button = menubar.add<GUI::Button>();
|
|
||||||
m_back_button->set_fixed_width(50);
|
|
||||||
m_back_button->set_icon(*m_back_icon);
|
|
||||||
m_back_button->set_enabled(false);
|
|
||||||
m_back_button->on_click = [&](unsigned) {
|
|
||||||
play_file_path(playlist().previous());
|
|
||||||
};
|
|
||||||
|
|
||||||
m_next_button = menubar.add<GUI::Button>();
|
m_back_action = GUI::Action::create("Back", m_back_icon, [&](auto&) {
|
||||||
m_next_button->set_fixed_width(50);
|
play_file_path(playlist().previous());
|
||||||
m_next_button->set_icon(*m_next_icon);
|
});
|
||||||
m_next_button->set_enabled(false);
|
m_back_action->set_enabled(false);
|
||||||
m_next_button->on_click = [&](unsigned) {
|
menubar.add_action(*m_back_action);
|
||||||
|
|
||||||
|
m_next_action = GUI::Action::create("Next", m_next_icon, [&](auto&) {
|
||||||
play_file_path(playlist().next());
|
play_file_path(playlist().next());
|
||||||
};
|
});
|
||||||
|
m_next_action->set_enabled(false);
|
||||||
|
menubar.add_action(*m_next_action);
|
||||||
|
|
||||||
m_volume_label = &menubar.add<GUI::Label>();
|
m_volume_label = &menubar.add<GUI::Label>();
|
||||||
m_volume_label->set_fixed_width(30);
|
m_volume_label->set_fixed_width(30);
|
||||||
|
@ -140,13 +133,13 @@ void SoundPlayerWidgetAdvancedView::drop_event(GUI::DropEvent& event)
|
||||||
void SoundPlayerWidgetAdvancedView::keydown_event(GUI::KeyEvent& event)
|
void SoundPlayerWidgetAdvancedView::keydown_event(GUI::KeyEvent& event)
|
||||||
{
|
{
|
||||||
if (event.key() == Key_Space)
|
if (event.key() == Key_Space)
|
||||||
m_play_button->click();
|
m_play_action->activate();
|
||||||
|
|
||||||
if (event.key() == Key_M)
|
if (event.key() == Key_M)
|
||||||
toggle_mute();
|
toggle_mute();
|
||||||
|
|
||||||
if (event.key() == Key_S)
|
if (event.key() == Key_S)
|
||||||
m_stop_button->click();
|
m_stop_action->activate();
|
||||||
|
|
||||||
if (event.key() == Key_Up)
|
if (event.key() == Key_Up)
|
||||||
m_volume_slider->increase_slider_by_page_steps(1);
|
m_volume_slider->increase_slider_by_page_steps(1);
|
||||||
|
@ -169,12 +162,12 @@ void SoundPlayerWidgetAdvancedView::set_playlist_visible(bool visible)
|
||||||
|
|
||||||
void SoundPlayerWidgetAdvancedView::play_state_changed(Player::PlayState state)
|
void SoundPlayerWidgetAdvancedView::play_state_changed(Player::PlayState state)
|
||||||
{
|
{
|
||||||
sync_previous_next_buttons();
|
sync_previous_next_actions();
|
||||||
|
|
||||||
m_play_button->set_enabled(state != PlayState::NoFileLoaded);
|
m_play_action->set_enabled(state != PlayState::NoFileLoaded);
|
||||||
m_play_button->set_icon(state == PlayState::Playing ? *m_pause_icon : *m_play_icon);
|
m_play_action->set_icon(state == PlayState::Playing ? m_pause_icon : m_play_icon);
|
||||||
|
|
||||||
m_stop_button->set_enabled(state != PlayState::Stopped && state != PlayState::NoFileLoaded);
|
m_stop_action->set_enabled(state != PlayState::Stopped && state != PlayState::NoFileLoaded);
|
||||||
|
|
||||||
m_playback_progress_slider->set_enabled(state != PlayState::NoFileLoaded);
|
m_playback_progress_slider->set_enabled(state != PlayState::NoFileLoaded);
|
||||||
}
|
}
|
||||||
|
@ -188,15 +181,15 @@ void SoundPlayerWidgetAdvancedView::mute_changed(bool)
|
||||||
// FIXME: Update the volume slider when player is muted
|
// FIXME: Update the volume slider when player is muted
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundPlayerWidgetAdvancedView::sync_previous_next_buttons()
|
void SoundPlayerWidgetAdvancedView::sync_previous_next_actions()
|
||||||
{
|
{
|
||||||
m_back_button->set_enabled(playlist().size() > 1 && !playlist().shuffling());
|
m_back_action->set_enabled(playlist().size() > 1 && !playlist().shuffling());
|
||||||
m_next_button->set_enabled(playlist().size() > 1);
|
m_next_action->set_enabled(playlist().size() > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundPlayerWidgetAdvancedView::shuffle_mode_changed(Player::ShuffleMode)
|
void SoundPlayerWidgetAdvancedView::shuffle_mode_changed(Player::ShuffleMode)
|
||||||
{
|
{
|
||||||
sync_previous_next_buttons();
|
sync_previous_next_actions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundPlayerWidgetAdvancedView::time_elapsed(int seconds)
|
void SoundPlayerWidgetAdvancedView::time_elapsed(int seconds)
|
||||||
|
|
|
@ -55,7 +55,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
SoundPlayerWidgetAdvancedView(GUI::Window&, Audio::ConnectionFromClient&);
|
SoundPlayerWidgetAdvancedView(GUI::Window&, Audio::ConnectionFromClient&);
|
||||||
|
|
||||||
void sync_previous_next_buttons();
|
void sync_previous_next_actions();
|
||||||
|
|
||||||
void drop_event(GUI::DropEvent& event) override;
|
void drop_event(GUI::DropEvent& event) override;
|
||||||
GUI::Window& m_window;
|
GUI::Window& m_window;
|
||||||
|
@ -71,10 +71,11 @@ private:
|
||||||
RefPtr<Gfx::Bitmap> m_back_icon;
|
RefPtr<Gfx::Bitmap> m_back_icon;
|
||||||
RefPtr<Gfx::Bitmap> m_next_icon;
|
RefPtr<Gfx::Bitmap> m_next_icon;
|
||||||
|
|
||||||
RefPtr<GUI::Button> m_play_button;
|
RefPtr<GUI::Action> m_play_action;
|
||||||
RefPtr<GUI::Button> m_stop_button;
|
RefPtr<GUI::Action> m_stop_action;
|
||||||
RefPtr<GUI::Button> m_back_button;
|
RefPtr<GUI::Action> m_back_action;
|
||||||
RefPtr<GUI::Button> m_next_button;
|
RefPtr<GUI::Action> m_next_action;
|
||||||
|
|
||||||
RefPtr<AutoSlider> m_playback_progress_slider;
|
RefPtr<AutoSlider> m_playback_progress_slider;
|
||||||
RefPtr<GUI::Label> m_volume_label;
|
RefPtr<GUI::Label> m_volume_label;
|
||||||
RefPtr<GUI::HorizontalSlider> m_volume_slider;
|
RefPtr<GUI::HorizontalSlider> m_volume_slider;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue