Skip to content

Commit

Permalink
Allow dropping automation in more ways
Browse files Browse the repository at this point in the history
This enables DnD from internal and spa knobs on

* Controller views (from the controller rack)
* Existing Automation Patterns
* Automation Editors
  • Loading branch information
JohannesLorenz committed Oct 22, 2018
1 parent 1a5c0e0 commit 7e7044d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
3 changes: 2 additions & 1 deletion include/ControllerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions src/gui/AutomationPatternView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
#include "AutomationPatternView.h"

#include <QDebug>
#include <QMouseEvent>
#include <QPainter>
#include <QMenu>
Expand Down Expand Up @@ -434,10 +435,10 @@ void AutomationPatternView::dropEvent( QDropEvent * _de )
QString val = StringPairDrag::decodeValue( _de );
if( type == "automatable_model" )
{
AutomatableModel * mod = dynamic_cast<AutomatableModel *>(
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 )
Expand All @@ -456,6 +457,8 @@ void AutomationPatternView::dropEvent( QDropEvent * _de )
{
gui->automationEditor()->setCurrentPattern( m_pat );
}

_de->acceptProposedAction();
}
else
{
Expand Down
10 changes: 6 additions & 4 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2464,10 +2464,10 @@ void AutomationEditorWindow::dropEvent( QDropEvent *_de )
QString val = StringPairDrag::decodeValue( _de );
if( type == "automatable_model" )
{
AutomatableModel * mod = dynamic_cast<AutomatableModel *>(
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 )
Expand All @@ -2480,6 +2480,8 @@ void AutomationEditorWindow::dropEvent( QDropEvent *_de )
}
setCurrentPattern( m_editor->m_pattern );
}

_de->acceptProposedAction();
}

update();
Expand Down
28 changes: 28 additions & 0 deletions src/gui/widgets/ControllerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -92,6 +94,7 @@ ControllerView::ControllerView( Controller * _model, QWidget * _parent ) :
m_subWindow->hide();

setModel( _model );
setAcceptDrops( true );
}


Expand Down Expand Up @@ -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 )
{
Expand Down

0 comments on commit 7e7044d

Please sign in to comment.