From 44b52ebd99b614dcc28cc4da284ac583dcbdc216 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Sun, 7 Dec 2014 11:53:20 +0100 Subject: [PATCH] Add Editor superclass Provides a toolbar with play, record and stop buttons. --- include/Editor.h | 65 +++++++++++++++++++++++++++++++++++++++ src/gui/Editor.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 include/Editor.h create mode 100644 src/gui/Editor.cpp diff --git a/include/Editor.h b/include/Editor.h new file mode 100644 index 000000000..0416f0369 --- /dev/null +++ b/include/Editor.h @@ -0,0 +1,65 @@ +/* + * Editor.h - declaration of Editor class + * + * Copyright (c) 2014 Lukas W + * + * 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 +#include + +#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 diff --git a/src/gui/Editor.cpp b/src/gui/Editor.cpp new file mode 100644 index 000000000..8f0e80da2 --- /dev/null +++ b/src/gui/Editor.cpp @@ -0,0 +1,76 @@ +/* + * Editor.cpp - implementation of Editor class + * + * Copyright (c) 2014 Lukas W + * + * 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 +#include + + +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() +{ + +}