]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 7 Apr 2017 19:41:48 +0000 (14:41 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 7 Apr 2017 19:41:48 +0000 (14:41 -0500)
libs/cpPipelineEditor/Block.cxx
libs/cpPipelineEditor/Block.h
libs/cpPipelineEditor/Canvas.cxx
libs/cpPipelineEditor/Canvas.h

index 315b197117ef55fa2de6dff5cb1c606d5fd37368..d04d5fee82c8b7afc07e9cdc408ec19123352e60 100644 (file)
@@ -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 );
+  */
 }
 
 // -------------------------------------------------------------------------
index 7e6fa2592ae046f445f943f2523534f2c0e4ea8b..d06964a73bffe3e64e138b420f46ff1d36e15e86 100644 (file)
@@ -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,
index 0015421e15ed281a6c328aa050e61970e857dbc0..20f4b7aa0859f1f6aa27fcbcbab4c9065d5746c0 100644 (file)
@@ -2,13 +2,6 @@
 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
 // -------------------------------------------------------------------------
 
-
-#include <iostream>
-
-
-
-
-
 #include <cpPipelineEditor/Canvas.h>
 #include <cpPipelineEditor/FilterBlock.h>
 #include <cpPipelineEditor/FunctorBlock.h>
@@ -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$
index 512dc2fc920b778cd793f9ad3ad1fd61ba9ff629..7259a653bb0ccb65cc37e494ee05db301c60c40f 100644 (file)
@@ -39,6 +39,7 @@ namespace cpPipelineEditor
 
   protected:
     QGraphicsScene* m_Scene;
+    Block* m_DraggedBlock;
   };
 
 } // ecapseman