Stop on second space key press

This commit is contained in:
Lukas W
2015-01-11 13:05:44 +01:00
parent 7f2f9f2685
commit 23dbe95e80
2 changed files with 14 additions and 2 deletions

View File

@@ -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:

View File

@@ -30,6 +30,7 @@
#include <QAction>
#include <QActionGroup>
#include <QMdiArea>
#include <QShortcut>
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);