]> Creatis software - cpPlugins.git/blobdiff - lib/cpPipelineEditor/Block.cxx
...
[cpPlugins.git] / lib / cpPipelineEditor / Block.cxx
index 6d473efba274ba4f78e6ca396a44aeb3e868e46d..cd32453cb0c8299d9ec78cdfb7102360b3894c7d 100644 (file)
@@ -2,22 +2,31 @@
 \r
 #include <QPen>\r
 #include <QGraphicsScene>\r
+#include <QGraphicsSceneContextMenuEvent>\r
 #include <QFontMetrics>\r
+#include <QMenu>\r
 #include <QPainter>\r
 #include <QStyleOptionGraphicsItem>\r
+#include <QGraphicsWidget>\r
+\r
+#include <cpPlugins/ParametersQtDialog.h>\r
 \r
 #include "Port.h"\r
 #include "Connection.h"\r
+#include "Editor.h"\r
 \r
 // -------------------------------------------------------------------------\r
 cpPipelineEditor::Block::\r
-Block( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene )\r
+Block(\r
+  TFilter* filter, const QString& name,\r
+  QGraphicsItem* parent, QGraphicsScene* scene\r
+  )\r
   : Superclass( parent, scene ),\r
     m_HorzMargin( 20 ),\r
     m_VertMargin( 5 ),\r
     m_NamePort( NULL ),\r
-    m_TypePort( NULL ),\r
-    m_Filter( filter )\r
+    m_Filter( filter ),\r
+    m_Editor( NULL )\r
 {\r
   QPainterPath p;\r
   p.addRoundedRect( -50, -15, 100, 30, 5, 5 );\r
@@ -32,18 +41,16 @@ Block( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene )
   this->m_Height = this->m_VertMargin;\r
 \r
   // Configure names\r
-  this->setNamePort( this->m_Filter->GetName( ) );\r
-  this->_setTypePort( this->m_Filter->GetClassName( ) );\r
+  this->setNamePort( name );\r
+  this->_setTypeInfo( this->m_Filter->GetClassName( ) );\r
 \r
   // Add input ports\r
-  std::set< std::string > inputs;\r
-  this->m_Filter->GetInputsNames( inputs );\r
+  auto inputs = this->m_Filter->GetInputsNames( );\r
   for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )\r
     this->addInputPort( iIt->c_str( ) );\r
 \r
   // Add output ports\r
-  std::set< std::string > outputs;\r
-  this->m_Filter->GetOutputsNames( outputs );\r
+  auto outputs = this->m_Filter->GetOutputsNames( );\r
   for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )\r
     this->addOutputPort( oIt->c_str( ) );\r
 }\r
@@ -54,6 +61,27 @@ cpPipelineEditor::Block::
 {\r
 }\r
 \r
+// -------------------------------------------------------------------------\r
+cpPipelineEditor::Editor* cpPipelineEditor::Block::\r
+editor( )\r
+{\r
+  return( this->m_Editor );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+const cpPipelineEditor::Editor* cpPipelineEditor::Block::\r
+editor( ) const\r
+{\r
+  return( this->m_Editor );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpPipelineEditor::Block::\r
+setEditor( cpPipelineEditor::Editor* editor )\r
+{\r
+  this->m_Editor = editor;\r
+}\r
+\r
 // -------------------------------------------------------------------------\r
 void cpPipelineEditor::Block::\r
 setNamePort( const QString& txt )\r
@@ -183,12 +211,9 @@ itemChange( GraphicsItemChange change, const QVariant& value )
 \r
 // -------------------------------------------------------------------------\r
 void cpPipelineEditor::Block::\r
-_setTypePort( const QString& txt )\r
+_setTypeInfo( const QString& txt )\r
 {\r
-  if( this->m_TypePort == NULL )\r
-    this->m_TypePort = new TypePort( this );\r
-  this->m_TypePort->setName( txt );\r
-  this->_configPort( this->m_TypePort );\r
+  this->setToolTip( txt );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -198,12 +223,20 @@ _configPort( Port* port )
   port->setBlock( this );\r
 \r
   QFontMetrics fm( this->scene( )->font( ) );\r
-  int w = fm.width( port->name( ) ) + ( 4 * port->radius( ) );\r
+  this->m_Width = 0;\r
+  foreach( QGraphicsItem* i, this->children( ) )\r
+  {\r
+    Port* p = dynamic_cast< Port* >( i );\r
+    if( p == NULL )\r
+      continue;\r
+    int w = fm.width( p->name( ) ) + ( 4 * p->radius( ) );\r
+    if( w > this->m_Width - this->m_HorzMargin )\r
+      this->m_Width = w + this->m_HorzMargin;\r
+\r
+  } // rof\r
   int h = fm.height( );\r
-  if( w > this->m_Width - this->m_HorzMargin )\r
-    this->m_Width = w + this->m_HorzMargin;\r
   this->m_Height = this->m_InputPorts.size( ) + this->m_OutputPorts.size( );\r
-  this->m_Height += 4;\r
+  this->m_Height += 3;\r
   this->m_Height *= h;\r
 \r
   QPainterPath pth;\r
@@ -223,8 +256,6 @@ _configPort( Port* port )
       continue;\r
 \r
     if( dynamic_cast< NamePort* >( i ) != NULL )\r
-      i->setPos( -this->m_Width / 2 + port->radius( ), y );\r
-    else if( dynamic_cast< TypePort* >( i ) != NULL )\r
     {\r
       i->setPos( -this->m_Width / 2 + port->radius( ), y );\r
       y += h;\r
@@ -249,4 +280,22 @@ mouseReleaseEvent( QGraphicsSceneMouseEvent* evt )
   this->Superclass::mouseReleaseEvent( evt );\r
 }\r
 \r
+// -------------------------------------------------------------------------\r
+void cpPipelineEditor::Block::\r
+contextMenuEvent( QGraphicsSceneContextMenuEvent* evt )\r
+{\r
+  QMenu menu;\r
+  QAction* configureAction = menu.addAction( "Configure" );\r
+  QAction* updateAction = menu.addAction( "Update" );\r
+  QAction* selectedAction = menu.exec( evt->screenPos( ) );\r
+\r
+  if( selectedAction == configureAction )\r
+  {\r
+    auto dlg = this->m_Filter->CreateQtDialog( );\r
+    dlg->exec( );\r
+  }\r
+  else if( selectedAction == updateAction )\r
+    this->m_Editor->updateFilter( this->namePort( ).toStdString( ) );\r
+}\r
+\r
 // eof - $RCSfile$\r