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::InputPort::
\r
129 InputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
130 : Superclass( parent, scene ),
\r
131 m_Connection( NULL )
\r
135 // -------------------------------------------------------------------------
\r
136 cpPipelineEditor::InputPort::
\r
139 if( this->m_Connection != NULL )
\r
140 delete this->m_Connection;
\r
143 // -------------------------------------------------------------------------
\r
144 void cpPipelineEditor::InputPort::
\r
147 QFontMetrics fm( this->scene( )->font( ) );
\r
148 this->m_Label->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
149 this->m_ExtendedLabel->setPos(
\r
150 -fm.width( this->extendedName( ) ) - this->m_Radius * 2,
\r
155 // -------------------------------------------------------------------------
\r
156 void cpPipelineEditor::InputPort::
\r
157 setExtend( bool extend )
\r
159 if( this->m_Connection == NULL )
\r
161 this->m_IsExtended = extend;
\r
162 this->m_ExtendedLabel->setVisible( extend );
\r
165 this->Superclass::setExtend( false );
\r
168 // -------------------------------------------------------------------------
\r
169 bool cpPipelineEditor::InputPort::
\r
170 isConnected( Port* other )
\r
172 if( this->m_Connection != NULL )
\r
174 this->m_Connection->port1( ) == other &&
\r
175 this->m_Connection->port2( ) == this
\r
181 // -------------------------------------------------------------------------
\r
182 void cpPipelineEditor::InputPort::
\r
183 setConnection( Connection* c )
\r
185 this->m_Connection = c;
\r
188 // -------------------------------------------------------------------------
\r
189 QVariant cpPipelineEditor::InputPort::
\r
190 itemChange( GraphicsItemChange change, const QVariant& value )
\r
192 if( change == ItemScenePositionHasChanged )
\r
194 if( this->m_Connection != NULL )
\r
196 this->m_Connection->updatePosFromPorts( );
\r
197 this->m_Connection->updatePath( );
\r
205 // -------------------------------------------------------------------------
\r
206 cpPipelineEditor::OutputPort::
\r
207 OutputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
208 : Superclass( parent, scene )
\r
212 // -------------------------------------------------------------------------
\r
213 cpPipelineEditor::OutputPort::
\r
216 foreach( Connection* conn, this->m_Connections )
\r
220 // -------------------------------------------------------------------------
\r
221 void cpPipelineEditor::OutputPort::
\r
224 QFontMetrics fm( this->scene( )->font( ) );
\r
225 this->m_Label->setPos(
\r
226 -fm.width( this->name( ) ) - this->m_Radius * 2, -fm.height( ) / 2
\r
228 this->m_ExtendedLabel->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
232 // -------------------------------------------------------------------------
\r
233 void cpPipelineEditor::OutputPort::
\r
234 setExtend( bool extend )
\r
236 this->m_IsExtended = extend;
\r
237 this->m_ExtendedLabel->setVisible( extend );
\r
240 // -------------------------------------------------------------------------
\r
241 bool cpPipelineEditor::OutputPort::
\r
242 isConnected( Port* other )
\r
244 auto i = this->m_Connections.begin( );
\r
246 for( ; i != this->m_Connections.end( ) && !conn; ++i )
\r
247 conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );
\r
251 // -------------------------------------------------------------------------
\r
252 QVariant cpPipelineEditor::OutputPort::
\r
253 itemChange( GraphicsItemChange change, const QVariant& value )
\r
255 if( change == ItemScenePositionHasChanged )
\r
257 foreach( Connection* conn, this->m_Connections )
\r
259 conn->updatePosFromPorts( );
\r
260 conn->updatePath( );
\r
268 // -------------------------------------------------------------------------
\r
269 void cpPipelineEditor::OutputPort::
\r
270 contextMenuEvent( QGraphicsSceneContextMenuEvent* evt )
\r
272 if( this->m_Block == NULL )
\r
276 QAction* showAction = menu.addAction( "Show" );
\r
277 QAction* hideAction = menu.addAction( "Hide" );
\r
278 QAction* selectedAction = menu.exec( evt->screenPos( ) );
\r
280 if( selectedAction == showAction )
\r
282 this->m_Block->editor( )->showOutputData(
\r
283 this->m_Block->namePort( ).toStdString( ),
\r
284 this->name( ).toStdString( )
\r
287 else if( selectedAction == hideAction )
\r