Draggable effects (#6648)

Reorder effects in Mixer with the mouse via click and drag
This commit is contained in:
Lost Robot
2023-02-18 07:22:16 -08:00
committed by GitHub
parent 507fa239dd
commit 8ba6a5f89e
2 changed files with 56 additions and 4 deletions

View File

@@ -30,6 +30,7 @@
#include "PluginView.h"
#include "Effect.h"
class QGraphicsOpacityEffect;
class QGroupBox;
class QLabel;
class QPushButton;
@@ -61,6 +62,11 @@ public:
}
static constexpr int DEFAULT_WIDTH = 215;
static constexpr int DEFAULT_HEIGHT = 60;
void mouseMoveEvent(QMouseEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
public slots:
void editControls();
@@ -90,6 +96,9 @@ private:
Knob * m_gate;
QMdiSubWindow * m_subWindow;
EffectControlDialog * m_controlView;
bool m_dragging;
QGraphicsOpacityEffect* m_opacityEffect;
} ;

View File

@@ -23,9 +23,11 @@
*
*/
#include <QGraphicsOpacityEffect>
#include <QLayout>
#include <QMouseEvent>
#include <QPushButton>
#include <QPainter>
#include <QLayout>
#include "EffectView.h"
#include "DummyEffect.h"
@@ -47,9 +49,10 @@ EffectView::EffectView( Effect * _model, QWidget * _parent ) :
PluginView( _model, _parent ),
m_bg( embed::getIconPixmap( "effect_plugin" ) ),
m_subWindow( nullptr ),
m_controlView( nullptr )
m_controlView(nullptr),
m_dragging(false)
{
setFixedSize( EffectView::DEFAULT_WIDTH, 60 );
setFixedSize(EffectView::DEFAULT_WIDTH, EffectView::DEFAULT_HEIGHT);
// Disable effects that are of type "DummyEffect"
bool isEnabled = !dynamic_cast<DummyEffect *>( effect() );
@@ -116,7 +119,10 @@ EffectView::EffectView( Effect * _model, QWidget * _parent ) :
m_subWindow->hide();
}
}
m_opacityEffect = new QGraphicsOpacityEffect(this);
m_opacityEffect->setOpacity(1);
setGraphicsEffect(m_opacityEffect);
//move above vst effect view creation
//setModel( _model );
@@ -208,6 +214,43 @@ void EffectView::contextMenuEvent( QContextMenuEvent * )
void EffectView::mousePressEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton)
{
m_dragging = true;
m_opacityEffect->setOpacity(0.3);
QCursor c(Qt::SizeVerCursor);
QApplication::setOverrideCursor(c);
update();
}
}
void EffectView::mouseReleaseEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton)
{
m_dragging = false;
m_opacityEffect->setOpacity(1);
QApplication::restoreOverrideCursor();
update();
}
}
void EffectView::mouseMoveEvent(QMouseEvent* event)
{
if (!m_dragging) { return; }
if (event->pos().y() < 0)
{
moveUp();
}
else if (event->pos().y() > EffectView::DEFAULT_HEIGHT)
{
moveDown();
}
}
void EffectView::paintEvent( QPaintEvent * )
{