From: Leonardo Flórez-Valencia Date: Fri, 7 Apr 2017 19:41:48 +0000 (-0500) Subject: ... X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=56fa477e9ef35f1a93d6a30885a6b659f6717cfe;p=cpPlugins.git ... --- diff --git a/libs/cpPipelineEditor/Block.cxx b/libs/cpPipelineEditor/Block.cxx index 315b197..d04d5fe 100644 --- a/libs/cpPipelineEditor/Block.cxx +++ b/libs/cpPipelineEditor/Block.cxx @@ -9,14 +9,16 @@ Block( QGraphicsItem* parent, QGraphicsScene* scene ) this->m_SelectedColor = Qt::darkYellow; this->m_NotSelectedColor = Qt::darkGreen; - QPainterPath p; - p.addRoundedRect( -50, -50, 50, 50, 5, 5 ); - - this->setPath( p ); - this->setPen( QPen( this->m_NotSelectedColor ) ); - this->setBrush( this->m_NotSelectedColor ); - this->setFlag( QGraphicsItem::ItemIsMovable ); - this->setFlag( QGraphicsItem::ItemIsSelectable ); + /* TODO + QPainterPath p; + p.addRect( -50, -50, 50, 50 ); + + this->setPath( p ); + this->setPen( QPen( this->m_NotSelectedColor ) ); + this->setBrush( this->m_NotSelectedColor ); + this->setFlag( QGraphicsItem::ItemIsMovable ); + this->setFlag( QGraphicsItem::ItemIsSelectable ); + */ } // ------------------------------------------------------------------------- diff --git a/libs/cpPipelineEditor/Block.h b/libs/cpPipelineEditor/Block.h index 7e6fa25..d06964a 100644 --- a/libs/cpPipelineEditor/Block.h +++ b/libs/cpPipelineEditor/Block.h @@ -21,6 +21,12 @@ namespace cpPipelineEditor ); virtual ~Block( ); + void setClassName( const std::string& name ); + void setObjectName( const std::string& name ); + void setNumberOfInputs( unsigned int n ); + void setNumberOfOutputs( unsigned int n ); + void setNumberOfParameters( unsigned int n ); + virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, diff --git a/libs/cpPipelineEditor/Canvas.cxx b/libs/cpPipelineEditor/Canvas.cxx index 0015421..20f4b7a 100644 --- a/libs/cpPipelineEditor/Canvas.cxx +++ b/libs/cpPipelineEditor/Canvas.cxx @@ -2,13 +2,6 @@ // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) // ------------------------------------------------------------------------- - -#include - - - - - #include #include #include @@ -20,7 +13,8 @@ // ------------------------------------------------------------------------- cpPipelineEditor::Canvas:: Canvas( QWidget* parent ) - : Superclass( parent ) + : Superclass( parent ), + m_DraggedBlock( NULL ) { this->m_Scene = new QGraphicsScene( this ); this->setScene( this->m_Scene ); @@ -48,6 +42,7 @@ createBlock( const std::string& name ) new_block = new FunctorBlock( NULL, this->m_Scene ); else if( block_type == "Widgets" ) new_block = new WidgetBlock( NULL, this->m_Scene ); + new_block->setPos( 0, 0 ); return( new_block ); } @@ -57,52 +52,88 @@ dragEnterEvent( QDragEnterEvent* event ) { const QMimeData* mime = event->mimeData( ); if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) + { + if( this->m_DraggedBlock == NULL ) + { + QTreeWidget* tree = dynamic_cast< QTreeWidget* >( event->source( ) ); + if( tree != NULL ) + { + // Process dropped data + QList< QTreeWidgetItem* > items = tree->selectedItems( ); + for( QTreeWidgetItem* item : items ) + { + std::string name = ""; + QTreeWidgetItem* p = item; + while( p != NULL ) + { + name += p->text( 0 ).toStdString( ) + "@"; + p = p->parent( ); + + } // elihw + name.resize( name.size( ) - 1 ); + + // Create block + this->m_DraggedBlock = this->createBlock( name ); + QPoint drop_pos = event->pos( ); + QPointF scene_pos = this->mapToScene( drop_pos ); + this->m_DraggedBlock->setPos( scene_pos ); + + } // rof + + } // fi + + } // fi event->acceptProposedAction( ); + } + else + event->ignore( ); } // ------------------------------------------------------------------------- void cpPipelineEditor::Canvas:: dragLeaveEvent( QDragLeaveEvent* event ) { + if( this->m_DraggedBlock != NULL ) + { + delete this->m_DraggedBlock; + this->m_DraggedBlock = NULL; + + } // fi + event->accept( ); } // ------------------------------------------------------------------------- void cpPipelineEditor::Canvas:: dragMoveEvent( QDragMoveEvent* event ) { + const QMimeData* mime = event->mimeData( ); + if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) + { + if( this->m_DraggedBlock != NULL ) + { + QPoint drop_pos = event->pos( ); + QPointF scene_pos = this->mapToScene( drop_pos ); + this->m_DraggedBlock->setPos( scene_pos ); + + } // fi + event->acceptProposedAction( ); + } + else + event->ignore( ); } // ------------------------------------------------------------------------- void cpPipelineEditor::Canvas:: dropEvent( QDropEvent* event ) { - // Get dropped data const QMimeData* mime = event->mimeData( ); - if( !( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) ) - return; - event->acceptProposedAction( ); - QTreeWidget* tree = dynamic_cast< QTreeWidget* >( event->source( ) ); - if( tree == NULL ) - return; - - // Process dropped data - QList< QTreeWidgetItem* > items = tree->selectedItems( ); - for( QTreeWidgetItem* item : items ) + if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) { - std::string name = ""; - QTreeWidgetItem* p = item; - while( p != NULL ) - { - name += p->text( 0 ).toStdString( ) + "@"; - p = p->parent( ); - - } // elihw - name.resize( name.size( ) - 1 ); - - // Create block - Block* b = this->createBlock( name ); - - } // rof + this->m_DraggedBlock = NULL; + event->acceptProposedAction( ); + } + else + event->ignore( ); } // eof - $RCSfile$ diff --git a/libs/cpPipelineEditor/Canvas.h b/libs/cpPipelineEditor/Canvas.h index 512dc2f..7259a65 100644 --- a/libs/cpPipelineEditor/Canvas.h +++ b/libs/cpPipelineEditor/Canvas.h @@ -39,6 +39,7 @@ namespace cpPipelineEditor protected: QGraphicsScene* m_Scene; + Block* m_DraggedBlock; }; } // ecapseman