Add Editor superclass

Provides a toolbar with play, record and stop buttons.
This commit is contained in:
Lukas W
2014-12-07 11:53:20 +01:00
parent ee1b9ba7bc
commit 44b52ebd99
2 changed files with 141 additions and 0 deletions

65
include/Editor.h Normal file
View File

@@ -0,0 +1,65 @@
/*
* Editor.h - declaration of Editor class
*
* Copyright (c) 2014 Lukas W <lukaswhl/at/gmail.com>
*
* This file is part of LMMS - http://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef EDITOR_COMMON_H
#define EDITOR_COMMON_H
#include <QMainWindow>
#include <QToolBar>
#include "Timeline.h"
#include "ToolButton.h"
/// \brief Superclass for editors with a toolbar.
///
/// Those editors include the Song Editor, the Automation Editor,
/// B&B Editor, Piano Roll.
class Editor : public QMainWindow
{
Q_OBJECT
public:
void setPlaying(bool playing=true);
signals:
protected:
/// \brief Constructor.
///
/// \param record If set true, the editor's toolbar will contain record
/// buttons in addition to the play and stop buttons.
Editor(bool record = false);
virtual ~Editor();
QToolBar* m_toolBar;
QAbstractButton* m_playButton;
QAbstractButton* m_recordButton;
QAbstractButton* m_recordAccompanyButton;
QAbstractButton* m_stopButton;
private:
};
#endif

76
src/gui/Editor.cpp Normal file
View File

@@ -0,0 +1,76 @@
/*
* Editor.cpp - implementation of Editor class
*
* Copyright (c) 2014 Lukas W <lukaswhl/at/gmail.com>
*
* This file is part of LMMS - http://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "Editor.h"
#include "embed.h"
#include <QAction>
#include <QToolBar>
void Editor::setPlaying(bool playing)
{
// If we're playing, show a pause icon
if (playing)
m_playButton->setIcon(embed::getIconPixmap("play"));
else
m_playButton->setIcon(embed::getIconPixmap("pause"));
}
Editor::Editor(bool record) :
m_toolBar(new QToolBar(this)),
m_playButton(nullptr),
m_recordButton(nullptr),
m_recordAccompanyButton(nullptr),
m_stopButton(nullptr)
{
auto addButton = [this](const char* pixmap_name, QString text, QString objectName) {
ToolButton* button = new ToolButton(embed::getIconPixmap(pixmap_name), text);
button->setObjectName(objectName);
m_toolBar->addWidget(button);
return button;
};
// Set up play button
m_playButton = addButton("play", tr("Play (Space)"), "playButton");
// Set up record buttons if wanted
if (record)
{
m_recordButton= addButton("record", tr("Record"), "recordButton");
m_recordAccompanyButton = addButton("record_accompany", tr("Record while playing"), "recordAccompanyButton");
}
// Set up stop button
m_stopButton = addButton("stop", tr("Stop (Space)"), "stopButton");
// Add toolbar to window
addToolBar(Qt::TopToolBarArea, m_toolBar);
}
Editor::~Editor()
{
}