From 7e7044d7028ce00d2389bd9aad8e863251b42f71 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Mon, 22 Oct 2018 18:43:34 +0200 Subject: [PATCH] Allow dropping automation in more ways This enables DnD from internal and spa knobs on * Controller views (from the controller rack) * Existing Automation Patterns * Automation Editors --- include/ControllerView.h | 3 ++- src/gui/AutomationPatternView.cpp | 11 +++++++---- src/gui/editors/AutomationEditor.cpp | 10 ++++++---- src/gui/widgets/ControllerView.cpp | 28 ++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/include/ControllerView.h b/include/ControllerView.h index 4b215feca9b..85938e3439a 100644 --- a/include/ControllerView.h +++ b/include/ControllerView.h @@ -71,7 +71,8 @@ public slots: virtual void contextMenuEvent( QContextMenuEvent * _me ); virtual void modelChanged(); virtual void mouseDoubleClickEvent( QMouseEvent * event ); - + virtual void dragEnterEvent( QDragEnterEvent *dee ); + virtual void dropEvent( QDropEvent * de ); private: QMdiSubWindow * m_subWindow; diff --git a/src/gui/AutomationPatternView.cpp b/src/gui/AutomationPatternView.cpp index 6879b5bbd23..f317ab4086f 100644 --- a/src/gui/AutomationPatternView.cpp +++ b/src/gui/AutomationPatternView.cpp @@ -23,6 +23,7 @@ */ #include "AutomationPatternView.h" +#include #include #include #include @@ -434,10 +435,10 @@ void AutomationPatternView::dropEvent( QDropEvent * _de ) QString val = StringPairDrag::decodeValue( _de ); if( type == "automatable_model" ) { - AutomatableModel * mod = dynamic_cast( - Engine::projectJournal()-> - journallingObject( val.toInt() ) ); - if( mod != NULL ) + AutomatableModel * mod = Engine::getAutomatableModel( val, + _de->mimeData()->hasFormat( "application/x-osc-stringpair") ); + + if( mod ) { bool added = m_pat->addObject( mod ); if ( !added ) @@ -456,6 +457,8 @@ void AutomationPatternView::dropEvent( QDropEvent * _de ) { gui->automationEditor()->setCurrentPattern( m_pat ); } + + _de->acceptProposedAction(); } else { diff --git a/src/gui/editors/AutomationEditor.cpp b/src/gui/editors/AutomationEditor.cpp index e00c107d1dc..2dd3c2cb537 100644 --- a/src/gui/editors/AutomationEditor.cpp +++ b/src/gui/editors/AutomationEditor.cpp @@ -2464,10 +2464,10 @@ void AutomationEditorWindow::dropEvent( QDropEvent *_de ) QString val = StringPairDrag::decodeValue( _de ); if( type == "automatable_model" ) { - AutomatableModel * mod = dynamic_cast( - Engine::projectJournal()-> - journallingObject( val.toInt() ) ); - if( mod != NULL ) + AutomatableModel * mod = Engine::getAutomatableModel( val, + _de->mimeData()->hasFormat( "application/x-osc-stringpair") ); + + if( mod ) { bool added = m_editor->m_pattern->addObject( mod ); if ( !added ) @@ -2480,6 +2480,8 @@ void AutomationEditorWindow::dropEvent( QDropEvent *_de ) } setCurrentPattern( m_editor->m_pattern ); } + + _de->acceptProposedAction(); } update(); diff --git a/src/gui/widgets/ControllerView.cpp b/src/gui/widgets/ControllerView.cpp index b61ce12c44b..0c84dbe2e9d 100644 --- a/src/gui/widgets/ControllerView.cpp +++ b/src/gui/widgets/ControllerView.cpp @@ -35,12 +35,14 @@ #include "ControllerView.h" #include "CaptionMenu.h" +#include "ControllerConnection.h" #include "ControllerDialog.h" #include "gui_templates.h" #include "embed.h" #include "GuiApplication.h" #include "LedCheckbox.h" #include "MainWindow.h" +#include "StringPairDrag.h" #include "ToolTip.h" @@ -92,6 +94,7 @@ ControllerView::ControllerView( Controller * _model, QWidget * _parent ) : m_subWindow->hide(); setModel( _model ); + setAcceptDrops( true ); } @@ -157,6 +160,31 @@ void ControllerView::renameController() } } +void ControllerView::dragEnterEvent( QDragEnterEvent * dee ) +{ + StringPairDrag::processDragEnterEvent( dee, "automatable_model" ); +} + +void ControllerView::dropEvent(QDropEvent *de) +{ + QString type = StringPairDrag::decodeKey( de ); + QString val = StringPairDrag::decodeValue( de ); + // qDebug() << "DROP: type/val:" << type << ", " << val; + + if( type == "automatable_model" ) + { + AutomatableModel * mod = Engine::getAutomatableModel( val, + de->mimeData()->hasFormat( "application/x-osc-stringpair") ); + + mod->setControllerConnection( new ControllerConnection( getController() ) ); + + // tell the source app that the drop did succeed + de->acceptProposedAction(); + } + + update(); +} + void ControllerView::mouseDoubleClickEvent( QMouseEvent * event ) {