1 #include <cpBaseQtApplication/Pipeline/Port.h>
\r
2 #include <cpBaseQtApplication/Pipeline/Connection.h>
\r
3 #include <cpBaseQtApplication/Pipeline/Block.h>
\r
5 #include <QGraphicsScene>
\r
6 #include <QGraphicsSceneContextMenuEvent>
\r
7 #include <QFontMetrics>
\r
12 // -------------------------------------------------------------------------
\r
13 cpBaseQtApplication::Pipeline::Port::
\r
14 Port( QGraphicsItem* parent, QGraphicsScene* scene )
\r
16 Superclass( parent, scene ),
\r
20 this->m_Label = new QGraphicsTextItem( this );
\r
21 this->m_ExtendedLabel = new QGraphicsTextItem( this );
\r
22 this->setExtend( false );
\r
25 p.addEllipse( 0, 0, 2 * this->m_Radius, 2 * this->m_Radius );
\r
28 this->setPen( QPen( Qt::darkRed ) );
\r
29 this->setBrush( Qt::red );
\r
30 this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges );
\r
33 // -------------------------------------------------------------------------
\r
34 cpBaseQtApplication::Pipeline::Port::
\r
39 // -------------------------------------------------------------------------
\r
40 void cpBaseQtApplication::Pipeline::Port::
\r
41 setBlock( Block* b )
\r
46 // -------------------------------------------------------------------------
\r
47 void cpBaseQtApplication::Pipeline::Port::
\r
48 setName( const QString& n )
\r
50 this->m_Label->setPlainText( n );
\r
51 this->_updateLabels( );
\r
54 // -------------------------------------------------------------------------
\r
55 void cpBaseQtApplication::Pipeline::Port::
\r
56 setExtendedName( const QString& n )
\r
58 this->m_ExtendedLabel->setPlainText( n );
\r
59 this->_updateLabels( );
\r
62 // -------------------------------------------------------------------------
\r
63 void cpBaseQtApplication::Pipeline::Port::
\r
64 setExtend( bool extend )
\r
67 this->m_IsExtended = false;
\r
68 this->m_ExtendedLabel->setVisible( false );
\r
71 // -------------------------------------------------------------------------
\r
72 void cpBaseQtApplication::Pipeline::Port::
\r
75 const QStyleOptionGraphicsItem* option,
\r
82 if( this->isExtended( ) )
\r
84 painter->setPen( QPen( Qt::darkBlue ) );
\r
85 painter->setBrush( Qt::blue );
\r
89 painter->setPen( QPen( Qt::darkRed ) );
\r
90 painter->setBrush( Qt::red );
\r
93 painter->drawPath( this->path( ) );
\r
96 // -------------------------------------------------------------------------
\r
97 cpBaseQtApplication::Pipeline::NamePort::
\r
98 NamePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
99 : Superclass( parent, scene )
\r
103 // -------------------------------------------------------------------------
\r
104 cpBaseQtApplication::Pipeline::NamePort::
\r
109 // -------------------------------------------------------------------------
\r
110 bool cpBaseQtApplication::Pipeline::NamePort::
\r
111 isConnected( Port* other )
\r
116 // -------------------------------------------------------------------------
\r
117 void cpBaseQtApplication::Pipeline::NamePort::
\r
120 QFont font( this->scene( )->font( ) );
\r
121 font.setBold( true );
\r
122 this->m_Label->setFont( font );
\r
123 this->m_ExtendedLabel->setFont( font );
\r
124 this->setPath( QPainterPath( ) );
\r
127 // -------------------------------------------------------------------------
\r
128 cpBaseQtApplication::Pipeline::InfoPort::
\r
129 InfoPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
130 : Superclass( parent, scene )
\r
134 // -------------------------------------------------------------------------
\r
135 cpBaseQtApplication::Pipeline::InfoPort::
\r
140 // -------------------------------------------------------------------------
\r
141 bool cpBaseQtApplication::Pipeline::InfoPort::
\r
142 isConnected( Port* other )
\r
147 // -------------------------------------------------------------------------
\r
148 void cpBaseQtApplication::Pipeline::InfoPort::
\r
151 QFont font( this->scene( )->font( ) );
\r
152 font.setBold( false );
\r
153 this->m_Label->setFont( font );
\r
154 this->m_ExtendedLabel->setFont( font );
\r
155 this->setPath( QPainterPath( ) );
\r
158 // -------------------------------------------------------------------------
\r
159 cpBaseQtApplication::Pipeline::InputPort::
\r
160 InputPort( QGraphicsItem* parent, bool multiple, QGraphicsScene* scene )
\r
161 : Superclass( parent, scene ),
\r
162 m_IsMultiple( multiple )
\r
166 // -------------------------------------------------------------------------
\r
167 cpBaseQtApplication::Pipeline::InputPort::
\r
170 this->m_Connection.clear( );
\r
173 // -------------------------------------------------------------------------
\r
174 void cpBaseQtApplication::Pipeline::InputPort::
\r
177 QFontMetrics fm( this->scene( )->font( ) );
\r
178 this->m_Label->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
179 this->m_ExtendedLabel->setPos(
\r
180 -fm.width( this->extendedName( ) ) - this->m_Radius * 2,
\r
185 // -------------------------------------------------------------------------
\r
186 void cpBaseQtApplication::Pipeline::InputPort::
\r
187 setExtend( bool extend )
\r
189 if( this->m_Connection.size( ) == 0 )
\r
191 this->m_IsExtended = extend;
\r
192 this->m_ExtendedLabel->setVisible( extend );
\r
195 this->Superclass::setExtend( false );
\r
198 // -------------------------------------------------------------------------
\r
199 bool cpBaseQtApplication::Pipeline::InputPort::
\r
200 isConnected( Port* other )
\r
203 auto i = this->m_Connection.begin( );
\r
204 for( ; i != this->m_Connection.end( ); ++i )
\r
205 conn |= ( ( *i )->port1( ) == other && ( *i )->port2( ) == this );
\r
209 // -------------------------------------------------------------------------
\r
210 void cpBaseQtApplication::Pipeline::InputPort::
\r
211 setConnection( Connection* c )
\r
213 if( this->m_IsMultiple || this->m_Connection.size( ) == 0 )
\r
214 this->m_Connection.push_back( c );
\r
217 // -------------------------------------------------------------------------
\r
218 void cpBaseQtApplication::Pipeline::InputPort::
\r
219 removeConnection( Connection* c )
\r
221 auto i = std::find(
\r
222 this->m_Connection.begin( ),
\r
223 this->m_Connection.end( ),
\r
226 if( i != this->m_Connection.end( ) )
\r
229 this->m_Connection.erase( i );
\r
234 // -------------------------------------------------------------------------
\r
235 QVariant cpBaseQtApplication::Pipeline::InputPort::
\r
236 itemChange( GraphicsItemChange change, const QVariant& value )
\r
238 if( change == ItemScenePositionHasChanged )
\r
241 auto i = this->m_Connection.begin( );
\r
242 i != this->m_Connection.end( );
\r
246 ( *i )->updatePosFromPorts( );
\r
247 ( *i )->updatePath( );
\r
255 // -------------------------------------------------------------------------
\r
256 cpBaseQtApplication::Pipeline::OutputPort::
\r
257 OutputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
258 : Superclass( parent, scene )
\r
262 // -------------------------------------------------------------------------
\r
263 cpBaseQtApplication::Pipeline::OutputPort::
\r
266 foreach( Connection* conn, this->m_Connections )
\r
270 // -------------------------------------------------------------------------
\r
271 void cpBaseQtApplication::Pipeline::OutputPort::
\r
274 QFontMetrics fm( this->scene( )->font( ) );
\r
275 this->m_Label->setPos(
\r
276 -fm.width( this->name( ) ) - this->m_Radius * 2, -fm.height( ) / 2
\r
278 this->m_ExtendedLabel->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
282 // -------------------------------------------------------------------------
\r
283 void cpBaseQtApplication::Pipeline::OutputPort::
\r
284 removeConnection( Connection* c )
\r
286 auto i = std::find(
\r
287 this->m_Connections.begin( ),
\r
288 this->m_Connections.end( ),
\r
291 if( i != this->m_Connections.end( ) )
\r
294 this->m_Connections.erase( i );
\r
299 // -------------------------------------------------------------------------
\r
300 void cpBaseQtApplication::Pipeline::OutputPort::
\r
301 setExtend( bool extend )
\r
303 this->m_IsExtended = extend;
\r
304 this->m_ExtendedLabel->setVisible( extend );
\r
307 // -------------------------------------------------------------------------
\r
308 bool cpBaseQtApplication::Pipeline::OutputPort::
\r
309 isConnected( Port* other )
\r
311 auto i = this->m_Connections.begin( );
\r
313 for( ; i != this->m_Connections.end( ) && !conn; ++i )
\r
314 conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );
\r
318 // -------------------------------------------------------------------------
\r
319 QVariant cpBaseQtApplication::Pipeline::OutputPort::
\r
320 itemChange( GraphicsItemChange change, const QVariant& value )
\r
322 if( change == ItemScenePositionHasChanged )
\r
324 foreach( Connection* conn, this->m_Connections )
\r
326 conn->updatePosFromPorts( );
\r
327 conn->updatePath( );
\r
335 // -------------------------------------------------------------------------
\r
336 void cpBaseQtApplication::Pipeline::OutputPort::
\r
337 contextMenuEvent( QGraphicsSceneContextMenuEvent* evt )
\r
339 if( this->m_Block == NULL )
\r
343 QAction* showAction = menu.addAction( "Show" );
\r
344 QAction* hideAction = menu.addAction( "Hide" );
\r
345 QAction* selectedAction = menu.exec( evt->screenPos( ) );
\r
347 if( selectedAction == showAction || selectedAction == hideAction )
\r
349 std::stringstream str;
\r
351 << this->name( ).toStdString( ) << "@"
\r
352 << this->m_Block->filter( )->GetName( );
\r
353 emit viewData( str.str( ), ( selectedAction == showAction ) );
\r