From: Leonardo Florez-Valencia Date: Mon, 25 Jan 2016 00:15:51 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~259 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=d9e804f90306f67051b8f0c756f0c9148e492d90;p=cpPlugins.git ... --- diff --git a/lib/cpPipelineEditor/Block.cxx b/lib/cpPipelineEditor/Block.cxx index bce1197..0cc3bd4 100644 --- a/lib/cpPipelineEditor/Block.cxx +++ b/lib/cpPipelineEditor/Block.cxx @@ -20,7 +20,6 @@ Block( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene ) m_HorzMargin( 20 ), m_VertMargin( 5 ), m_NamePort( NULL ), - m_TypePort( NULL ), m_Filter( filter ), m_Editor( NULL ) { @@ -38,7 +37,7 @@ Block( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene ) // Configure names this->setNamePort( this->m_Filter->GetName( ) ); - this->_setTypePort( this->m_Filter->GetClassName( ) ); + this->_setTypeInfo( this->m_Filter->GetClassName( ) ); // Add input ports auto inputs = this->m_Filter->GetInputsNames( ); @@ -207,14 +206,8 @@ itemChange( GraphicsItemChange change, const QVariant& value ) // ------------------------------------------------------------------------- void cpPipelineEditor::Block:: -_setTypePort( const QString& txt ) +_setTypeInfo( const QString& txt ) { - /* TODO - if( this->m_TypePort == NULL ) - this->m_TypePort = new TypePort( this ); - this->m_TypePort->setName( txt ); - this->_configPort( this->m_TypePort ); - */ this->setToolTip( txt ); } @@ -225,12 +218,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; @@ -250,8 +251,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; @@ -286,9 +285,7 @@ contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ) QAction* selectedAction = menu.exec( evt->screenPos( ) ); if( selectedAction == configureAction ) - { auto res = this->m_Filter->ExecConfigurationDialog( NULL ); - } else if( selectedAction == updateAction ) this->m_Editor->updateFilter( this->namePort( ).toStdString( ) ); } diff --git a/lib/cpPipelineEditor/Block.h b/lib/cpPipelineEditor/Block.h index b6a7b33..bbdb0c6 100644 --- a/lib/cpPipelineEditor/Block.h +++ b/lib/cpPipelineEditor/Block.h @@ -10,7 +10,6 @@ namespace cpPipelineEditor class Editor; class Port; class NamePort; - class TypePort; class InputPort; class OutputPort; @@ -59,7 +58,7 @@ namespace cpPipelineEditor protected: QVariant itemChange( GraphicsItemChange change, const QVariant& value ); - void _setTypePort( const QString& txt ); + void _setTypeInfo( const QString& txt ); void _configPort( Port* port ); virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* evt ); @@ -72,7 +71,6 @@ namespace cpPipelineEditor int m_Height; NamePort* m_NamePort; - TypePort* m_TypePort; std::map< std::string, InputPort* > m_InputPorts; std::map< std::string, OutputPort* > m_OutputPorts; diff --git a/lib/cpPipelineEditor/Connection.cxx b/lib/cpPipelineEditor/Connection.cxx index 59f66c0..0d5eea2 100644 --- a/lib/cpPipelineEditor/Connection.cxx +++ b/lib/cpPipelineEditor/Connection.cxx @@ -15,6 +15,7 @@ Connection( QGraphicsItem* parent, QGraphicsScene* scene ) this->setZValue( -1 ); this->m_Port1 = NULL; this->m_Port2 = NULL; + this->setFlag( QGraphicsItem::ItemIsSelectable ); } // ------------------------------------------------------------------------- @@ -115,4 +116,25 @@ port2( ) const return( this->m_Port2 ); } +#include + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Connection:: +paint( + QPainter* painter, + const QStyleOptionGraphicsItem* option, + QWidget* widget + ) +{ + Q_UNUSED( option ); + Q_UNUSED( widget ); + + if( this->isSelected( ) ) + painter->setPen( QPen( Qt::red, 5 ) ); + else + painter->setPen( QPen( Qt::black, 2 ) ); + this->setBrush( Qt::NoBrush ); + painter->drawPath( this->path( ) ); +} + // eof - $RCSfile$ diff --git a/lib/cpPipelineEditor/Connection.h b/lib/cpPipelineEditor/Connection.h index b7eb26e..94b8676 100644 --- a/lib/cpPipelineEditor/Connection.h +++ b/lib/cpPipelineEditor/Connection.h @@ -36,6 +36,12 @@ namespace cpPipelineEditor inline int type( ) const { return( this->Type ); } + virtual void paint( + QPainter* painter, + const QStyleOptionGraphicsItem* option, + QWidget* widget + ); + private: QPointF m_Pos1; QPointF m_Pos2; diff --git a/lib/cpPipelineEditor/Port.cxx b/lib/cpPipelineEditor/Port.cxx index a2125f7..b447b0a 100644 --- a/lib/cpPipelineEditor/Port.cxx +++ b/lib/cpPipelineEditor/Port.cxx @@ -124,37 +124,6 @@ isConnected( Port* other ) return( false ); } -// ------------------------------------------------------------------------- -cpPipelineEditor::TypePort:: -TypePort( QGraphicsItem* parent, QGraphicsScene* scene ) - : Superclass( parent, scene ) -{ -} - -// ------------------------------------------------------------------------- -cpPipelineEditor::TypePort:: -~TypePort( ) -{ -} - -// ------------------------------------------------------------------------- -void cpPipelineEditor::TypePort:: -_updateLabels( ) -{ - QFont font( this->scene( )->font( ) ); - font.setItalic( true ); - this->m_Label->setFont( font ); - this->m_ExtendedLabel->setFont( font ); - this->setPath( QPainterPath( ) ); -} - -// ------------------------------------------------------------------------- -bool cpPipelineEditor::TypePort:: -isConnected( Port* other ) -{ - return( false ); -} - // ------------------------------------------------------------------------- cpPipelineEditor::InputPort:: InputPort( QGraphicsItem* parent, QGraphicsScene* scene ) diff --git a/lib/cpPipelineEditor/Port.h b/lib/cpPipelineEditor/Port.h index 18bcd94..4daafd0 100644 --- a/lib/cpPipelineEditor/Port.h +++ b/lib/cpPipelineEditor/Port.h @@ -89,29 +89,6 @@ namespace cpPipelineEditor virtual void _updateLabels( ); }; - /** - */ - class TypePort - : public Port - { - public: - typedef TypePort Self; - typedef Port Superclass; - - enum { Type = Superclass::Type + 2 }; - - public: - TypePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); - virtual ~TypePort( ); - - virtual bool isConnected( Port* other ); - inline int type( ) const - { return( this->Type ); } - - protected: - virtual void _updateLabels( ); - }; - /** */ class InputPort