2 #include "Connection.h"
\r
6 #include <QGraphicsScene>
\r
7 #include <QGraphicsSceneContextMenuEvent>
\r
8 #include <QFontMetrics>
\r
13 // -------------------------------------------------------------------------
\r
14 cpPipelineEditor::Port::
\r
15 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 cpPipelineEditor::Port::
\r
39 // -------------------------------------------------------------------------
\r
40 void cpPipelineEditor::Port::
\r
41 setBlock( Block* b )
\r
46 // -------------------------------------------------------------------------
\r
47 void cpPipelineEditor::Port::
\r
48 setName( const QString& n )
\r
50 this->m_Label->setPlainText( n );
\r
51 this->_updateLabels( );
\r
54 // -------------------------------------------------------------------------
\r
55 void cpPipelineEditor::Port::
\r
56 setExtendedName( const QString& n )
\r
58 this->m_ExtendedLabel->setPlainText( n );
\r
59 this->_updateLabels( );
\r
62 // -------------------------------------------------------------------------
\r
63 void cpPipelineEditor::Port::
\r
64 setExtend( bool extend )
\r
67 this->m_IsExtended = false;
\r
68 this->m_ExtendedLabel->setVisible( false );
\r
71 // -------------------------------------------------------------------------
\r
72 void cpPipelineEditor::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 cpPipelineEditor::NamePort::
\r
98 NamePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
99 : Superclass( parent, scene )
\r
103 // -------------------------------------------------------------------------
\r
104 cpPipelineEditor::NamePort::
\r
109 // -------------------------------------------------------------------------
\r
110 void cpPipelineEditor::NamePort::
\r
113 QFont font( this->scene( )->font( ) );
\r
114 font.setBold( true );
\r
115 this->m_Label->setFont( font );
\r
116 this->m_ExtendedLabel->setFont( font );
\r
117 this->setPath( QPainterPath( ) );
\r
120 // -------------------------------------------------------------------------
\r
121 bool cpPipelineEditor::NamePort::
\r
122 isConnected( Port* other )
\r
127 // -------------------------------------------------------------------------
\r
128 cpPipelineEditor::TypePort::
\r
129 TypePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
130 : Superclass( parent, scene )
\r
134 // -------------------------------------------------------------------------
\r
135 cpPipelineEditor::TypePort::
\r
140 // -------------------------------------------------------------------------
\r
141 void cpPipelineEditor::TypePort::
\r
144 QFont font( this->scene( )->font( ) );
\r
145 font.setItalic( true );
\r
146 this->m_Label->setFont( font );
\r
147 this->m_ExtendedLabel->setFont( font );
\r
148 this->setPath( QPainterPath( ) );
\r
151 // -------------------------------------------------------------------------
\r
152 bool cpPipelineEditor::TypePort::
\r
153 isConnected( Port* other )
\r
158 // -------------------------------------------------------------------------
\r
159 cpPipelineEditor::InputPort::
\r
160 InputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
161 : Superclass( parent, scene ),
\r
162 m_Connection( NULL )
\r
166 // -------------------------------------------------------------------------
\r
167 cpPipelineEditor::InputPort::
\r
170 if( this->m_Connection != NULL )
\r
171 delete this->m_Connection;
\r
174 // -------------------------------------------------------------------------
\r
175 void cpPipelineEditor::InputPort::
\r
178 QFontMetrics fm( this->scene( )->font( ) );
\r
179 this->m_Label->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
180 this->m_ExtendedLabel->setPos(
\r
181 -fm.width( this->extendedName( ) ) - this->m_Radius * 2,
\r
186 // -------------------------------------------------------------------------
\r
187 void cpPipelineEditor::InputPort::
\r
188 setExtend( bool extend )
\r
190 if( this->m_Connection == NULL )
\r
192 this->m_IsExtended = extend;
\r
193 this->m_ExtendedLabel->setVisible( extend );
\r
196 this->Superclass::setExtend( false );
\r
199 // -------------------------------------------------------------------------
\r
200 bool cpPipelineEditor::InputPort::
\r
201 isConnected( Port* other )
\r
203 if( this->m_Connection != NULL )
\r
205 this->m_Connection->port1( ) == other &&
\r
206 this->m_Connection->port2( ) == this
\r
212 // -------------------------------------------------------------------------
\r
213 void cpPipelineEditor::InputPort::
\r
214 setConnection( Connection* c )
\r
216 this->m_Connection = c;
\r
219 // -------------------------------------------------------------------------
\r
220 QVariant cpPipelineEditor::InputPort::
\r
221 itemChange( GraphicsItemChange change, const QVariant& value )
\r
223 if( change == ItemScenePositionHasChanged )
\r
225 if( this->m_Connection != NULL )
\r
227 this->m_Connection->updatePosFromPorts( );
\r
228 this->m_Connection->updatePath( );
\r
236 // -------------------------------------------------------------------------
\r
237 cpPipelineEditor::OutputPort::
\r
238 OutputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
239 : Superclass( parent, scene )
\r
243 // -------------------------------------------------------------------------
\r
244 cpPipelineEditor::OutputPort::
\r
247 foreach( Connection* conn, this->m_Connections )
\r
251 // -------------------------------------------------------------------------
\r
252 void cpPipelineEditor::OutputPort::
\r
255 QFontMetrics fm( this->scene( )->font( ) );
\r
256 this->m_Label->setPos(
\r
257 -fm.width( this->name( ) ) - this->m_Radius * 2, -fm.height( ) / 2
\r
259 this->m_ExtendedLabel->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
263 // -------------------------------------------------------------------------
\r
264 void cpPipelineEditor::OutputPort::
\r
265 setExtend( bool extend )
\r
267 this->m_IsExtended = extend;
\r
268 this->m_ExtendedLabel->setVisible( extend );
\r
271 // -------------------------------------------------------------------------
\r
272 bool cpPipelineEditor::OutputPort::
\r
273 isConnected( Port* other )
\r
275 auto i = this->m_Connections.begin( );
\r
277 for( ; i != this->m_Connections.end( ) && !conn; ++i )
\r
278 conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );
\r
282 // -------------------------------------------------------------------------
\r
283 QVariant cpPipelineEditor::OutputPort::
\r
284 itemChange( GraphicsItemChange change, const QVariant& value )
\r
286 if( change == ItemScenePositionHasChanged )
\r
288 foreach( Connection* conn, this->m_Connections )
\r
290 conn->updatePosFromPorts( );
\r
291 conn->updatePath( );
\r
299 // -------------------------------------------------------------------------
\r
300 void cpPipelineEditor::OutputPort::
\r
301 contextMenuEvent( QGraphicsSceneContextMenuEvent* evt )
\r
303 if( this->m_Block == NULL )
\r
307 QAction* showAction = menu.addAction( "Show" );
\r
308 QAction* hideAction = menu.addAction( "Hide" );
\r
309 QAction* selectedAction = menu.exec( evt->screenPos( ) );
\r
311 if( selectedAction == showAction )
\r
313 this->m_Block->editor( )->showOutputData(
\r
314 this->m_Block->namePort( ).toStdString( ),
\r
315 this->name( ).toStdString( )
\r
318 else if( selectedAction == hideAction )
\r