4 #include <QGraphicsScene>
\r
5 #include <QGraphicsSceneContextMenuEvent>
\r
6 #include <QFontMetrics>
\r
9 #include <QStyleOptionGraphicsItem>
\r
10 #include <QGraphicsWidget>
\r
13 #include "Connection.h"
\r
15 // -------------------------------------------------------------------------
\r
16 cpPipelineEditor::Block::
\r
17 Block( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene )
\r
18 : Superclass( parent, scene ),
\r
26 p.addRoundedRect( -50, -15, 100, 30, 5, 5 );
\r
29 this->setPen( QPen( Qt::darkGreen ) );
\r
30 this->setBrush( Qt::green );
\r
31 this->setFlag( QGraphicsItem::ItemIsMovable );
\r
32 this->setFlag( QGraphicsItem::ItemIsSelectable );
\r
34 this->m_Width = this->m_HorzMargin;
\r
35 this->m_Height = this->m_VertMargin;
\r
38 this->setNamePort( this->m_Filter->GetName( ) );
\r
39 this->_setTypePort( this->m_Filter->GetClassName( ) );
\r
42 std::set< std::string > inputs;
\r
43 this->m_Filter->GetInputsNames( inputs );
\r
44 for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
\r
45 this->addInputPort( iIt->c_str( ) );
\r
48 std::set< std::string > outputs;
\r
49 this->m_Filter->GetOutputsNames( outputs );
\r
50 for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
\r
51 this->addOutputPort( oIt->c_str( ) );
\r
54 // -------------------------------------------------------------------------
\r
55 cpPipelineEditor::Block::
\r
60 // -------------------------------------------------------------------------
\r
61 void cpPipelineEditor::Block::
\r
62 setNamePort( const QString& txt )
\r
64 if( this->m_NamePort == NULL )
\r
65 this->m_NamePort = new NamePort( this );
\r
66 this->m_NamePort->setName( txt );
\r
67 this->_configPort( this->m_NamePort );
\r
70 // -------------------------------------------------------------------------
\r
71 cpPipelineEditor::InputPort* cpPipelineEditor::Block::
\r
72 addInputPort( const QString& txt )
\r
74 InputPort* ip = new InputPort( this );
\r
75 ip->setExtendedName(
\r
77 txt.toStdString( ) +
\r
78 std::string( "@" ) +
\r
79 this->namePort( ).toStdString( )
\r
83 this->m_InputPorts[ txt.toStdString( ) ] = ip;
\r
84 this->_configPort( ip );
\r
88 // -------------------------------------------------------------------------
\r
89 cpPipelineEditor::OutputPort* cpPipelineEditor::Block::
\r
90 addOutputPort( const QString& txt )
\r
92 OutputPort* op = new OutputPort( this );
\r
93 op->setExtendedName(
\r
95 txt.toStdString( ) +
\r
96 std::string( "@" ) +
\r
97 this->namePort( ).toStdString( )
\r
100 op->setName( txt );
\r
101 this->m_OutputPorts[ txt.toStdString( ) ] = op;
\r
102 this->_configPort( op );
\r
106 // -------------------------------------------------------------------------
\r
107 cpPipelineEditor::InputPort* cpPipelineEditor::Block::
\r
108 inputPort( const QString& txt )
\r
110 auto i = this->m_InputPorts.find( txt.toStdString( ) );
\r
111 if( i != this->m_InputPorts.end( ) )
\r
112 return( i->second );
\r
117 // -------------------------------------------------------------------------
\r
118 cpPipelineEditor::OutputPort* cpPipelineEditor::Block::
\r
119 outputPort( const QString& txt )
\r
121 auto o = this->m_OutputPorts.find( txt.toStdString( ) );
\r
122 if( o != this->m_OutputPorts.end( ) )
\r
123 return( o->second );
\r
128 // -------------------------------------------------------------------------
\r
129 QString cpPipelineEditor::Block::
\r
132 return( this->m_NamePort->name( ) );
\r
135 // -------------------------------------------------------------------------
\r
136 const cpPipelineEditor::InputPort* cpPipelineEditor::Block::
\r
137 inputPort( const QString& txt ) const
\r
139 auto i = this->m_InputPorts.find( txt.toStdString( ) );
\r
140 if( i != this->m_InputPorts.end( ) )
\r
141 return( i->second );
\r
146 // -------------------------------------------------------------------------
\r
147 const cpPipelineEditor::OutputPort* cpPipelineEditor::Block::
\r
148 outputPort( const QString& txt ) const
\r
150 auto o = this->m_OutputPorts.find( txt.toStdString( ) );
\r
151 if( o != this->m_OutputPorts.end( ) )
\r
152 return( o->second );
\r
157 // -------------------------------------------------------------------------
\r
158 void cpPipelineEditor::Block::
\r
160 QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget
\r
163 Q_UNUSED( option );
\r
164 Q_UNUSED( widget );
\r
166 if( this->isSelected( ) )
\r
168 painter->setPen( QPen( Qt::darkYellow ) );
\r
169 painter->setBrush( Qt::yellow );
\r
173 painter->setPen( QPen( Qt::darkGreen ) );
\r
174 painter->setBrush( Qt::green );
\r
177 painter->drawPath( this->path( ) );
\r
180 // -------------------------------------------------------------------------
\r
181 QVariant cpPipelineEditor::Block::
\r
182 itemChange( GraphicsItemChange change, const QVariant& value )
\r
187 // -------------------------------------------------------------------------
\r
188 void cpPipelineEditor::Block::
\r
189 _setTypePort( const QString& txt )
\r
191 if( this->m_TypePort == NULL )
\r
192 this->m_TypePort = new TypePort( this );
\r
193 this->m_TypePort->setName( txt );
\r
194 this->_configPort( this->m_TypePort );
\r
197 // -------------------------------------------------------------------------
\r
198 void cpPipelineEditor::Block::
\r
199 _configPort( Port* port )
\r
201 port->setBlock( this );
\r
203 QFontMetrics fm( this->scene( )->font( ) );
\r
204 int w = fm.width( port->name( ) ) + ( 4 * port->radius( ) );
\r
205 int h = fm.height( );
\r
206 if( w > this->m_Width - this->m_HorzMargin )
\r
207 this->m_Width = w + this->m_HorzMargin;
\r
208 this->m_Height = this->m_InputPorts.size( ) + this->m_OutputPorts.size( );
\r
209 this->m_Height += 4;
\r
210 this->m_Height *= h;
\r
213 pth.addRoundedRect(
\r
214 -this->m_Width / 2,
\r
215 -this->m_Height / 2,
\r
217 this->m_Height, 5, 5
\r
219 this->setPath( pth );
\r
221 int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( );
\r
222 foreach( QGraphicsItem* i, this->children( ) )
\r
224 Port* p = dynamic_cast< Port* >( i );
\r
228 if( dynamic_cast< NamePort* >( i ) != NULL )
\r
229 i->setPos( -this->m_Width / 2 + port->radius( ), y );
\r
230 else if( dynamic_cast< TypePort* >( i ) != NULL )
\r
232 i->setPos( -this->m_Width / 2 + port->radius( ), y );
\r
235 else if( dynamic_cast< InputPort* >( i ) != NULL )
\r
236 i->setPos( -this->m_Width / 2 - 2 * port->radius( ), y );
\r
237 else if( dynamic_cast< OutputPort* >( i ) != NULL )
\r
238 i->setPos( this->m_Width / 2, y );
\r
244 // -------------------------------------------------------------------------
\r
245 void cpPipelineEditor::Block::
\r
246 mouseReleaseEvent( QGraphicsSceneMouseEvent* evt )
\r
248 if( this->m_Filter != NULL )
\r
249 this->m_Filter->SetViewCoords(
\r
250 this->scenePos( ).x( ), this->scenePos( ).y( )
\r
252 this->Superclass::mouseReleaseEvent( evt );
\r
255 // -------------------------------------------------------------------------
\r
256 void cpPipelineEditor::Block::
\r
257 contextMenuEvent( QGraphicsSceneContextMenuEvent* evt )
\r
260 QAction* configureAction = menu.addAction( "Configure" );
\r
261 QAction* updateAction = menu.addAction( "Update" );
\r
262 QAction* selectedAction = menu.exec( evt->screenPos( ) );
\r
264 if( selectedAction == configureAction )
\r
266 auto res = this->m_Filter->ExecConfigurationDialog( NULL );
\r
268 else if( selectedAction == updateAction )
\r