1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
12 #include <cpPipelineEditor/Canvas.h>
13 #include <cpPipelineEditor/FilterBlock.h>
14 #include <cpPipelineEditor/FunctorBlock.h>
15 #include <cpPipelineEditor/WidgetBlock.h>
17 #include <QDragEnterEvent>
18 #include <QTreeWidget>
20 // -------------------------------------------------------------------------
21 cpPipelineEditor::Canvas::
22 Canvas( QWidget* parent )
23 : Superclass( parent )
25 this->m_Scene = new QGraphicsScene( this );
26 this->setScene( this->m_Scene );
27 this->setRenderHint( QPainter::Antialiasing );
28 this->setAcceptDrops( true );
31 // -------------------------------------------------------------------------
32 cpPipelineEditor::Canvas::
37 // -------------------------------------------------------------------------
38 cpPipelineEditor::Block* cpPipelineEditor::Canvas::
39 createBlock( const std::string& name )
41 QString str = name.c_str( );
42 QStringList tokens = str.split( "@" );
43 std::string block_type = tokens.back( ).toStdString( );
44 Block* new_block = NULL;
45 if( block_type == "Filters" )
46 new_block = new FilterBlock( NULL, this->m_Scene );
47 else if( block_type == "Functors" )
48 new_block = new FunctorBlock( NULL, this->m_Scene );
49 else if( block_type == "Widgets" )
50 new_block = new WidgetBlock( NULL, this->m_Scene );
54 // -------------------------------------------------------------------------
55 void cpPipelineEditor::Canvas::
56 dragEnterEvent( QDragEnterEvent* event )
58 const QMimeData* mime = event->mimeData( );
59 if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) )
60 event->acceptProposedAction( );
63 // -------------------------------------------------------------------------
64 void cpPipelineEditor::Canvas::
65 dragLeaveEvent( QDragLeaveEvent* event )
69 // -------------------------------------------------------------------------
70 void cpPipelineEditor::Canvas::
71 dragMoveEvent( QDragMoveEvent* event )
75 // -------------------------------------------------------------------------
76 void cpPipelineEditor::Canvas::
77 dropEvent( QDropEvent* event )
80 const QMimeData* mime = event->mimeData( );
81 if( !( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) )
83 event->acceptProposedAction( );
84 QTreeWidget* tree = dynamic_cast< QTreeWidget* >( event->source( ) );
88 // Process dropped data
89 QList< QTreeWidgetItem* > items = tree->selectedItems( );
90 for( QTreeWidgetItem* item : items )
92 std::string name = "";
93 QTreeWidgetItem* p = item;
96 name += p->text( 0 ).toStdString( ) + "@";
100 name.resize( name.size( ) - 1 );
103 Block* b = this->createBlock( name );