From 23dbe95e80b2386be1f3f7d08d8942d2f717b585 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Sun, 11 Jan 2015 13:05:44 +0100 Subject: [PATCH] Stop on second space key press --- include/Editor.h | 4 ++++ src/gui/editors/Editor.cpp | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/Editor.h b/include/Editor.h index 1070aa649..e4da281dc 100644 --- a/include/Editor.h +++ b/include/Editor.h @@ -48,6 +48,10 @@ protected slots: virtual void recordAccompany() {} virtual void stop() {} +private slots: + /// Called by pressing the space key. Plays or stops. + void togglePlayStop(); + signals: protected: diff --git a/src/gui/editors/Editor.cpp b/src/gui/editors/Editor.cpp index 8594f1b95..985d22f40 100644 --- a/src/gui/editors/Editor.cpp +++ b/src/gui/editors/Editor.cpp @@ -30,6 +30,7 @@ #include #include #include +#include void Editor::setPauseIcon(bool displayPauseIcon) @@ -41,6 +42,14 @@ void Editor::setPauseIcon(bool displayPauseIcon) m_playAction->setIcon(embed::getIconPixmap("play")); } +void Editor::togglePlayStop() +{ + if (Engine::getSong()->isPlaying()) + stop(); + else + play(); +} + Editor::Editor(bool record) : m_toolBar(new QToolBar(this)), m_playAction(nullptr), @@ -63,13 +72,12 @@ Editor::Editor(bool record) : m_recordAction = new QAction(embed::getIconPixmap("record"), tr("Record"), this); m_recordAccompanyAction = new QAction(embed::getIconPixmap("record_accompany"), tr("Record while playing"), this); - m_playAction->setShortcut(Qt::Key_Space); - // Set up connections connect(m_playAction, SIGNAL(triggered()), this, SLOT(play())); connect(m_recordAction, SIGNAL(triggered()), this, SLOT(record())); connect(m_recordAccompanyAction, SIGNAL(triggered()), this, SLOT(recordAccompany())); connect(m_stopAction, SIGNAL(triggered()), this, SLOT(stop())); + new QShortcut(Qt::Key_Space, this, SLOT(togglePlayStop())); // Add toolbar to window addToolBar(Qt::TopToolBarArea, m_toolBar);