--- /dev/null
+#include <cpBaseQtApplication/Pipeline/Port.h>\r
+#include <cpBaseQtApplication/Pipeline/Connection.h>\r
+#include <cpBaseQtApplication/Pipeline/Block.h>\r
+\r
+#include <QGraphicsScene>\r
+#include <QGraphicsSceneContextMenuEvent>\r
+#include <QFontMetrics>\r
+#include <QMenu>\r
+#include <QPainter>\r
+#include <QPen>\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::Port::\r
+Port( QGraphicsItem* parent, QGraphicsScene* scene )\r
+ : QObject( ),\r
+ Superclass( parent, scene ),\r
+ m_Radius( 5 ),\r
+ m_Margin( 2 )\r
+{\r
+ this->m_Label = new QGraphicsTextItem( this );\r
+ this->m_ExtendedLabel = new QGraphicsTextItem( this );\r
+ this->setExtend( false );\r
+\r
+ QPainterPath p;\r
+ p.addEllipse( 0, 0, 2 * this->m_Radius, 2 * this->m_Radius );\r
+\r
+ this->setPath( p );\r
+ this->setPen( QPen( Qt::darkRed ) );\r
+ this->setBrush( Qt::red );\r
+ this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::Port::\r
+~Port( )\r
+{\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::Port::\r
+setBlock( Block* b )\r
+{\r
+ this->m_Block = b;\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::Port::\r
+setName( const QString& n )\r
+{\r
+ this->m_Label->setPlainText( n );\r
+ this->_updateLabels( );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::Port::\r
+setExtendedName( const QString& n )\r
+{\r
+ this->m_ExtendedLabel->setPlainText( n );\r
+ this->_updateLabels( );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::Port::\r
+setExtend( bool extend )\r
+{\r
+ // Do nothing!\r
+ this->m_IsExtended = false;\r
+ this->m_ExtendedLabel->setVisible( false );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::Port::\r
+paint(\r
+ QPainter* painter,\r
+ const QStyleOptionGraphicsItem* option,\r
+ QWidget* widget\r
+ )\r
+{\r
+ Q_UNUSED( option );\r
+ Q_UNUSED( widget );\r
+\r
+ if( this->isExtended( ) )\r
+ {\r
+ painter->setPen( QPen( Qt::darkBlue ) );\r
+ painter->setBrush( Qt::blue );\r
+ }\r
+ else\r
+ {\r
+ painter->setPen( QPen( Qt::darkRed ) );\r
+ painter->setBrush( Qt::red );\r
+\r
+ } // fi\r
+ painter->drawPath( this->path( ) );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::NamePort::\r
+NamePort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+ : Superclass( parent, scene )\r
+{\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::NamePort::\r
+~NamePort( )\r
+{\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool cpBaseQtApplication::Pipeline::NamePort::\r
+isConnected( Port* other )\r
+{\r
+ return( false );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::NamePort::\r
+_updateLabels( )\r
+{\r
+ QFont font( this->scene( )->font( ) );\r
+ font.setBold( true );\r
+ this->m_Label->setFont( font );\r
+ this->m_ExtendedLabel->setFont( font );\r
+ this->setPath( QPainterPath( ) );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::InfoPort::\r
+InfoPort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+ : Superclass( parent, scene )\r
+{\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::InfoPort::\r
+~InfoPort( )\r
+{\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool cpBaseQtApplication::Pipeline::InfoPort::\r
+isConnected( Port* other )\r
+{\r
+ return( false );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::InfoPort::\r
+_updateLabels( )\r
+{\r
+ QFont font( this->scene( )->font( ) );\r
+ font.setBold( false );\r
+ this->m_Label->setFont( font );\r
+ this->m_ExtendedLabel->setFont( font );\r
+ this->setPath( QPainterPath( ) );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::InputPort::\r
+InputPort( QGraphicsItem* parent, bool multiple, QGraphicsScene* scene )\r
+ : Superclass( parent, scene ),\r
+ m_IsMultiple( multiple )\r
+{\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::InputPort::\r
+~InputPort( )\r
+{\r
+ this->m_Connection.clear( );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::InputPort::\r
+_updateLabels( )\r
+{\r
+ QFontMetrics fm( this->scene( )->font( ) );\r
+ this->m_Label->setPos( this->m_Radius * 2, -fm.height( ) / 2 );\r
+ this->m_ExtendedLabel->setPos(\r
+ -fm.width( this->extendedName( ) ) - this->m_Radius * 2,\r
+ -fm.height( ) / 2\r
+ );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::InputPort::\r
+setExtend( bool extend )\r
+{\r
+ if( this->m_Connection.size( ) == 0 )\r
+ {\r
+ this->m_IsExtended = extend;\r
+ this->m_ExtendedLabel->setVisible( extend );\r
+ }\r
+ else\r
+ this->Superclass::setExtend( false );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool cpBaseQtApplication::Pipeline::InputPort::\r
+isConnected( Port* other )\r
+{\r
+ bool conn = false;\r
+ auto i = this->m_Connection.begin( );\r
+ for( ; i != this->m_Connection.end( ); ++i )\r
+ conn |= ( ( *i )->port1( ) == other && ( *i )->port2( ) == this );\r
+ return( conn );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::InputPort::\r
+setConnection( Connection* c )\r
+{\r
+ if( this->m_IsMultiple || this->m_Connection.size( ) == 0 )\r
+ this->m_Connection.push_back( c );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::InputPort::\r
+removeConnection( Connection* c )\r
+{\r
+ auto i = std::find(\r
+ this->m_Connection.begin( ),\r
+ this->m_Connection.end( ),\r
+ c\r
+ );\r
+ if( i != this->m_Connection.end( ) )\r
+ {\r
+ *i = NULL;\r
+ this->m_Connection.erase( i );\r
+\r
+ } // fi\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+QVariant cpBaseQtApplication::Pipeline::InputPort::\r
+itemChange( GraphicsItemChange change, const QVariant& value )\r
+{\r
+ if( change == ItemScenePositionHasChanged )\r
+ {\r
+ for(\r
+ auto i = this->m_Connection.begin( );\r
+ i != this->m_Connection.end( );\r
+ ++i\r
+ )\r
+ {\r
+ ( *i )->updatePosFromPorts( );\r
+ ( *i )->updatePath( );\r
+\r
+ } // fi\r
+\r
+ } // fi\r
+ return( value );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::OutputPort::\r
+OutputPort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+ : Superclass( parent, scene )\r
+{\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+cpBaseQtApplication::Pipeline::OutputPort::\r
+~OutputPort( )\r
+{\r
+ foreach( Connection* conn, this->m_Connections )\r
+ delete conn;\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::OutputPort::\r
+_updateLabels( )\r
+{\r
+ QFontMetrics fm( this->scene( )->font( ) );\r
+ this->m_Label->setPos(\r
+ -fm.width( this->name( ) ) - this->m_Radius * 2, -fm.height( ) / 2\r
+ );\r
+ this->m_ExtendedLabel->setPos( this->m_Radius * 2, -fm.height( ) / 2 );\r
+\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::OutputPort::\r
+removeConnection( Connection* c )\r
+{\r
+ auto i = std::find(\r
+ this->m_Connections.begin( ),\r
+ this->m_Connections.end( ),\r
+ c\r
+ );\r
+ if( i != this->m_Connections.end( ) )\r
+ {\r
+ *i = NULL;\r
+ this->m_Connections.erase( i );\r
+\r
+ } // fi\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::OutputPort::\r
+setExtend( bool extend )\r
+{\r
+ this->m_IsExtended = extend;\r
+ this->m_ExtendedLabel->setVisible( extend );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool cpBaseQtApplication::Pipeline::OutputPort::\r
+isConnected( Port* other )\r
+{\r
+ auto i = this->m_Connections.begin( );\r
+ bool conn = false;\r
+ for( ; i != this->m_Connections.end( ) && !conn; ++i )\r
+ conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );\r
+ return( conn );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+QVariant cpBaseQtApplication::Pipeline::OutputPort::\r
+itemChange( GraphicsItemChange change, const QVariant& value )\r
+{\r
+ if( change == ItemScenePositionHasChanged )\r
+ {\r
+ foreach( Connection* conn, this->m_Connections )\r
+ {\r
+ conn->updatePosFromPorts( );\r
+ conn->updatePath( );\r
+\r
+ } // rof\r
+\r
+ } // fi\r
+ return( value );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Pipeline::OutputPort::\r
+contextMenuEvent( QGraphicsSceneContextMenuEvent* evt )\r
+{\r
+ if( this->m_Block == NULL )\r
+ return;\r
+ \r
+ QMenu menu;\r
+ QAction* showAction = menu.addAction( "Show" );\r
+ QAction* hideAction = menu.addAction( "Hide" );\r
+ QAction* selectedAction = menu.exec( evt->screenPos( ) );\r
+\r
+ if( selectedAction == showAction || selectedAction == hideAction )\r
+ {\r
+ std::stringstream str;\r
+ str\r
+ << this->name( ).toStdString( ) << "@"\r
+ << this->m_Block->filter( )->GetName( );\r
+ emit viewData( str.str( ), ( selectedAction == showAction ) );\r
+\r
+ } // fi\r
+}\r
+\r
+// eof - $RCSfile$\r