Editor: Add edit mode support

This commit is contained in:
Lukas W
2014-12-11 02:39:04 +01:00
parent 1d07a91a83
commit ebbec2f270
6 changed files with 71 additions and 74 deletions

View File

@@ -25,12 +25,16 @@
#ifndef EDITOR_COMMON_H
#define EDITOR_COMMON_H
#include <QAction>
#include <QMainWindow>
#include <QToolBar>
#include "TimeLineWidget.h"
#include "ToolButton.h"
// Forward declarations
class QActionGroup;
/// \brief Superclass for editors with a toolbar.
///
/// Those editors include the Song Editor, the Automation Editor, B&B Editor,
@@ -41,12 +45,24 @@ class Editor : public QMainWindow
public:
void setPauseIcon(bool displayPauseIcon=true);
int editMode() const;
void setEditMode(int mode);
signals:
void editModeChanged(int);
protected:
QAction* addEditMode(const QIcon &icon, const QString &text, const QString& whatsThis=QString());
protected slots:
virtual void play();
virtual void record();
virtual void recordAccompany();
virtual void stop();
private slots:
void setEditModeByAction(QAction* action);
signals:
protected:
@@ -65,6 +81,8 @@ protected:
QAction* m_recordAccompanyAction;
QAction* m_stopAction;
private:
quint8 m_editMode;
QActionGroup* m_editModeGroup;
};

View File

@@ -140,11 +140,7 @@ protected slots:
void horScrolled( int new_pos );
void verScrolled( int new_pos );
void setEditMode(EditModes mode);
void setEditModeDraw() {setEditMode(ModeDraw); }
void setEditModeErase() {setEditMode(ModeErase); }
void setEditModeSelect() {setEditMode(ModeSelect); }
void setEditModeDetune() {setEditMode(ModeEditDetuning); }
void setEditMode(int mode);
void copySelectedNotes();
void cutSelectedNotes();

View File

@@ -2005,51 +2005,17 @@ AutomationEditorWindow::AutomationEditorWindow() :
"current pattern." ) );
// Edit mode buttons
QActionGroup * tool_action_group = new QActionGroup(this);
m_drawAction = new QAction(embed::getIconPixmap("edit_draw"),
tr("Draw mode (Shift+D)"), tool_action_group);
m_drawAction->setCheckable(true);
m_drawAction = addEditMode(embed::getIconPixmap("edit_draw"), tr("Draw mode (Shift+D)"));
m_drawAction->setShortcut(Qt::SHIFT | Qt::Key_D);
m_eraseAction = new QAction(embed::getIconPixmap("edit_erase"),
tr("Erase mode (Shift+E)"), tool_action_group);
m_eraseAction->setCheckable(true);
m_eraseAction = addEditMode(embed::getIconPixmap("edit_erase"), tr("Erase mode (Shift+E)"));
m_eraseAction->setShortcut(Qt::SHIFT | Qt::Key_E);
m_drawAction->setChecked(true);
//TODO: m_selectButton and m_moveButton are broken.
/*m_selectButton = new ToolButton( embed::getIconPixmap(
"edit_select" ),
tr( "Select mode (Shift+S)" ),
this, SLOT( selectButtonToggled() ),
m_toolBar );
m_selectButton->setCheckable( true );
m_moveButton = new ToolButton( embed::getIconPixmap( "edit_move" ),
tr( "Move selection mode (Shift+M)" ),
this, SLOT( moveButtonToggled() ),
m_toolBar );
m_moveButton->setCheckable( true );*/
QSignalMapper* signalmapper = new QSignalMapper(this);
signalmapper->setMapping(m_drawAction, AutomationEditor::DRAW);
signalmapper->setMapping(m_eraseAction, AutomationEditor::ERASE);
// signalmapper->setMapping(m_selectButton, AutomationEditor::SELECT);
// signalmapper->setMapping(m_moveButton, AutomationEditor::MOVE);
connect(m_drawAction, SIGNAL(triggered()), signalmapper, SLOT(map()));
connect(m_eraseAction, SIGNAL(triggered()), signalmapper, SLOT(map()));
// connect(m_selectButton, SIGNAL(triggered()), signalmapper, SLOT(map()));
// connect(m_moveButton, SIGNAL(triggered()), signalmapper, SLOT(map()));
connect(signalmapper, SIGNAL(mapped(int)), m_editor, SLOT(setEditMode(int)));
// tool_action_group->addAction( m_drawButton );
// tool_action_group->addAction( m_eraseButton );
//tool_button_group->addButton( m_selectButton );
//tool_button_group->addButton( m_moveButton );
// TODO: m_selectButton and m_moveButton are broken.
// m_selectButton = addEditMode(embed::getIconPixmap("edit_select"), tr("Select mode (Shift+S)"));
// m_moveButton = addEditMode(embed::getIconPixmap("edit_move"), tr("Move selection mode (Shift+M)"));
m_drawAction->setWhatsThis(
tr( "Click here and draw-mode will be activated. In this "
@@ -2073,7 +2039,7 @@ AutomationEditorWindow::AutomationEditorWindow() :
"mode. You can also press 'Shift+M' on your keyboard "
"to activate this mode." ) );*/
connect(this, SIGNAL(editModeChanged(int)), m_editor, SLOT(setEditMode(int)));
// Progression type buttons
QActionGroup* progression_type_group = new QActionGroup(this);

View File

@@ -27,9 +27,9 @@
#include "MainWindow.h"
#include "embed.h"
#include <QMdiArea>
#include <QAction>
#include <QToolBar>
#include <QActionGroup>
#include <QMdiArea>
void Editor::setPauseIcon(bool displayPauseIcon)
@@ -41,6 +41,28 @@ void Editor::setPauseIcon(bool displayPauseIcon)
m_playAction->setIcon(embed::getIconPixmap("play"));
}
int Editor::editMode() const
{
return m_editMode;
}
void Editor::setEditMode(int mode)
{
if (mode <= m_editModeGroup->actions().size())
{
m_editMode = mode;
}
emit(editModeChanged(mode));
}
QAction* Editor::addEditMode(const QIcon& icon, const QString& text, const QString& whatsThis)
{
QAction* editModeAction = new QAction(icon, text, m_editModeGroup);
editModeAction->setWhatsThis(whatsThis);
editModeAction->setCheckable(true);
return editModeAction;
}
void Editor::play()
{
}
@@ -57,12 +79,21 @@ void Editor::stop()
{
}
void Editor::setEditModeByAction(QAction* action)
{
int index = m_editModeGroup->actions().indexOf(action);
if (index != -1)
setEditMode(index);
}
Editor::Editor(bool record) :
m_toolBar(new QToolBar(this)),
m_playAction(nullptr),
m_recordAction(nullptr),
m_recordAccompanyAction(nullptr),
m_stopAction(nullptr)
m_stopAction(nullptr),
m_editMode(0),
m_editModeGroup(new QActionGroup(this))
{
m_toolBar->setContextMenuPolicy(Qt::PreventContextMenu);
m_toolBar->setMovable(false);
@@ -98,6 +129,9 @@ Editor::Editor(bool record) :
connect(m_recordAccompanyAction, SIGNAL(triggered()), this, SLOT(recordAccompany()));
}
connect(m_stopAction, SIGNAL(triggered()), this, SLOT(stop()));
// Connect edit mode
connect(m_editModeGroup, SIGNAL(triggered(QAction*)), this, SLOT(setEditModeByAction(QAction*)));
}
Editor::~Editor()

View File

@@ -3423,9 +3423,9 @@ void PianoRoll::verScrolled( int new_pos )
void PianoRoll::setEditMode(PianoRoll::EditModes mode)
void PianoRoll::setEditMode(int mode)
{
m_editMode = mode;
m_editMode = (EditModes) mode;
}
@@ -3940,27 +3940,18 @@ PianoRollWindow::PianoRollWindow() :
tr( "Click here to stop playback of current pattern." ) );
// init edit-buttons at the top
QActionGroup* tool_button_group = new QActionGroup(this);
m_drawAction = new QAction(embed::getIconPixmap("edit_draw"),
tr( "Draw mode (Shift+D)" ), tool_button_group);
m_drawAction = addEditMode(embed::getIconPixmap("edit_draw"), tr("Draw mode (Shift+D)"));
m_drawAction->setShortcut(Qt::SHIFT | Qt::Key_D);
m_drawAction->setCheckable( true );
m_drawAction->setChecked( true );
m_eraseAction = new QAction(embed::getIconPixmap("edit_erase"),
tr("Erase mode (Shift+E)"), tool_button_group);
m_eraseAction = addEditMode(embed::getIconPixmap("edit_erase"), tr("Erase mode (Shift+E)"));
m_eraseAction->setShortcut(Qt::SHIFT | Qt::Key_E);
m_eraseAction->setCheckable( true );
m_selectAction = new QAction( embed::getIconPixmap("edit_select"),
tr("Select mode (Shift+S)"), tool_button_group);
m_selectAction = addEditMode(embed::getIconPixmap("edit_select"), tr("Select mode (Shift+S)"));
m_selectAction->setShortcut(Qt::SHIFT | Qt::Key_S);
m_selectAction->setCheckable( true );
m_detuneAction = new QAction(embed::getIconPixmap("automation"),
tr("Detune mode (Shift+T)"), tool_button_group);
m_detuneAction = addEditMode(embed::getIconPixmap("automation"), tr("Detune mode (Shift+T)"));
m_detuneAction->setShortcut(Qt::SHIFT | Qt::Key_T);
m_detuneAction->setCheckable( true );
m_drawAction->setWhatsThis(
tr( "Click here and draw mode will be activated. In this "
@@ -3985,10 +3976,7 @@ PianoRollWindow::PianoRollWindow() :
"notes from one to another. You can also press "
"'Shift+T' on your keyboard to activate this mode." ) );
connect(m_drawAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeDraw()));
connect(m_eraseAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeErase()));
connect(m_selectAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeSelect()));
connect(m_detuneAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeDetune()));
connect(this, SIGNAL(editModeChanged(int)), m_editor, SLOT(setEditMode(int)));
// Copy + paste actions
m_cutAction = new QAction(embed::getIconPixmap("edit_cut"),

View File

@@ -631,15 +631,10 @@ SongEditorWindow::SongEditorWindow(Song* song) :
connect(m_addSampleTrackAction, SIGNAL(triggered()), m_editor->m_song, SLOT(addSampleTrack()));
connect(m_addAutomationTrackAction, SIGNAL(triggered()), m_editor->m_song, SLOT(addAutomationTrack()));
QActionGroup* tool_action_group = new QActionGroup(this);
m_drawModeAction = new QAction(embed::getIconPixmap("edit_draw"),
tr("Draw mode"), tool_action_group);
m_drawModeAction->setCheckable(true);
m_drawModeAction = addEditMode(embed::getIconPixmap("edit_draw"), tr("Draw mode"));
m_drawModeAction->setChecked(true);
m_selectModeAction = new QAction(embed::getIconPixmap("edit_select"),
tr("Edit mode (select and move)"), tool_action_group);
m_selectModeAction->setCheckable(true);
m_selectModeAction = addEditMode(embed::getIconPixmap("edit_select"), tr("Edit mode (select and move)"));
connect(m_drawModeAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeDraw()));
connect(m_selectModeAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeSelect()));