4 #include <QGraphicsScene>
\r
5 #include <QFontMetrics>
\r
7 #include <QStyleOptionGraphicsItem>
\r
10 #include "Connection.h"
\r
12 // -------------------------------------------------------------------------
\r
13 cpPipelineEditor::Block::
\r
14 Block( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene )
\r
15 : Superclass( parent, scene ),
\r
23 p.addRoundedRect( -50, -15, 100, 30, 5, 5 );
\r
26 this->setPen( QPen( Qt::darkGreen ) );
\r
27 this->setBrush( Qt::green );
\r
28 this->setFlag( QGraphicsItem::ItemIsMovable );
\r
29 this->setFlag( QGraphicsItem::ItemIsSelectable );
\r
31 this->m_Width = this->m_HorzMargin;
\r
32 this->m_Height = this->m_VertMargin;
\r
35 this->setNamePort( this->m_Filter->GetName( ) );
\r
36 this->_setTypePort( this->m_Filter->GetClassName( ) );
\r
39 std::set< std::string > inputs;
\r
40 this->m_Filter->GetInputsNames( inputs );
\r
41 for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
\r
42 this->addInputPort( iIt->c_str( ) );
\r
45 std::set< std::string > outputs;
\r
46 this->m_Filter->GetOutputsNames( outputs );
\r
47 for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
\r
48 this->addOutputPort( oIt->c_str( ) );
\r
51 // -------------------------------------------------------------------------
\r
52 cpPipelineEditor::Block::
\r
57 // -------------------------------------------------------------------------
\r
58 void cpPipelineEditor::Block::
\r
59 setNamePort( const QString& txt )
\r
61 if( this->m_NamePort == NULL )
\r
62 this->m_NamePort = new NamePort( this );
\r
63 this->m_NamePort->setName( txt );
\r
64 this->_configPort( this->m_NamePort );
\r
67 // -------------------------------------------------------------------------
\r
68 cpPipelineEditor::InputPort* cpPipelineEditor::Block::
\r
69 addInputPort( const QString& txt )
\r
71 InputPort* ip = new InputPort( this );
\r
72 ip->setExtendedName(
\r
74 txt.toStdString( ) +
\r
75 std::string( "@" ) +
\r
76 this->namePort( ).toStdString( )
\r
80 this->m_InputPorts[ txt.toStdString( ) ] = ip;
\r
81 this->_configPort( ip );
\r
85 // -------------------------------------------------------------------------
\r
86 cpPipelineEditor::OutputPort* cpPipelineEditor::Block::
\r
87 addOutputPort( const QString& txt )
\r
89 OutputPort* op = new OutputPort( this );
\r
90 op->setExtendedName(
\r
92 txt.toStdString( ) +
\r
93 std::string( "@" ) +
\r
94 this->namePort( ).toStdString( )
\r
98 this->m_OutputPorts[ txt.toStdString( ) ] = op;
\r
99 this->_configPort( op );
\r
103 // -------------------------------------------------------------------------
\r
104 cpPipelineEditor::InputPort* cpPipelineEditor::Block::
\r
105 inputPort( const QString& txt )
\r
107 auto i = this->m_InputPorts.find( txt.toStdString( ) );
\r
108 if( i != this->m_InputPorts.end( ) )
\r
109 return( i->second );
\r
114 // -------------------------------------------------------------------------
\r
115 cpPipelineEditor::OutputPort* cpPipelineEditor::Block::
\r
116 outputPort( const QString& txt )
\r
118 auto o = this->m_OutputPorts.find( txt.toStdString( ) );
\r
119 if( o != this->m_OutputPorts.end( ) )
\r
120 return( o->second );
\r
125 // -------------------------------------------------------------------------
\r
126 QString cpPipelineEditor::Block::
\r
129 return( this->m_NamePort->name( ) );
\r
132 // -------------------------------------------------------------------------
\r
133 const cpPipelineEditor::InputPort* cpPipelineEditor::Block::
\r
134 inputPort( const QString& txt ) const
\r
136 auto i = this->m_InputPorts.find( txt.toStdString( ) );
\r
137 if( i != this->m_InputPorts.end( ) )
\r
138 return( i->second );
\r
143 // -------------------------------------------------------------------------
\r
144 const cpPipelineEditor::OutputPort* cpPipelineEditor::Block::
\r
145 outputPort( const QString& txt ) const
\r
147 auto o = this->m_OutputPorts.find( txt.toStdString( ) );
\r
148 if( o != this->m_OutputPorts.end( ) )
\r
149 return( o->second );
\r
154 // -------------------------------------------------------------------------
\r
155 void cpPipelineEditor::Block::
\r
157 QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget
\r
160 Q_UNUSED( option );
\r
161 Q_UNUSED( widget );
\r
163 if( this->isSelected( ) )
\r
165 painter->setPen( QPen( Qt::darkYellow ) );
\r
166 painter->setBrush( Qt::yellow );
\r
170 painter->setPen( QPen( Qt::darkGreen ) );
\r
171 painter->setBrush( Qt::green );
\r
174 painter->drawPath( this->path( ) );
\r
177 // -------------------------------------------------------------------------
\r
178 QVariant cpPipelineEditor::Block::
\r
179 itemChange( GraphicsItemChange change, const QVariant& value )
\r
184 // -------------------------------------------------------------------------
\r
185 void cpPipelineEditor::Block::
\r
186 _setTypePort( const QString& txt )
\r
188 if( this->m_TypePort == NULL )
\r
189 this->m_TypePort = new TypePort( this );
\r
190 this->m_TypePort->setName( txt );
\r
191 this->_configPort( this->m_TypePort );
\r
194 // -------------------------------------------------------------------------
\r
195 void cpPipelineEditor::Block::
\r
196 _configPort( Port* port )
\r
198 port->setBlock( this );
\r
200 QFontMetrics fm( this->scene( )->font( ) );
\r
201 int w = fm.width( port->name( ) ) + ( 4 * port->radius( ) );
\r
202 int h = fm.height( );
\r
203 if( w > this->m_Width - this->m_HorzMargin )
\r
204 this->m_Width = w + this->m_HorzMargin;
\r
205 this->m_Height = this->m_InputPorts.size( ) + this->m_OutputPorts.size( );
\r
206 this->m_Height += 4;
\r
207 this->m_Height *= h;
\r
210 pth.addRoundedRect(
\r
211 -this->m_Width / 2,
\r
212 -this->m_Height / 2,
\r
214 this->m_Height, 5, 5
\r
216 this->setPath( pth );
\r
218 int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( );
\r
219 foreach( QGraphicsItem* i, this->children( ) )
\r
221 Port* p = dynamic_cast< Port* >( i );
\r
225 if( dynamic_cast< NamePort* >( i ) != NULL )
\r
226 i->setPos( -this->m_Width / 2 + port->radius( ), y );
\r
227 else if( dynamic_cast< TypePort* >( i ) != NULL )
\r
229 i->setPos( -this->m_Width / 2 + port->radius( ), y );
\r
232 else if( dynamic_cast< InputPort* >( i ) != NULL )
\r
233 i->setPos( -this->m_Width / 2 - 2 * port->radius( ), y );
\r
234 else if( dynamic_cast< OutputPort* >( i ) != NULL )
\r
235 i->setPos( this->m_Width / 2, y );
\r
241 // -------------------------------------------------------------------------
\r
242 void cpPipelineEditor::Block::
\r
243 mouseReleaseEvent( QGraphicsSceneMouseEvent* evt )
\r
245 if( this->m_Filter != NULL )
\r
246 this->m_Filter->SetViewCoords(
\r
247 this->scenePos( ).x( ), this->scenePos( ).y( )
\r
249 this->Superclass::mouseReleaseEvent( evt );
\r