2 #include "Connection.h"
\r
4 #include <QGraphicsScene>
\r
5 #include <QFontMetrics>
\r
9 // -------------------------------------------------------------------------
\r
10 cpPipelineEditor::Port::
\r
11 Port( QGraphicsItem* parent, QGraphicsScene* scene )
\r
12 : Superclass( parent, scene ),
\r
16 this->m_Label = new QGraphicsTextItem( this );
\r
17 this->m_ExtendedLabel = new QGraphicsTextItem( this );
\r
18 this->setExtend( false );
\r
21 p.addEllipse( 0, 0, 2 * this->m_Radius, 2 * this->m_Radius );
\r
24 this->setPen( QPen( Qt::darkRed ) );
\r
25 this->setBrush( Qt::red );
\r
26 this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges );
\r
29 // -------------------------------------------------------------------------
\r
30 cpPipelineEditor::Port::
\r
35 // -------------------------------------------------------------------------
\r
36 void cpPipelineEditor::Port::
\r
37 setBlock( Block* b )
\r
42 // -------------------------------------------------------------------------
\r
43 void cpPipelineEditor::Port::
\r
44 setName( const QString& n )
\r
46 this->m_Label->setPlainText( n );
\r
47 this->_updateLabels( );
\r
50 // -------------------------------------------------------------------------
\r
51 void cpPipelineEditor::Port::
\r
52 setExtendedName( const QString& n )
\r
54 this->m_ExtendedLabel->setPlainText( n );
\r
55 this->_updateLabels( );
\r
58 // -------------------------------------------------------------------------
\r
59 void cpPipelineEditor::Port::
\r
60 setExtend( bool extend )
\r
63 this->m_IsExtended = false;
\r
64 this->m_ExtendedLabel->setVisible( false );
\r
67 // -------------------------------------------------------------------------
\r
68 void cpPipelineEditor::Port::
\r
71 const QStyleOptionGraphicsItem* option,
\r
78 if( this->isExtended( ) )
\r
80 painter->setPen( QPen( Qt::darkBlue ) );
\r
81 painter->setBrush( Qt::blue );
\r
85 painter->setPen( QPen( Qt::darkRed ) );
\r
86 painter->setBrush( Qt::red );
\r
89 painter->drawPath( this->path( ) );
\r
92 // -------------------------------------------------------------------------
\r
93 cpPipelineEditor::NamePort::
\r
94 NamePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
95 : Superclass( parent, scene )
\r
99 // -------------------------------------------------------------------------
\r
100 cpPipelineEditor::NamePort::
\r
105 // -------------------------------------------------------------------------
\r
106 void cpPipelineEditor::NamePort::
\r
109 QFont font( this->scene( )->font( ) );
\r
110 font.setBold( true );
\r
111 this->m_Label->setFont( font );
\r
112 this->m_ExtendedLabel->setFont( font );
\r
113 this->setPath( QPainterPath( ) );
\r
116 // -------------------------------------------------------------------------
\r
117 bool cpPipelineEditor::NamePort::
\r
118 isConnected( Port* other )
\r
123 // -------------------------------------------------------------------------
\r
124 cpPipelineEditor::TypePort::
\r
125 TypePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
126 : Superclass( parent, scene )
\r
130 // -------------------------------------------------------------------------
\r
131 cpPipelineEditor::TypePort::
\r
136 // -------------------------------------------------------------------------
\r
137 void cpPipelineEditor::TypePort::
\r
140 QFont font( this->scene( )->font( ) );
\r
141 font.setItalic( true );
\r
142 this->m_Label->setFont( font );
\r
143 this->m_ExtendedLabel->setFont( font );
\r
144 this->setPath( QPainterPath( ) );
\r
147 // -------------------------------------------------------------------------
\r
148 bool cpPipelineEditor::TypePort::
\r
149 isConnected( Port* other )
\r
154 // -------------------------------------------------------------------------
\r
155 cpPipelineEditor::InputPort::
\r
156 InputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
157 : Superclass( parent, scene ),
\r
158 m_Connection( NULL )
\r
162 // -------------------------------------------------------------------------
\r
163 cpPipelineEditor::InputPort::
\r
166 if( this->m_Connection != NULL )
\r
167 delete this->m_Connection;
\r
170 // -------------------------------------------------------------------------
\r
171 void cpPipelineEditor::InputPort::
\r
174 QFontMetrics fm( this->scene( )->font( ) );
\r
175 this->m_Label->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
176 this->m_ExtendedLabel->setPos(
\r
177 -fm.width( this->extendedName( ) ) - this->m_Radius * 2,
\r
182 // -------------------------------------------------------------------------
\r
183 void cpPipelineEditor::InputPort::
\r
184 setExtend( bool extend )
\r
186 if( this->m_Connection == NULL )
\r
188 this->m_IsExtended = extend;
\r
189 this->m_ExtendedLabel->setVisible( extend );
\r
192 this->Superclass::setExtend( false );
\r
195 // -------------------------------------------------------------------------
\r
196 bool cpPipelineEditor::InputPort::
\r
197 isConnected( Port* other )
\r
199 if( this->m_Connection != NULL )
\r
201 this->m_Connection->port1( ) == other &&
\r
202 this->m_Connection->port2( ) == this
\r
208 // -------------------------------------------------------------------------
\r
209 void cpPipelineEditor::InputPort::
\r
210 setConnection( Connection* c )
\r
212 this->m_Connection = c;
\r
215 // -------------------------------------------------------------------------
\r
216 QVariant cpPipelineEditor::InputPort::
\r
217 itemChange( GraphicsItemChange change, const QVariant& value )
\r
219 if( change == ItemScenePositionHasChanged )
\r
221 if( this->m_Connection != NULL )
\r
223 this->m_Connection->updatePosFromPorts( );
\r
224 this->m_Connection->updatePath( );
\r
232 // -------------------------------------------------------------------------
\r
233 cpPipelineEditor::OutputPort::
\r
234 OutputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
235 : Superclass( parent, scene )
\r
239 // -------------------------------------------------------------------------
\r
240 cpPipelineEditor::OutputPort::
\r
243 foreach( Connection* conn, this->m_Connections )
\r
247 // -------------------------------------------------------------------------
\r
248 void cpPipelineEditor::OutputPort::
\r
251 QFontMetrics fm( this->scene( )->font( ) );
\r
252 this->m_Label->setPos(
\r
253 -fm.width( this->name( ) ) - this->m_Radius * 2, -fm.height( ) / 2
\r
255 this->m_ExtendedLabel->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
259 // -------------------------------------------------------------------------
\r
260 void cpPipelineEditor::OutputPort::
\r
261 setExtend( bool extend )
\r
263 this->m_IsExtended = extend;
\r
264 this->m_ExtendedLabel->setVisible( extend );
\r
267 // -------------------------------------------------------------------------
\r
268 bool cpPipelineEditor::OutputPort::
\r
269 isConnected( Port* other )
\r
271 auto i = this->m_Connections.begin( );
\r
273 for( ; i != this->m_Connections.end( ) && !conn; ++i )
\r
274 conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );
\r
278 // -------------------------------------------------------------------------
\r
279 QVariant cpPipelineEditor::OutputPort::
\r
280 itemChange( GraphicsItemChange change, const QVariant& value )
\r
282 if( change == ItemScenePositionHasChanged )
\r
284 foreach( Connection* conn, this->m_Connections )
\r
286 conn->updatePosFromPorts( );
\r
287 conn->updatePath( );
\r