Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add menu option and hotkeys to move controllers/effects #7139

Merged
merged 13 commits into from
May 23, 2024
2 changes: 2 additions & 0 deletions include/ControllerRackView.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class ControllerRackView : public QWidget, public SerializingObject

public slots:
void deleteController( lmms::gui::ControllerView * _view );
void moveUp(lmms::gui::ControllerView* _view);
void moveDown(lmms::gui::ControllerView* _view);
void onControllerAdded( lmms::Controller * );
void onControllerRemoved( lmms::Controller * );

Expand Down
4 changes: 4 additions & 0 deletions include/ControllerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ public slots:
void deleteController();
void closeControls();
void renameController();
void moveUp();
void moveDown();

signals:
void moveUp(lmms::gui::ControllerView* _view);
void moveDown(lmms::gui::ControllerView* _view);
void deleteController( lmms::gui::ControllerView * _view );


Expand Down
45 changes: 45 additions & 0 deletions src/gui/ControllerRackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include <QApplication>
#include <QAction>
#include <QPushButton>
#include <QScrollArea>
#include <QMessageBox>
Expand Down Expand Up @@ -132,6 +133,33 @@ void ControllerRackView::deleteController( ControllerView * _view )
song->removeController( c );
}

void ControllerRackView::moveUp(ControllerView* view)
{
// cannot move the first module further up
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
if (view == m_controllerViews.first()) { return; }

int i = 0;
for (auto it = m_controllerViews.begin(); it != m_controllerViews.end(); ++it, ++i)
{
if (*it == view) { break; }
}
ControllerView* temp = m_controllerViews[i - 1];
m_controllerViews[i - 1] = view;
m_controllerViews[i] = temp;

m_scrollAreaLayout->removeWidget(view);
m_scrollAreaLayout->insertWidget(i - 1, view);
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
}

void ControllerRackView::moveDown(ControllerView* view)
{
if(view != m_controllerViews.last())
{
// moving next controller up is the same
moveUp(*(std::find(m_controllerViews.begin(), m_controllerViews.end(), view) + 1));
}
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
}




Expand All @@ -141,9 +169,26 @@ void ControllerRackView::onControllerAdded( Controller * controller )

auto controllerView = new ControllerView(controller, scrollAreaWidget);

connect(controllerView, SIGNAL(moveUp(lmms::gui::ControllerView* )), this,
SLOT(moveUp(lmms::gui::ControllerView* )), Qt::QueuedConnection);
connect(controllerView, SIGNAL(moveDown(lmms::gui::ControllerView* )), this,
SLOT(moveDown(lmms::gui::ControllerView* )), Qt::QueuedConnection);
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
connect( controllerView, SIGNAL(deleteController(lmms::gui::ControllerView*)),
this, SLOT(deleteController(lmms::gui::ControllerView*)), Qt::QueuedConnection );

QAction* moveUpAction = new QAction(controllerView);
moveUpAction->setShortcut(Qt::Key_Up | Qt::AltModifier);
moveUpAction->setShortcutContext(Qt::WidgetShortcut);
connect(moveUpAction, SIGNAL(triggered()), controllerView, SLOT(moveUp()));
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
controllerView->addAction( moveUpAction );
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved

QAction* moveDownAction = new QAction(controllerView);
moveDownAction->setShortcut(Qt::Key_Down | Qt::AltModifier);
moveDownAction->setShortcutContext(Qt::WidgetShortcut);
connect(moveDownAction, SIGNAL(triggered()), controllerView, SLOT(moveDown()));
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
controllerView->addAction(moveDownAction);


m_controllerViews.append( controllerView );
m_scrollAreaLayout->insertWidget( m_nextIndex, controllerView );

Expand Down
10 changes: 9 additions & 1 deletion src/gui/ControllerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ControllerView::ControllerView( Controller * _model, QWidget * _parent ) :
{
this->setFrameStyle( QFrame::StyledPanel );
this->setFrameShadow( QFrame::Raised );
this->setFocusPolicy(Qt::StrongFocus);
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved

auto vBoxLayout = new QVBoxLayout(this);

Expand Down Expand Up @@ -132,6 +133,9 @@ void ControllerView::closeControls()
m_show = true;
}

void ControllerView::moveUp() { emit moveUp(this); }

void ControllerView::moveDown() { emit moveDown(this); }

void ControllerView::deleteController()
{
Expand Down Expand Up @@ -173,7 +177,11 @@ void ControllerView::modelChanged()

void ControllerView::contextMenuEvent( QContextMenuEvent * )
{
QPointer<CaptionMenu> contextMenu = new CaptionMenu( model()->displayName(), this );
Controller* c = castModel<Controller>();
QPointer<CaptionMenu> contextMenu = new CaptionMenu(c->name(), this);
contextMenu->addAction(embed::getIconPixmap("arp_up"), tr("Move &up"), this, SLOT(moveUp()));
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
contextMenu->addAction(embed::getIconPixmap("arp_down"), tr("Move &down"), this, SLOT(moveDown()));
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
contextMenu->addSeparator();
contextMenu->addAction( embed::getIconPixmap( "cancel" ),
tr( "&Remove this controller" ),
this, SLOT(deleteController()));
Expand Down
14 changes: 14 additions & 0 deletions src/gui/EffectRackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include <QApplication>
#include <QAction>
#include <QPushButton>
#include <QScrollArea>
#include <QVBoxLayout>
Expand Down Expand Up @@ -177,6 +178,19 @@ void EffectRackView::update()
connect( view, SIGNAL(deletePlugin(lmms::gui::EffectView*)),
this, SLOT(deletePlugin(lmms::gui::EffectView*)),
Qt::QueuedConnection );

QAction* moveUpAction = new QAction(view);
moveUpAction->setShortcut(Qt::Key_Up | Qt::AltModifier);
moveUpAction->setShortcutContext(Qt::WidgetShortcut);
connect(moveUpAction, SIGNAL(triggered()), view, SLOT(moveUp()));
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
view->addAction(moveUpAction);

QAction* moveDownAction = new QAction(view);
moveDownAction->setShortcut(Qt::Key_Down | Qt::AltModifier);
moveDownAction->setShortcutContext(Qt::WidgetShortcut);
connect(moveDownAction, SIGNAL(triggered()), view, SLOT(moveDown()));
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
view->addAction(moveDownAction);

view->show();
m_effectViews.append( view );
if( i < view_map.size() )
Expand Down
1 change: 1 addition & 0 deletions src/gui/EffectView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ EffectView::EffectView( Effect * _model, QWidget * _parent ) :
m_dragging(false)
{
setFixedSize(EffectView::DEFAULT_WIDTH, EffectView::DEFAULT_HEIGHT);
this->setFocusPolicy(Qt::StrongFocus);
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved

// Disable effects that are of type "DummyEffect"
bool isEnabled = !dynamic_cast<DummyEffect *>( effect() );
Expand Down
Loading