X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPipelineEditor%2FBlock.cxx;h=cd32453cb0c8299d9ec78cdfb7102360b3894c7d;hb=e2fb8817731f6231d34941a208e46b36dad425b2;hp=96e60f8c3d2698c6cca5edc6d8b80f1dfe775f55;hpb=46f2cf7aa39bda8301b22fcfddd43daf0dc13770;p=cpPlugins.git diff --git a/lib/cpPipelineEditor/Block.cxx b/lib/cpPipelineEditor/Block.cxx index 96e60f8..cd32453 100644 --- a/lib/cpPipelineEditor/Block.cxx +++ b/lib/cpPipelineEditor/Block.cxx @@ -2,22 +2,31 @@ #include #include +#include #include +#include #include #include +#include + +#include #include "Port.h" #include "Connection.h" +#include "Editor.h" // ------------------------------------------------------------------------- cpPipelineEditor::Block:: -Block( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene ) +Block( + TFilter* filter, const QString& name, + QGraphicsItem* parent, QGraphicsScene* scene + ) : Superclass( parent, scene ), m_HorzMargin( 20 ), m_VertMargin( 5 ), m_NamePort( NULL ), - m_TypePort( NULL ), - m_Filter( filter ) + m_Filter( filter ), + m_Editor( NULL ) { QPainterPath p; p.addRoundedRect( -50, -15, 100, 30, 5, 5 ); @@ -32,18 +41,16 @@ Block( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene ) this->m_Height = this->m_VertMargin; // Configure names - this->setNamePort( this->m_Filter->GetName( ) ); - this->_setTypePort( this->m_Filter->GetClassName( ) ); + this->setNamePort( name ); + this->_setTypeInfo( this->m_Filter->GetClassName( ) ); // Add input ports - std::set< std::string > inputs; - this->m_Filter->GetInputsNames( inputs ); + auto inputs = this->m_Filter->GetInputsNames( ); for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt ) this->addInputPort( iIt->c_str( ) ); // Add output ports - std::set< std::string > outputs; - this->m_Filter->GetOutputsNames( outputs ); + auto outputs = this->m_Filter->GetOutputsNames( ); for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt ) this->addOutputPort( oIt->c_str( ) ); } @@ -54,6 +61,27 @@ cpPipelineEditor::Block:: { } +// ------------------------------------------------------------------------- +cpPipelineEditor::Editor* cpPipelineEditor::Block:: +editor( ) +{ + return( this->m_Editor ); +} + +// ------------------------------------------------------------------------- +const cpPipelineEditor::Editor* cpPipelineEditor::Block:: +editor( ) const +{ + return( this->m_Editor ); +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Block:: +setEditor( cpPipelineEditor::Editor* editor ) +{ + this->m_Editor = editor; +} + // ------------------------------------------------------------------------- void cpPipelineEditor::Block:: setNamePort( const QString& txt ) @@ -183,12 +211,9 @@ itemChange( GraphicsItemChange change, const QVariant& value ) // ------------------------------------------------------------------------- void cpPipelineEditor::Block:: -_setTypePort( const QString& txt ) +_setTypeInfo( const QString& txt ) { - if( this->m_TypePort == NULL ) - this->m_TypePort = new TypePort( this ); - this->m_TypePort->setName( txt ); - this->_configPort( this->m_TypePort ); + this->setToolTip( txt ); } // ------------------------------------------------------------------------- @@ -198,12 +223,20 @@ _configPort( Port* port ) port->setBlock( this ); QFontMetrics fm( this->scene( )->font( ) ); - int w = fm.width( port->name( ) ) + ( 4 * port->radius( ) ); + this->m_Width = 0; + foreach( QGraphicsItem* i, this->children( ) ) + { + Port* p = dynamic_cast< Port* >( i ); + if( p == NULL ) + continue; + int w = fm.width( p->name( ) ) + ( 4 * p->radius( ) ); + if( w > this->m_Width - this->m_HorzMargin ) + this->m_Width = w + this->m_HorzMargin; + + } // rof int h = fm.height( ); - if( w > this->m_Width - this->m_HorzMargin ) - this->m_Width = w + this->m_HorzMargin; this->m_Height = this->m_InputPorts.size( ) + this->m_OutputPorts.size( ); - this->m_Height += 4; + this->m_Height += 3; this->m_Height *= h; QPainterPath pth; @@ -223,8 +256,6 @@ _configPort( Port* port ) continue; if( dynamic_cast< NamePort* >( i ) != NULL ) - i->setPos( -this->m_Width / 2 + port->radius( ), y ); - else if( dynamic_cast< TypePort* >( i ) != NULL ) { i->setPos( -this->m_Width / 2 + port->radius( ), y ); y += h; @@ -233,17 +264,6 @@ _configPort( Port* port ) i->setPos( -this->m_Width / 2 - 2 * port->radius( ), y ); else if( dynamic_cast< OutputPort* >( i ) != NULL ) i->setPos( this->m_Width / 2, y ); - - /* TODO - Port* p = dynamic_cast< Port* >( i ); - if( p == NULL ) - continue; - - if( dynamic_cast< OutputPort* >( p ) != NULL ) - p->setPos( this->m_Width / 2 + port->radius( ), y ); - else - p->setPos( -this->m_Width / 2 - port->radius( ), y ); - */ y += h; } // rof @@ -260,4 +280,22 @@ mouseReleaseEvent( QGraphicsSceneMouseEvent* evt ) this->Superclass::mouseReleaseEvent( evt ); } +// ------------------------------------------------------------------------- +void cpPipelineEditor::Block:: +contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ) +{ + QMenu menu; + QAction* configureAction = menu.addAction( "Configure" ); + QAction* updateAction = menu.addAction( "Update" ); + QAction* selectedAction = menu.exec( evt->screenPos( ) ); + + if( selectedAction == configureAction ) + { + auto dlg = this->m_Filter->CreateQtDialog( ); + dlg->exec( ); + } + else if( selectedAction == updateAction ) + this->m_Editor->updateFilter( this->namePort( ).toStdString( ) ); +} + // eof - $RCSfile$