Introduce ActionGroup subclass
This commit is contained in:
57
include/ActionGroup.h
Normal file
57
include/ActionGroup.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 ACTION_GROUP_H
|
||||
#define ACTION_GROUP_H
|
||||
|
||||
#include <QActionGroup>
|
||||
|
||||
/// \brief Convenience subclass of QActionGroup
|
||||
///
|
||||
/// This class provides the same functionality as QActionGroup, but in addition
|
||||
/// has the actionTriggered(int) signal.
|
||||
/// It also sets every added action's checkable property to true.
|
||||
class ActionGroup : public QActionGroup
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ActionGroup(QObject* parent);
|
||||
|
||||
QAction* addAction(QAction *a);
|
||||
QAction* addAction(const QString &text);
|
||||
QAction* addAction(const QIcon &icon, const QString &text);
|
||||
|
||||
signals:
|
||||
/// This signal is emitted when the action at the given index is triggered.
|
||||
void triggered(int index);
|
||||
|
||||
private slots:
|
||||
void actionTriggered_(QAction* action);
|
||||
|
||||
private:
|
||||
QList<QAction*> m_actions;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -134,9 +134,7 @@ protected slots:
|
||||
void setEditMode(int mode);
|
||||
|
||||
void setProgressionType(AutomationPattern::ProgressionTypes type);
|
||||
void setProgressionDiscrete();
|
||||
void setProgressionLinear();
|
||||
void setProgressionHermite();
|
||||
void setProgressionType(int type);
|
||||
void setTension();
|
||||
|
||||
void copySelectedValues();
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#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,
|
||||
@@ -45,23 +42,11 @@ 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);
|
||||
virtual void play() {}
|
||||
virtual void record() {}
|
||||
virtual void recordAccompany() {}
|
||||
virtual void stop() {}
|
||||
|
||||
signals:
|
||||
|
||||
@@ -80,9 +65,6 @@ protected:
|
||||
QAction* m_recordAction;
|
||||
QAction* m_recordAccompanyAction;
|
||||
QAction* m_stopAction;
|
||||
private:
|
||||
quint8 m_editMode;
|
||||
QActionGroup* m_editModeGroup;
|
||||
};
|
||||
|
||||
|
||||
|
||||
55
src/gui/ActionGroup.cpp
Normal file
55
src/gui/ActionGroup.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ActionGroup.h"
|
||||
|
||||
ActionGroup::ActionGroup(QObject* parent) : QActionGroup(parent)
|
||||
{
|
||||
connect(this, SIGNAL(triggered(QAction*)), this, SLOT(actionTriggered_(QAction*)));
|
||||
}
|
||||
|
||||
QAction* ActionGroup::addAction(QAction* a)
|
||||
{
|
||||
a->setCheckable(true);
|
||||
|
||||
return QActionGroup::addAction(a);
|
||||
}
|
||||
|
||||
QAction* ActionGroup::addAction(const QString& text)
|
||||
{
|
||||
return addAction(new QAction(text, this));
|
||||
}
|
||||
|
||||
QAction* ActionGroup::addAction(const QIcon& icon, const QString& text)
|
||||
{
|
||||
return addAction(new QAction(icon, text, this));
|
||||
}
|
||||
|
||||
void ActionGroup::actionTriggered_(QAction* action)
|
||||
{
|
||||
Q_ASSERT(action != 0);
|
||||
Q_ASSERT(actions().contains(action));
|
||||
|
||||
emit triggered(actions().indexOf(action));
|
||||
}
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#include "ActionGroup.h"
|
||||
#include "SongEditor.h"
|
||||
#include "MainWindow.h"
|
||||
#include "embed.h"
|
||||
@@ -1643,22 +1643,9 @@ void AutomationEditor::setProgressionType(AutomationPattern::ProgressionTypes ty
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AutomationEditor::setProgressionDiscrete()
|
||||
void AutomationEditor::setProgressionType(int type)
|
||||
{
|
||||
setProgressionType(AutomationPattern::DiscreteProgression);
|
||||
}
|
||||
|
||||
|
||||
void AutomationEditor::setProgressionLinear()
|
||||
{
|
||||
setProgressionType(AutomationPattern::LinearProgression);
|
||||
}
|
||||
|
||||
|
||||
void AutomationEditor::setProgressionHermite()
|
||||
{
|
||||
setProgressionType(AutomationPattern::CubicHermiteProgression);
|
||||
setProgressionType((AutomationPattern::ProgressionTypes) type);
|
||||
}
|
||||
|
||||
|
||||
@@ -2005,17 +1992,18 @@ AutomationEditorWindow::AutomationEditorWindow() :
|
||||
"current pattern." ) );
|
||||
|
||||
// Edit mode buttons
|
||||
QAction* drawAction = addEditMode(embed::getIconPixmap("edit_draw"), tr("Draw mode (Shift+D)"));
|
||||
ActionGroup* editModeGroup = new ActionGroup(this);
|
||||
QAction* drawAction = editModeGroup->addAction(embed::getIconPixmap("edit_draw"), tr("Draw mode (Shift+D)"));
|
||||
drawAction->setShortcut(Qt::SHIFT | Qt::Key_D);
|
||||
|
||||
QAction* eraseAction = addEditMode(embed::getIconPixmap("edit_erase"), tr("Erase mode (Shift+E)"));
|
||||
QAction* eraseAction = editModeGroup->addAction(embed::getIconPixmap("edit_erase"), tr("Erase mode (Shift+E)"));
|
||||
eraseAction->setShortcut(Qt::SHIFT | Qt::Key_E);
|
||||
|
||||
drawAction->setChecked(true);
|
||||
|
||||
// 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_selectButton = new QAction(embed::getIconPixmap("edit_select"), tr("Select mode (Shift+S)"), editModeGroup);
|
||||
// m_moveButton = new QAction(embed::getIconPixmap("edit_move"), tr("Move selection mode (Shift+M)"), editModeGroup);
|
||||
|
||||
drawAction->setWhatsThis(
|
||||
tr( "Click here and draw-mode will be activated. In this "
|
||||
@@ -2039,26 +2027,21 @@ 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)));
|
||||
connect(editModeGroup, SIGNAL(triggered(int)), m_editor, SLOT(setEditMode(int)));
|
||||
|
||||
// Progression type buttons
|
||||
QActionGroup* progression_type_group = new QActionGroup(this);
|
||||
ActionGroup* progression_type_group = new ActionGroup(this);
|
||||
|
||||
m_discreteAction = new QAction(embed::getIconPixmap("progression_discrete"),
|
||||
tr("Discrete progression"), progression_type_group);
|
||||
m_linearAction = new QAction(embed::getIconPixmap("progression_linear"),
|
||||
tr("Linear progression"), progression_type_group);
|
||||
m_cubicHermiteAction = new QAction(embed::getIconPixmap("progression_cubic_hermite"),
|
||||
tr( "Cubic Hermite progression"), progression_type_group);
|
||||
m_discreteAction = progression_type_group->addAction(
|
||||
embed::getIconPixmap("progression_discrete"), tr("Discrete progression"));
|
||||
m_linearAction = progression_type_group->addAction(
|
||||
embed::getIconPixmap("progression_linear"), tr("Linear progression"));
|
||||
m_cubicHermiteAction = progression_type_group->addAction(
|
||||
embed::getIconPixmap("progression_cubic_hermite"), tr( "Cubic Hermite progression"));
|
||||
|
||||
m_linearAction->setCheckable( true );
|
||||
m_cubicHermiteAction->setCheckable( true );
|
||||
m_discreteAction->setCheckable( true );
|
||||
m_discreteAction->setChecked( true );
|
||||
|
||||
connect(m_discreteAction, SIGNAL(triggered()), m_editor, SLOT(setProgressionDiscrete()));
|
||||
connect(m_linearAction, SIGNAL(triggered()), m_editor, SLOT(setProgressionLinear()));
|
||||
connect(m_cubicHermiteAction, SIGNAL(triggered()), m_editor, SLOT(setProgressionHermite()));
|
||||
connect(progression_type_group, SIGNAL(triggered(int)), m_editor, SLOT(setProgressionType(int)));
|
||||
|
||||
// setup tension-stuff
|
||||
m_tensionKnob = new Knob( knobSmall_17, this, "Tension" );
|
||||
|
||||
@@ -41,59 +41,12 @@ 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()
|
||||
{
|
||||
}
|
||||
|
||||
void Editor::record()
|
||||
{
|
||||
}
|
||||
|
||||
void Editor::recordAccompany()
|
||||
{
|
||||
}
|
||||
|
||||
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_editMode(0),
|
||||
m_editModeGroup(new QActionGroup(this))
|
||||
m_stopAction(nullptr)
|
||||
{
|
||||
m_toolBar->setContextMenuPolicy(Qt::PreventContextMenu);
|
||||
m_toolBar->setMovable(false);
|
||||
@@ -118,9 +71,6 @@ 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*)));
|
||||
|
||||
// Add toolbar to window
|
||||
addToolBar(Qt::TopToolBarArea, m_toolBar);
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "ActionGroup.h"
|
||||
#include "ConfigManager.h"
|
||||
#include "PianoRoll.h"
|
||||
#include "BBTrackContainer.h"
|
||||
@@ -3939,17 +3940,17 @@ PianoRollWindow::PianoRollWindow() :
|
||||
tr( "Click here to stop playback of current pattern." ) );
|
||||
|
||||
// init edit-buttons at the top
|
||||
QAction* drawAction = addEditMode(embed::getIconPixmap("edit_draw"), tr("Draw mode (Shift+D)"));
|
||||
drawAction->setShortcut(Qt::SHIFT | Qt::Key_D);
|
||||
ActionGroup* editModeGroup = new ActionGroup(this);
|
||||
QAction* drawAction = editModeGroup->addAction(embed::getIconPixmap("edit_draw"), tr("Draw mode (Shift+D)"));
|
||||
QAction* eraseAction = editModeGroup->addAction(embed::getIconPixmap("edit_erase"), tr("Erase mode (Shift+E)"));
|
||||
QAction* selectAction = editModeGroup->addAction(embed::getIconPixmap("edit_select"), tr("Select mode (Shift+S)"));
|
||||
QAction* detuneAction = editModeGroup->addAction(embed::getIconPixmap("automation"), tr("Detune mode (Shift+T)"));
|
||||
|
||||
drawAction->setChecked( true );
|
||||
|
||||
QAction* eraseAction = addEditMode(embed::getIconPixmap("edit_erase"), tr("Erase mode (Shift+E)"));
|
||||
drawAction->setShortcut(Qt::SHIFT | Qt::Key_D);
|
||||
eraseAction->setShortcut(Qt::SHIFT | Qt::Key_E);
|
||||
|
||||
QAction* selectAction = addEditMode(embed::getIconPixmap("edit_select"), tr("Select mode (Shift+S)"));
|
||||
selectAction->setShortcut(Qt::SHIFT | Qt::Key_S);
|
||||
|
||||
QAction* detuneAction = addEditMode(embed::getIconPixmap("automation"), tr("Detune mode (Shift+T)"));
|
||||
detuneAction->setShortcut(Qt::SHIFT | Qt::Key_T);
|
||||
|
||||
drawAction->setWhatsThis(
|
||||
@@ -3975,7 +3976,7 @@ PianoRollWindow::PianoRollWindow() :
|
||||
"notes from one to another. You can also press "
|
||||
"'Shift+T' on your keyboard to activate this mode." ) );
|
||||
|
||||
connect(this, SIGNAL(editModeChanged(int)), m_editor, SLOT(setEditMode(int)));
|
||||
connect(editModeGroup, SIGNAL(triggered(int)), m_editor, SLOT(setEditMode(int)));
|
||||
|
||||
// Copy + paste actions
|
||||
QAction* cutAction = new QAction(embed::getIconPixmap("edit_cut"),
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "ActionGroup.h"
|
||||
#include "SongEditor.h"
|
||||
#include "AutomatableSlider.h"
|
||||
#include "ComboBox.h"
|
||||
@@ -628,10 +629,11 @@ 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()));
|
||||
|
||||
m_drawModeAction = addEditMode(embed::getIconPixmap("edit_draw"), tr("Draw mode"));
|
||||
m_drawModeAction->setChecked(true);
|
||||
ActionGroup* editModeGroup = new ActionGroup(this);
|
||||
m_drawModeAction = editModeGroup->addAction(embed::getIconPixmap("edit_draw"), tr("Draw mode"));
|
||||
m_selectModeAction = editModeGroup->addAction(embed::getIconPixmap("edit_select"), tr("Edit mode (select and move)"));
|
||||
|
||||
m_selectModeAction = addEditMode(embed::getIconPixmap("edit_select"), tr("Edit mode (select and move)"));
|
||||
m_drawModeAction->setChecked(true);
|
||||
|
||||
connect(m_drawModeAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeDraw()));
|
||||
connect(m_selectModeAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeSelect()));
|
||||
|
||||
Reference in New Issue
Block a user