2 #include "Connection.h"
\r
6 #include <cpPlugins/DataObjectVisualizationQtDialog.h>
\r
8 #include <QGraphicsScene>
\r
9 #include <QGraphicsSceneContextMenuEvent>
\r
10 #include <QFontMetrics>
\r
15 // -------------------------------------------------------------------------
\r
16 cpPipelineEditor::Port::
\r
17 Port( QGraphicsItem* parent, QGraphicsScene* scene )
\r
18 : Superclass( parent, scene ),
\r
22 this->m_Label = new QGraphicsTextItem( this );
\r
23 this->m_ExtendedLabel = new QGraphicsTextItem( this );
\r
24 this->setExtend( false );
\r
27 p.addEllipse( 0, 0, 2 * this->m_Radius, 2 * this->m_Radius );
\r
30 this->setPen( QPen( Qt::darkRed ) );
\r
31 this->setBrush( Qt::red );
\r
32 this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges );
\r
35 // -------------------------------------------------------------------------
\r
36 cpPipelineEditor::Port::
\r
41 // -------------------------------------------------------------------------
\r
42 void cpPipelineEditor::Port::
\r
43 setBlock( Block* b )
\r
48 // -------------------------------------------------------------------------
\r
49 void cpPipelineEditor::Port::
\r
50 setName( const QString& n )
\r
52 this->m_Label->setPlainText( n );
\r
53 this->_updateLabels( );
\r
56 // -------------------------------------------------------------------------
\r
57 void cpPipelineEditor::Port::
\r
58 setExtendedName( const QString& n )
\r
60 this->m_ExtendedLabel->setPlainText( n );
\r
61 this->_updateLabels( );
\r
64 // -------------------------------------------------------------------------
\r
65 void cpPipelineEditor::Port::
\r
66 setExtend( bool extend )
\r
69 this->m_IsExtended = false;
\r
70 this->m_ExtendedLabel->setVisible( false );
\r
73 // -------------------------------------------------------------------------
\r
74 void cpPipelineEditor::Port::
\r
77 const QStyleOptionGraphicsItem* option,
\r
84 if( this->isExtended( ) )
\r
86 painter->setPen( QPen( Qt::darkBlue ) );
\r
87 painter->setBrush( Qt::blue );
\r
91 painter->setPen( QPen( Qt::darkRed ) );
\r
92 painter->setBrush( Qt::red );
\r
95 painter->drawPath( this->path( ) );
\r
98 // -------------------------------------------------------------------------
\r
99 cpPipelineEditor::NamePort::
\r
100 NamePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
101 : Superclass( parent, scene )
\r
105 // -------------------------------------------------------------------------
\r
106 cpPipelineEditor::NamePort::
\r
111 // -------------------------------------------------------------------------
\r
112 void cpPipelineEditor::NamePort::
\r
115 QFont font( this->scene( )->font( ) );
\r
116 font.setBold( true );
\r
117 this->m_Label->setFont( font );
\r
118 this->m_ExtendedLabel->setFont( font );
\r
119 this->setPath( QPainterPath( ) );
\r
122 // -------------------------------------------------------------------------
\r
123 bool cpPipelineEditor::NamePort::
\r
124 isConnected( Port* other )
\r
129 // -------------------------------------------------------------------------
\r
130 cpPipelineEditor::InputPort::
\r
131 InputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
132 : Superclass( parent, scene ),
\r
133 m_Connection( NULL )
\r
137 // -------------------------------------------------------------------------
\r
138 cpPipelineEditor::InputPort::
\r
141 if( this->m_Connection != NULL )
\r
142 delete this->m_Connection;
\r
145 // -------------------------------------------------------------------------
\r
146 void cpPipelineEditor::InputPort::
\r
149 QFontMetrics fm( this->scene( )->font( ) );
\r
150 this->m_Label->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
151 this->m_ExtendedLabel->setPos(
\r
152 -fm.width( this->extendedName( ) ) - this->m_Radius * 2,
\r
157 // -------------------------------------------------------------------------
\r
158 void cpPipelineEditor::InputPort::
\r
159 setExtend( bool extend )
\r
161 if( this->m_Connection == NULL )
\r
163 this->m_IsExtended = extend;
\r
164 this->m_ExtendedLabel->setVisible( extend );
\r
167 this->Superclass::setExtend( false );
\r
170 // -------------------------------------------------------------------------
\r
171 bool cpPipelineEditor::InputPort::
\r
172 isConnected( Port* other )
\r
174 if( this->m_Connection != NULL )
\r
176 this->m_Connection->port1( ) == other &&
\r
177 this->m_Connection->port2( ) == this
\r
183 // -------------------------------------------------------------------------
\r
184 void cpPipelineEditor::InputPort::
\r
185 setConnection( Connection* c )
\r
187 this->m_Connection = c;
\r
190 // -------------------------------------------------------------------------
\r
191 QVariant cpPipelineEditor::InputPort::
\r
192 itemChange( GraphicsItemChange change, const QVariant& value )
\r
194 if( change == ItemScenePositionHasChanged )
\r
196 if( this->m_Connection != NULL )
\r
198 this->m_Connection->updatePosFromPorts( );
\r
199 this->m_Connection->updatePath( );
\r
207 // -------------------------------------------------------------------------
\r
208 cpPipelineEditor::OutputPort::
\r
209 OutputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
210 : Superclass( parent, scene )
\r
214 // -------------------------------------------------------------------------
\r
215 cpPipelineEditor::OutputPort::
\r
218 foreach( Connection* conn, this->m_Connections )
\r
222 // -------------------------------------------------------------------------
\r
223 void cpPipelineEditor::OutputPort::
\r
226 QFontMetrics fm( this->scene( )->font( ) );
\r
227 this->m_Label->setPos(
\r
228 -fm.width( this->name( ) ) - this->m_Radius * 2, -fm.height( ) / 2
\r
230 this->m_ExtendedLabel->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
234 // -------------------------------------------------------------------------
\r
235 void cpPipelineEditor::OutputPort::
\r
236 setExtend( bool extend )
\r
238 this->m_IsExtended = extend;
\r
239 this->m_ExtendedLabel->setVisible( extend );
\r
242 // -------------------------------------------------------------------------
\r
243 bool cpPipelineEditor::OutputPort::
\r
244 isConnected( Port* other )
\r
246 auto i = this->m_Connections.begin( );
\r
248 for( ; i != this->m_Connections.end( ) && !conn; ++i )
\r
249 conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );
\r
253 // -------------------------------------------------------------------------
\r
254 QVariant cpPipelineEditor::OutputPort::
\r
255 itemChange( GraphicsItemChange change, const QVariant& value )
\r
257 if( change == ItemScenePositionHasChanged )
\r
259 foreach( Connection* conn, this->m_Connections )
\r
261 conn->updatePosFromPorts( );
\r
262 conn->updatePath( );
\r
270 // -------------------------------------------------------------------------
\r
271 void cpPipelineEditor::OutputPort::
\r
272 contextMenuEvent( QGraphicsSceneContextMenuEvent* evt )
\r
274 if( this->m_Block == NULL )
\r
278 QAction* showAction = menu.addAction( "Show" );
\r
279 QAction* hideAction = menu.addAction( "Hide" );
\r
280 QAction* propertiesAction = menu.addAction( "Properties" );
\r
281 QAction* selectedAction = menu.exec( evt->screenPos( ) );
\r
283 if( selectedAction == showAction )
\r
285 this->m_Block->editor( )->showOutputData(
\r
286 this->m_Block->namePort( ).toStdString( ),
\r
287 this->name( ).toStdString( )
\r
290 else if( selectedAction == hideAction )
\r
292 this->m_Block->editor( )->hideOutputData(
\r
293 this->m_Block->namePort( ).toStdString( ),
\r
294 this->name( ).toStdString( )
\r
297 else if( selectedAction == propertiesAction )
\r
299 auto filter = this->m_Block->filter( );
\r
300 auto name = this->name( ).toStdString( );
\r
301 if( filter != NULL )
\r
303 auto output = filter->GetOutput( name );
\r
304 if( output != NULL )
\r
306 auto dlg = output->CreateQtDialog( );
\r