From: Leonardo Florez-Valencia Date: Wed, 13 Jan 2016 23:37:37 +0000 (-0500) Subject: More on graph editor X-Git-Tag: v0.1~271 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=c06908465eb6da50572779f423d1e2c9e03b68dd;p=cpPlugins.git More on graph editor --- diff --git a/appli/cpPipelineEditor/QNEBlock.cxx b/appli/cpPipelineEditor/QNEBlock.cxx index 2b7ed51..67f4a9b 100644 --- a/appli/cpPipelineEditor/QNEBlock.cxx +++ b/appli/cpPipelineEditor/QNEBlock.cxx @@ -33,6 +33,7 @@ #include #include "QNEPort.h" +#include "QNEConnection.h" // ------------------------------------------------------------------------- PipelineEditor::QNEBlock:: @@ -95,6 +96,13 @@ PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: addInputPort( const QString& txt ) { QNEInputPort* ip = new QNEInputPort( this ); + ip->setExtendedName( + ( + txt.toStdString( ) + + std::string( "@" ) + + this->namePort( ).toStdString( ) + ).c_str( ) + ); ip->setName( txt ); this->m_InputPorts[ txt.toStdString( ) ] = ip; this->_configPort( ip ); @@ -106,12 +114,49 @@ PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: addOutputPort( const QString& txt ) { QNEOutputPort* op = new QNEOutputPort( this ); + op->setExtendedName( + ( + txt.toStdString( ) + + std::string( "@" ) + + this->namePort( ).toStdString( ) + ).c_str( ) + ); op->setName( txt ); this->m_OutputPorts[ txt.toStdString( ) ] = op; this->_configPort( op ); return( op ); } +// ------------------------------------------------------------------------- +bool PipelineEditor::QNEBlock:: +extendInputPort( const QString& txt, QNEConnection* conn ) +{ + auto p = this->m_InputPorts.find( txt.toStdString( ) ); + auto i = this->m_ExtInputPorts.find( txt.toStdString( ) ); + if( p != this->m_InputPorts.end( ) && i == this->m_ExtInputPorts.end( ) ) + { + this->m_ExtInputPorts[ txt.toStdString( ) ] = conn; + return( true ); + } + else + return( false ); +} + +// ------------------------------------------------------------------------- +bool PipelineEditor::QNEBlock:: +extendOutputPort( const QString& txt, QNEConnection* conn ) +{ + auto p = this->m_OutputPorts.find( txt.toStdString( ) ); + auto i = this->m_ExtOutputPorts.find( txt.toStdString( ) ); + if( p != this->m_OutputPorts.end( ) && i == this->m_ExtOutputPorts.end( ) ) + { + this->m_ExtOutputPorts[ txt.toStdString( ) ] = conn; + return( true ); + } + else + return( false ); +} + // ------------------------------------------------------------------------- PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: inputPort( const QString& txt ) @@ -134,6 +179,13 @@ outputPort( const QString& txt ) return( NULL ); } +// ------------------------------------------------------------------------- +QString PipelineEditor::QNEBlock:: +namePort( ) const +{ + return( this->m_NamePort->name( ) ); +} + // ------------------------------------------------------------------------- const PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: inputPort( const QString& txt ) const @@ -157,10 +209,25 @@ outputPort( const QString& txt ) const } // ------------------------------------------------------------------------- -const QString& PipelineEditor::QNEBlock:: -namePort( ) const +const PipelineEditor::QNEConnection* PipelineEditor::QNEBlock:: +extendedInputPort( const QString& txt ) const { - return( this->m_NamePort->name( ) ); + auto i = this->m_ExtInputPorts.find( txt.toStdString( ) ); + if( i != this->m_ExtInputPorts.end( ) ) + return( i->second ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +const PipelineEditor::QNEConnection* PipelineEditor::QNEBlock:: +extendedOutputPort( const QString& txt ) const +{ + auto i = this->m_ExtOutputPorts.find( txt.toStdString( ) ); + if( i != this->m_ExtOutputPorts.end( ) ) + return( i->second ); + else + return( NULL ); } // ------------------------------------------------------------------------- @@ -210,11 +277,13 @@ _configPort( QNEPort* port ) port->setBlock( this ); QFontMetrics fm( this->scene( )->font( ) ); - int w = fm.width( port->name( ) ); + int w = fm.width( port->name( ) ) + ( 4 * port->radius( ) ); int h = fm.height( ); if( w > this->m_Width - this->m_HorzMargin ) this->m_Width = w + this->m_HorzMargin; - this->m_Height += h; + this->m_Height = this->m_InputPorts.size( ) + this->m_OutputPorts.size( ); + this->m_Height += 4; + this->m_Height *= h; QPainterPath pth; pth.addRoundedRect( @@ -232,10 +301,28 @@ _configPort( QNEPort* port ) if( p == NULL ) continue; - if( dynamic_cast< QNEOutputPort* >( p ) != NULL ) - p->setPos( this->m_Width / 2 + port->radius( ), y ); - else - p->setPos( -this->m_Width / 2 - port->radius( ), y ); + if( dynamic_cast< QNENamePort* >( i ) != NULL ) + i->setPos( -this->m_Width / 2 + port->radius( ), y ); + else if( dynamic_cast< QNETypePort* >( i ) != NULL ) + { + i->setPos( -this->m_Width / 2 + port->radius( ), y ); + y += h; + } + else if( dynamic_cast< QNEInputPort* >( i ) != NULL ) + i->setPos( -this->m_Width / 2 - 2 * port->radius( ), y ); + else if( dynamic_cast< QNEOutputPort* >( i ) != NULL ) + i->setPos( this->m_Width / 2, y ); + + /* TODO + QNEPort* p = dynamic_cast< QNEPort* >( i ); + if( p == NULL ) + continue; + + if( dynamic_cast< QNEOutputPort* >( p ) != NULL ) + p->setPos( this->m_Width / 2 + port->radius( ), y ); + else + p->setPos( -this->m_Width / 2 - port->radius( ), y ); + */ y += h; } // rof diff --git a/appli/cpPipelineEditor/QNEBlock.h b/appli/cpPipelineEditor/QNEBlock.h index d1a398e..8e95ce0 100644 --- a/appli/cpPipelineEditor/QNEBlock.h +++ b/appli/cpPipelineEditor/QNEBlock.h @@ -37,6 +37,7 @@ namespace PipelineEditor class QNETypePort; class QNEInputPort; class QNEOutputPort; + class QNEConnection; class QNEBlock : public QGraphicsPathItem @@ -58,17 +59,23 @@ namespace PipelineEditor void setNamePort( const QString& txt ); QNEInputPort* addInputPort( const QString& txt ); QNEOutputPort* addOutputPort( const QString& txt ); + + bool extendInputPort( const QString& txt, QNEConnection* conn ); + bool extendOutputPort( const QString& txt, QNEConnection* conn ); + QNEInputPort* inputPort( const QString& txt ); QNEOutputPort* outputPort( const QString& txt ); - const QString& namePort( ) const; + QString namePort( ) const; const QNEInputPort* inputPort( const QString& txt ) const; const QNEOutputPort* outputPort( const QString& txt ) const; + const QNEConnection* extendedInputPort( const QString& txt ) const; + const QNEConnection* extendedOutputPort( const QString& txt ) const; inline int type( ) const { return( this->Type ); } - void paint( + virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget @@ -91,6 +98,8 @@ namespace PipelineEditor QNETypePort* m_TypePort; std::map< std::string, QNEInputPort* > m_InputPorts; std::map< std::string, QNEOutputPort* > m_OutputPorts; + std::map< std::string, QNEConnection* > m_ExtOutputPorts; + std::map< std::string, QNEConnection* > m_ExtInputPorts; TFilter::Pointer m_Filter; }; diff --git a/appli/cpPipelineEditor/QNEConnection.cxx b/appli/cpPipelineEditor/QNEConnection.cxx index df84c81..c79bb7e 100644 --- a/appli/cpPipelineEditor/QNEConnection.cxx +++ b/appli/cpPipelineEditor/QNEConnection.cxx @@ -101,8 +101,14 @@ setPort2( QNEInputPort* p ) void PipelineEditor::QNEConnection:: updatePosFromPorts( ) { - this->m_Pos1 = this->m_Port1->scenePos( ); - this->m_Pos2 = this->m_Port2->scenePos( ); + if( this->m_Port1 != NULL ) + this->m_Pos1 = + this->m_Port1->scenePos( ) + + QPointF( this->m_Port1->radius( ), this->m_Port1->radius( ) ); + if( this->m_Port2 != NULL ) + this->m_Pos2 = + this->m_Port2->scenePos( ) + + QPointF( this->m_Port2->radius( ), this->m_Port2->radius( ) ); } // ------------------------------------------------------------------------- diff --git a/appli/cpPipelineEditor/QNEPort.cxx b/appli/cpPipelineEditor/QNEPort.cxx index 6aa653b..7b71975 100644 --- a/appli/cpPipelineEditor/QNEPort.cxx +++ b/appli/cpPipelineEditor/QNEPort.cxx @@ -29,6 +29,7 @@ #include #include +#include #include // ------------------------------------------------------------------------- @@ -39,12 +40,11 @@ QNEPort( QGraphicsItem* parent, QGraphicsScene* scene ) m_Margin( 2 ) { this->m_Label = new QGraphicsTextItem( this ); + this->m_ExtendedLabel = new QGraphicsTextItem( this ); + this->setExtend( false ); QPainterPath p; - p.addEllipse( - -this->m_Radius, -this->m_Radius, - 2 * this->m_Radius, 2 * this->m_Radius - ); + p.addEllipse( 0, 0, 2 * this->m_Radius, 2 * this->m_Radius ); this->setPath( p ); this->setPen( QPen( Qt::darkRed ) ); @@ -69,15 +69,50 @@ setBlock( QNEBlock* b ) void PipelineEditor::QNEPort:: setName( const QString& n ) { - this->m_Name = n; this->m_Label->setPlainText( n ); + this->_updateLabels( ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEPort:: +setExtendedName( const QString& n ) +{ + this->m_ExtendedLabel->setPlainText( n ); + this->_updateLabels( ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEPort:: +setExtend( bool extend ) +{ + // Do nothing! + this->m_IsExtended = false; + this->m_ExtendedLabel->setVisible( false ); } // ------------------------------------------------------------------------- void PipelineEditor::QNEPort:: -setPtr( quint64 p ) +paint( + QPainter* painter, + const QStyleOptionGraphicsItem* option, + QWidget* widget + ) { - this->m_Ptr = p; + Q_UNUSED( option ); + Q_UNUSED( widget ); + + if( this->isExtended( ) ) + { + painter->setPen( QPen( Qt::darkBlue ) ); + painter->setBrush( Qt::blue ); + } + else + { + painter->setPen( QPen( Qt::darkRed ) ); + painter->setBrush( Qt::red ); + + } // fi + painter->drawPath( this->path( ) ); } // ------------------------------------------------------------------------- @@ -95,13 +130,12 @@ PipelineEditor::QNENamePort:: // ------------------------------------------------------------------------- void PipelineEditor::QNENamePort:: -setName( const QString& n ) +_updateLabels( ) { - this->Superclass::setName( n ); - QFont font( this->scene( )->font( ) ); font.setBold( true ); this->m_Label->setFont( font ); + this->m_ExtendedLabel->setFont( font ); this->setPath( QPainterPath( ) ); } @@ -127,13 +161,12 @@ PipelineEditor::QNETypePort:: // ------------------------------------------------------------------------- void PipelineEditor::QNETypePort:: -setName( const QString& n ) +_updateLabels( ) { - this->Superclass::setName( n ); - QFont font( this->scene( )->font( ) ); font.setItalic( true ); this->m_Label->setFont( font ); + this->m_ExtendedLabel->setFont( font ); this->setPath( QPainterPath( ) ); } @@ -162,15 +195,27 @@ PipelineEditor::QNEInputPort:: // ------------------------------------------------------------------------- void PipelineEditor::QNEInputPort:: -setName( const QString& n ) +_updateLabels( ) { - this->Superclass::setName( n ); - QFontMetrics fm( this->scene( )->font( ) ); - QRect r = fm.boundingRect( this->m_Name ); - int rm = this->m_Radius + this->m_Margin; - int h = -this->m_Label->boundingRect( ).height( ) / 2; - this->m_Label->setPos( rm, h ); + this->m_Label->setPos( this->m_Radius * 2, -fm.height( ) / 2 ); + this->m_ExtendedLabel->setPos( + -fm.width( this->extendedName( ) ) - this->m_Radius * 2, + -fm.height( ) / 2 + ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEInputPort:: +setExtend( bool extend ) +{ + if( this->m_Connection == NULL ) + { + this->m_IsExtended = extend; + this->m_ExtendedLabel->setVisible( extend ); + } + else + this->Superclass::setExtend( false ); } // ------------------------------------------------------------------------- @@ -227,17 +272,22 @@ PipelineEditor::QNEOutputPort:: // ------------------------------------------------------------------------- void PipelineEditor::QNEOutputPort:: -setName( const QString& n ) +_updateLabels( ) { - this->Superclass::setName( n ); - QFontMetrics fm( this->scene( )->font( ) ); - QRect r = fm.boundingRect( this->m_Name ); - int rm = this->m_Radius + this->m_Margin; - int h = -this->m_Label->boundingRect( ).height( ) / 2; this->m_Label->setPos( - -rm - this->m_Label->boundingRect( ).width( ), h + -fm.width( this->name( ) ) - this->m_Radius * 2, -fm.height( ) / 2 ); + this->m_ExtendedLabel->setPos( this->m_Radius * 2, -fm.height( ) / 2 ); + +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEOutputPort:: +setExtend( bool extend ) +{ + this->m_IsExtended = extend; + this->m_ExtendedLabel->setVisible( extend ); } // ------------------------------------------------------------------------- diff --git a/appli/cpPipelineEditor/QNEPort.h b/appli/cpPipelineEditor/QNEPort.h index 383167b..e10af5e 100644 --- a/appli/cpPipelineEditor/QNEPort.h +++ b/appli/cpPipelineEditor/QNEPort.h @@ -54,28 +54,41 @@ namespace PipelineEditor { return( this->m_Block ); } virtual void setName( const QString& n ); - inline const QString& name( ) const - { return( this->m_Name ); } - - void setPtr( quint64 p ); - inline quint64 ptr( ) - { return( this->m_Ptr ); } + virtual void setExtendedName( const QString& n ); + inline QString name( ) const + { return( this->m_Label->toPlainText( ) ); } + inline QString extendedName( ) const + { return( this->m_ExtendedLabel->toPlainText( ) ); } inline int radius( ) const { return( this->m_Radius ); } + inline bool isExtended( ) const + { return( this->m_IsExtended ); } + virtual void setExtend( bool extend ); + virtual bool isConnected( QNEPort* other ) = 0; inline int type( ) const { return( this->Type ); } + virtual void paint( + QPainter* painter, + const QStyleOptionGraphicsItem* option, + QWidget* widget + ); + + protected: + virtual void _updateLabels( ) { } + protected: QNEBlock* m_Block; - QString m_Name; + int m_Radius; + int m_Margin; + bool m_IsExtended; + QGraphicsTextItem* m_Label; - int m_Radius; - int m_Margin; - quint64 m_Ptr; + QGraphicsTextItem* m_ExtendedLabel; }; /** @@ -93,11 +106,12 @@ namespace PipelineEditor QNENamePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); virtual ~QNENamePort( ); - virtual void setName( const QString& n ); - virtual bool isConnected( QNEPort* other ); inline int type( ) const { return( this->Type ); } + + protected: + virtual void _updateLabels( ); }; /** @@ -115,11 +129,12 @@ namespace PipelineEditor QNETypePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); virtual ~QNETypePort( ); - virtual void setName( const QString& n ); - virtual bool isConnected( QNEPort* other ); inline int type( ) const { return( this->Type ); } + + protected: + virtual void _updateLabels( ); }; /** @@ -137,7 +152,7 @@ namespace PipelineEditor QNEInputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); virtual ~QNEInputPort( ); - virtual void setName( const QString& n ); + virtual void setExtend( bool extend ); virtual bool isConnected( QNEPort* other ); inline int type( ) const @@ -153,6 +168,7 @@ namespace PipelineEditor protected: QVariant itemChange( GraphicsItemChange change, const QVariant& value ); + virtual void _updateLabels( ); protected: QNEConnection* m_Connection; @@ -173,7 +189,7 @@ namespace PipelineEditor QNEOutputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); virtual ~QNEOutputPort( ); - virtual void setName( const QString& n ); + virtual void setExtend( bool extend ); virtual bool isConnected( QNEPort* other ); inline int type( ) const @@ -186,6 +202,7 @@ namespace PipelineEditor protected: QVariant itemChange( GraphicsItemChange change, const QVariant& value ); + virtual void _updateLabels( ); protected: QVector< QNEConnection* > m_Connections; diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index 99db8a6..46508ca 100644 --- a/appli/cpPipelineEditor/QNodesEditor.cxx +++ b/appli/cpPipelineEditor/QNodesEditor.cxx @@ -42,6 +42,20 @@ #include "QNEConnection.h" #include "QNEBlock.h" +// ------------------------------------------------------------------------- +#define PipelineEditor_QNodesEditor_Callback_SWITCH( E, e ) \ + case QEvent::E: \ + { \ + Q##E##Event* evt = dynamic_cast< Q##E##Event* >( e ); \ + if( evt != NULL ) \ + this->_##E##_cbk( evt ); \ + } \ + break + +// ------------------------------------------------------------------------- +#define PipelineEditor_QNodesEditor_Callback_CODE( E ) \ + void PipelineEditor::QNodesEditor::_##E##_cbk( Q##E##Event* evt ) + // ------------------------------------------------------------------------- PipelineEditor::QNodesEditor:: QNodesEditor( QObject* parent ) @@ -177,6 +191,7 @@ _CreateBlock( TFilter* f, const QPointF& pnt ) } // ------------------------------------------------------------------------- +/* TODO void PipelineEditor::QNodesEditor:: _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) { @@ -227,7 +242,6 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) } // fi } break; - /* TODO: case Qt::RightButton: { } @@ -236,11 +250,11 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) { } break; - */ default: break; } // hctiws } + */ // ------------------------------------------------------------------------- bool PipelineEditor::QNodesEditor:: @@ -249,375 +263,334 @@ eventFilter( QObject* o, QEvent* e ) // Event type switch( int( e->type( ) ) ) { - case QEvent::GraphicsSceneContextMenu: - { - QGraphicsSceneContextMenuEvent* evt = - dynamic_cast< QGraphicsSceneContextMenuEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneDragEnter: - { - QGraphicsSceneDragDropEvent* evt = - dynamic_cast< QGraphicsSceneDragDropEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneDragLeave: - { - QGraphicsSceneDragDropEvent* evt = - dynamic_cast< QGraphicsSceneDragDropEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneDragMove: - { - QGraphicsSceneDragDropEvent* evt = - dynamic_cast< QGraphicsSceneDragDropEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneDrop: - { - QGraphicsSceneDragDropEvent* evt = - dynamic_cast< QGraphicsSceneDragDropEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneHelp: - { - QGraphicsSceneHelpEvent* evt = - dynamic_cast< QGraphicsSceneHelpEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneHoverEnter: - { - QGraphicsSceneHoverEvent* evt = - dynamic_cast< QGraphicsSceneHoverEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneHoverLeave: - { - QGraphicsSceneHoverEvent* evt = - dynamic_cast< QGraphicsSceneHoverEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneHoverMove: - { - QGraphicsSceneHoverEvent* evt = - dynamic_cast< QGraphicsSceneHoverEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneMouseDoubleClick: - { - QGraphicsSceneMouseEvent* evt = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( evt != NULL ) - { - QGraphicsItem* item = this->itemAt( evt->scenePos( ) ); - if( item != NULL ) - { - this->_DoubleClick( evt, item ); - return( true ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneContextMenu, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneDragEnter, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneDragLeave, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneDragMove, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneDrop, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneHelp, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneHoverEnter, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneHoverLeave, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneHoverMove, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMouseDoubleClick, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMouseMove, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMousePress, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMouseRelease, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMove, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneResize, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneWheel, e ); + default: + break; + } // hctiws - } // fi + return( this->Superclass::eventFilter( o, e ) ); +} - } // fi - } - break; - case QEvent::GraphicsSceneMouseMove: - { - QGraphicsSceneMouseEvent* evt = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( evt != NULL ) - { - if( this->m_Conn ) - { - if( this->m_Conn->port1( ) == NULL ) - this->m_Conn->setPos1( evt->scenePos( ) ); - else if( this->m_Conn->port2( ) == NULL ) - this->m_Conn->setPos2( evt->scenePos( ) ); - this->m_Conn->updatePath( ); - return( true ); +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneContextMenu ) +{ +} - } // fi +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneDragEnter ) +{ +} - } // fi - } - break; - case QEvent::GraphicsSceneMousePress: - { - QGraphicsSceneMouseEvent* evt = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( evt != NULL ) - { - switch( evt->button( ) ) - { - case Qt::LeftButton: - { - QNEOutputPort* port = - dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) ); - if( port != NULL ) - { - if( port->block( ) != NULL ) - { - this->m_Conn = new QNEConnection( 0, this->m_Scene ); - this->m_Conn->setPort1( port ); - this->m_Conn->setPos1( port->scenePos( ) ); - this->m_Conn->setPos2( evt->scenePos( ) ); - this->m_Conn->updatePath( ); - return( true ); +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneDragLeave ) +{ +} - } // fi +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneDragMove ) +{ +} - } // fi - } - break; - case Qt::RightButton: - { - QNEInputPort* in_port = - dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); - QNEOutputPort* out_port = - dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) ); - if( in_port != NULL ) - { - if( in_port->connection( ) == NULL && in_port->block( ) != NULL ) - { - this->m_Conn = new QNEConnection( 0, this->m_Scene ); - this->m_Conn->setPort2( in_port ); - this->m_Conn->setPos1( evt->scenePos( ) ); - this->m_Conn->setPos2( in_port->scenePos( ) ); - this->m_Conn->updatePath( ); - return( true ); +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneDrop ) +{ +} - } // fi - } - else if( out_port != NULL && out_port->block( ) != NULL ) - { - this->m_Conn = new QNEConnection( 0, this->m_Scene ); - this->m_Conn->setPort1( out_port ); - this->m_Conn->setPos1( out_port->scenePos( ) ); - this->m_Conn->setPos2( evt->scenePos( ) ); - this->m_Conn->updatePath( ); - return( true ); +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneHelp ) +{ +} - } // fi - } - break; - default: - break; +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneHoverEnter ) +{ +} - } // hctiws +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneHoverLeave ) +{ +} - } // fi - } - break; - case QEvent::GraphicsSceneMouseRelease: +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneHoverMove ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMouseDoubleClick ) +{ + QGraphicsItem* item = this->itemAt( evt->scenePos( ) ); + if( item == NULL ) + return; + + switch( evt->button( ) ) + { + case Qt::LeftButton: { - QGraphicsSceneMouseEvent* evt = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( evt != NULL ) + QNEBlock* block = dynamic_cast< QNEBlock* >( item ); + QNEPort* port = dynamic_cast< QNEPort* >( item ); + QNEConnection* conn = dynamic_cast< QNEConnection* >( item ); + + if( block != NULL ) { - if( this->m_Conn != NULL && evt->button( ) == Qt::LeftButton ) + QString old_name = block->namePort( ); + bool ok; + QString new_name = + QInputDialog::getText( + dynamic_cast< QWidget* >( this->parent( ) ), + "Change filter name", + "Filter name:", + QLineEdit::Normal, + old_name, + &ok + ); + if( ok && !new_name.isEmpty( ) && old_name != new_name ) { - QNEInputPort* port2 = - dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); - if( port2 != NULL ) + ok = this->m_Graph->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); + if( ok ) { - QNEOutputPort* port1 = - dynamic_cast< QNEOutputPort* >( this->m_Conn->port1( ) ); - if( port1 != NULL ) - { - if( - port1->block( ) != port2->block( ) && - !port2->hasConnection( ) && - !port1->isConnected( port2 ) - ) - { - this->m_Conn->setPos2( port2->scenePos( ) ); - this->m_Conn->setPort2( port2 ); - this->m_Conn->updatePath( ); - - this->m_Workspace->Connect( - port1->block( )->namePort( ).toStdString( ), - port2->block( )->namePort( ).toStdString( ), - port1->name( ).toStdString( ), - port2->name( ).toStdString( ) - ); - this->m_Graph->AddConnection( - port1->block( )->namePort( ).toStdString( ), - port2->block( )->namePort( ).toStdString( ), - this->m_Conn - ); - - this->m_Conn = NULL; - return( true ); - - } // fi - - } // fi + block->setNamePort( new_name ); + this->m_Workspace->GetGraph( )->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); } // fi - delete this->m_Conn; - this->m_Conn = NULL; - return( true ); - } - else if( this->m_Conn != NULL && evt->button( ) == Qt::RightButton ) - { - QNEOutputPort* port1 = this->m_Conn->port1( ); - QNEInputPort* port2 = this->m_Conn->port2( ); - if( port1 != NULL && port2 == NULL ) + } // fi + } + else if( port != NULL ) + { + if( evt->modifiers( ) == Qt::ControlModifier ) + { + port->setExtend( !( port->isExtended( ) ) ); + QNEInputPort* in_port = dynamic_cast< QNEInputPort* >( port ); + QNEOutputPort* out_port = dynamic_cast< QNEOutputPort* >( port ); + if( port->isExtended( ) ) { - if( - dynamic_cast< QNEInputPort* >( - this->itemAt( evt->scenePos( ) ) - ) == NULL - ) + if( in_port != NULL ) { - port2 = new QNEInputPort( NULL, this->m_Scene ); - port2->setName( port1->name( ) ); - port2->setPos( evt->scenePos( ) ); - this->m_Conn->setPos2( evt->scenePos( ) ); - this->m_Conn->setPort2( port2 ); - this->m_Conn->updatePath( ); + this->m_Workspace->AddInputPort( + in_port->extendedName( ).toStdString( ), + in_port->block( )->namePort( ).toStdString( ), + in_port->name( ).toStdString( ) + ); } - else - delete this->m_Conn; - this->m_Conn = NULL; - return( true ); + else if( out_port != NULL ) + { + } // fi } - else if( port1 == NULL && port2 != NULL ) + else { - if( - dynamic_cast< QNEOutputPort* >( - this->itemAt( evt->scenePos( ) ) - ) == NULL - ) + if( in_port != NULL ) { - port1 = new QNEOutputPort( NULL, this->m_Scene ); - port1->setName( port2->name( ) ); - port1->setPos( evt->scenePos( ) ); - this->m_Conn->setPos1( evt->scenePos( ) ); - this->m_Conn->setPort1( port1 ); - this->m_Conn->updatePath( ); } - else - delete this->m_Conn; - this->m_Conn = NULL; - return( true ); + else if( out_port != NULL ) + { + } // fi } // fi + this->m_Scene->update( ); + } + else if( evt->modifiers( ) == Qt::NoModifier ) + { + if( port->isExtended( ) ) + { + QString old_name = port->extendedName( ); + bool ok; + QString new_name = + QInputDialog::getText( + dynamic_cast< QWidget* >( this->parent( ) ), + "Change filter name", + "Filter name:", + QLineEdit::Normal, + old_name, + &ok + ); + if( ok && !new_name.isEmpty( ) && old_name != new_name ) + { + // TODO: port->setExtendedName( new_name ); + /* TODO + ok = this->m_Graph->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); + if( ok ) + { + block->setNamePort( new_name ); + this->m_Workspace->GetGraph( )->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); + + } // fi + */ + } // fi - } // fi + } // fi - } // fi - } - break; - case QEvent::GraphicsSceneMove: - { - QGraphicsSceneMoveEvent* evt = - dynamic_cast< QGraphicsSceneMoveEvent* >( e ); - if( evt != NULL ) + } // fi + } + else if( conn != NULL ) { } // fi } break; - case QEvent::GraphicsSceneResize: + /* TODO: + case Qt::RightButton: + { + } + break; + case Qt::MiddleButton: + { + } + break; + */ + default: + break; + } // hctiws +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMouseMove ) +{ + if( this->m_Conn != NULL ) { - QGraphicsSceneResizeEvent* evt = - dynamic_cast< QGraphicsSceneResizeEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneWheel: + if( this->m_Conn->port1( ) == NULL ) + this->m_Conn->setPos1( evt->scenePos( ) ); + else if( this->m_Conn->port2( ) == NULL ) + this->m_Conn->setPos2( evt->scenePos( ) ); + this->m_Conn->updatePath( ); + + } // fi +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMousePress ) +{ + QNEInputPort* in_port = + dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); + QNEOutputPort* out_port = + dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) ); + if( in_port == NULL && out_port == NULL ) + return; + + switch( evt->button( ) ) { - QGraphicsSceneWheelEvent* evt = - dynamic_cast< QGraphicsSceneWheelEvent* >( e ); - if( evt != NULL ) + case Qt::LeftButton: + { + if( out_port != NULL ) { + if( out_port->block( ) != NULL ) + { + // Start new connection + this->m_Conn = new QNEConnection( 0, this->m_Scene ); + this->m_Conn->setPort1( out_port ); + this->m_Conn->setPos1( out_port->scenePos( ) ); + this->m_Conn->setPos2( evt->scenePos( ) ); + this->m_Conn->updatePosFromPorts( ); + this->m_Conn->updatePath( ); + + } // fi + } // fi } break; default: break; + } // hctiws +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMouseRelease ) +{ + if( this->m_Conn == NULL ) + return; - // Mouse event - /* - QGraphicsSceneMouseEvent* me = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( me != NULL ) + switch( evt->button( ) ) + { + case Qt::LeftButton: + { + QNEInputPort* port2 = + dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); + if( port2 != NULL ) { - } // fi - */ + QNEOutputPort* port1 = + dynamic_cast< QNEOutputPort* >( this->m_Conn->port1( ) ); + if( port1 != NULL ) + { + if( + port1->block( ) != port2->block( ) && + !port2->hasConnection( ) && + !port1->isConnected( port2 ) && + !port2->isExtended( ) + ) + { + this->m_Conn->setPos2( port2->scenePos( ) ); + this->m_Conn->setPort2( port2 ); + this->m_Conn->updatePosFromPorts( ); + this->m_Conn->updatePath( ); - /* TODO - switch( ( int ) e->type( ) ) - { - case QEvent::GraphicsSceneMouseMove: - { - if( this->m_Conn ) - { - this->m_Conn->setPos2( me->scenePos( ) ); - this->m_Conn->updatePath( ); - return( true ); - } - break; - } - case QEvent::GraphicsSceneMouseRelease: - { - if( this->m_Conn && me->button( ) == Qt::LeftButton ) - { - QGraphicsItem* item = itemAt( me->scenePos( ) ); - if( item && item->type( ) == QNEPort::Type ) - { - QNEPort* port1 = this->m_Conn->port1( ); - QNEPort* port2 = ( QNEPort* ) item; - if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isConnected( port2 ) ) - { - this->m_Conn->setPos2( port2->scenePos( ) ); - this->m_Conn->setPort2( port2 ); - this->m_Conn->updatePath( ); - this->m_Conn = NULL; - return( true ); - } - } + this->m_Workspace->Connect( + port1->block( )->namePort( ).toStdString( ), + port2->block( )->namePort( ).toStdString( ), + port1->name( ).toStdString( ), + port2->name( ).toStdString( ) + ); + this->m_Graph->AddConnection( + port1->block( )->namePort( ).toStdString( ), + port2->block( )->namePort( ).toStdString( ), + this->m_Conn + ); + } + else + delete this->m_Conn; + } + else + delete this->m_Conn; + } + else + delete this->m_Conn; + this->m_Conn = NULL; + } + break; + default: + break; + } // hctisw +} - delete this->m_Conn; - this->m_Conn = NULL; - return( true ); - } - break; - } - } // hctiws - */ +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMove ) +{ +} - return( this->Superclass::eventFilter( o, e ) ); +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneResize ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneWheel ) +{ } // eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/QNodesEditor.h b/appli/cpPipelineEditor/QNodesEditor.h index f338d91..d148bbe 100644 --- a/appli/cpPipelineEditor/QNodesEditor.h +++ b/appli/cpPipelineEditor/QNodesEditor.h @@ -35,6 +35,18 @@ class QGraphicsScene; class QGraphicsSceneMouseEvent; class QGraphicsItem; +class QGraphicsSceneContextMenuEvent; +class QGraphicsSceneDragDropEvent; +class QGraphicsSceneHelpEvent; +class QGraphicsSceneHoverEvent; +class QGraphicsSceneMouseEvent; +class QGraphicsSceneMoveEvent; +class QGraphicsSceneResizeEvent; +class QGraphicsSceneWheelEvent; + +// ------------------------------------------------------------------------- +#define PipelineEditor_QNodesEditor_Callback_DCL( E ) \ + void _##E##_cbk( Q##E##Event* e ); namespace PipelineEditor { @@ -78,7 +90,36 @@ namespace PipelineEditor QGraphicsItem* itemAt( const QPointF& pos ); inline void _CreateBlock( TFilter* f, const QPointF& pnt ); - inline void _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ); + + protected: + typedef QGraphicsSceneDragDropEvent QGraphicsSceneDragEnterEvent; + typedef QGraphicsSceneDragDropEvent QGraphicsSceneDragLeaveEvent; + typedef QGraphicsSceneDragDropEvent QGraphicsSceneDragMoveEvent; + typedef QGraphicsSceneDragDropEvent QGraphicsSceneDropEvent; + typedef QGraphicsSceneHoverEvent QGraphicsSceneHoverEnterEvent; + typedef QGraphicsSceneHoverEvent QGraphicsSceneHoverMoveEvent; + typedef QGraphicsSceneHoverEvent QGraphicsSceneHoverLeaveEvent; + typedef QGraphicsSceneMouseEvent QGraphicsSceneMouseDoubleClickEvent; + typedef QGraphicsSceneMouseEvent QGraphicsSceneMouseMoveEvent; + typedef QGraphicsSceneMouseEvent QGraphicsSceneMousePressEvent; + typedef QGraphicsSceneMouseEvent QGraphicsSceneMouseReleaseEvent; + + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneContextMenu ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneDragEnter ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneDragLeave ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneDragMove ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneDrop ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneHelp ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneHoverEnter ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneHoverLeave ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneHoverMove ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneMouseDoubleClick ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneMouseMove ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneMousePress ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneMouseRelease ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneMove ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneResize ); + PipelineEditor_QNodesEditor_Callback_DCL( GraphicsSceneWheel ); private: QGraphicsScene* m_Scene; @@ -93,3 +134,25 @@ namespace PipelineEditor #endif // __PIPELINEEDITOR__QNODESEDITOR__H__ // eof - $RCSfile$ + + /* TODO + case QEvent::GraphicsSceneContextMenu: + QGraphicsSceneContextMenuEvent* evt = + + case QEvent::GraphicsSceneDragEnter: + case QEvent::GraphicsSceneDragLeave: + case QEvent::GraphicsSceneDragMove: + case QEvent::GraphicsSceneDrop: + case QEvent::GraphicsSceneHelp: + case QEvent::GraphicsSceneHoverEnter: + case QEvent::GraphicsSceneHoverLeave: + case QEvent::GraphicsSceneHoverMove: + case QEvent::GraphicsSceneMouseDoubleClick: + case QEvent::GraphicsSceneMouseMove: + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMouseRelease: + case QEvent::GraphicsSceneMove: + case QEvent::GraphicsSceneResize: + case QEvent::GraphicsSceneWheel: + */ + diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index 3c42481..dfe66d9 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -193,6 +193,8 @@ AddInputPort( const std::string& filter, const std::string& filter_input ) { + std::cout << name << " " << filter << " " << filter_input << std::endl; + this->m_InputPorts[ name ] = TGlobalPort( filter, filter_input ); }