1 /* Copyright (c) 2012, STANISLAW ADASZEWSKI
\r
4 Redistribution and use in source and binary forms, with or without
\r
5 modification, are permitted provided that the following conditions are met:
\r
6 * Redistributions of source code must retain the above copyright
\r
7 notice, this list of conditions and the following disclaimer.
\r
8 * Redistributions in binary form must reproduce the above copyright
\r
9 notice, this list of conditions and the following disclaimer in the
\r
10 documentation and/or other materials provided with the distribution.
\r
11 * Neither the name of STANISLAW ADASZEWSKI nor the
\r
12 names of its contributors may be used to endorse or promote products
\r
13 derived from this software without specific prior written permission.
\r
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
\r
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
18 DISCLAIMED. IN NO EVENT SHALL STANISLAW ADASZEWSKI BE LIABLE FOR ANY
\r
19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
\r
22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 #include "QNEPort.h"
\r
28 #include "QNEConnection.h"
\r
30 #include <QGraphicsScene>
\r
31 #include <QFontMetrics>
\r
34 // -------------------------------------------------------------------------
\r
35 PipelineEditor::QNEPort::
\r
36 QNEPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
37 : Superclass( parent, scene ),
\r
41 this->m_Label = new QGraphicsTextItem( this );
\r
45 -this->m_Radius, -this->m_Radius,
\r
46 2 * this->m_Radius, 2 * this->m_Radius
\r
50 this->setPen( QPen( Qt::darkRed ) );
\r
51 this->setBrush( Qt::red );
\r
52 this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges );
\r
55 // -------------------------------------------------------------------------
\r
56 PipelineEditor::QNEPort::
\r
61 // -------------------------------------------------------------------------
\r
62 void PipelineEditor::QNEPort::
\r
63 setBlock( QNEBlock* b )
\r
68 // -------------------------------------------------------------------------
\r
69 void PipelineEditor::QNEPort::
\r
70 setName( const QString& n )
\r
73 this->m_Label->setPlainText( n );
\r
76 // -------------------------------------------------------------------------
\r
77 void PipelineEditor::QNEPort::
\r
83 // -------------------------------------------------------------------------
\r
84 PipelineEditor::QNENamePort::
\r
85 QNENamePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
86 : Superclass( parent, scene )
\r
90 // -------------------------------------------------------------------------
\r
91 PipelineEditor::QNENamePort::
\r
96 // -------------------------------------------------------------------------
\r
97 void PipelineEditor::QNENamePort::
\r
98 setName( const QString& n )
\r
100 this->Superclass::setName( n );
\r
102 QFont font( this->scene( )->font( ) );
\r
103 font.setBold( true );
\r
104 this->m_Label->setFont( font );
\r
105 this->setPath( QPainterPath( ) );
\r
108 // -------------------------------------------------------------------------
\r
109 bool PipelineEditor::QNENamePort::
\r
110 isConnected( QNEPort* other )
\r
115 // -------------------------------------------------------------------------
\r
116 PipelineEditor::QNETypePort::
\r
117 QNETypePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
118 : Superclass( parent, scene )
\r
122 // -------------------------------------------------------------------------
\r
123 PipelineEditor::QNETypePort::
\r
128 // -------------------------------------------------------------------------
\r
129 void PipelineEditor::QNETypePort::
\r
130 setName( const QString& n )
\r
132 this->Superclass::setName( n );
\r
134 QFont font( this->scene( )->font( ) );
\r
135 font.setItalic( true );
\r
136 this->m_Label->setFont( font );
\r
137 this->setPath( QPainterPath( ) );
\r
140 // -------------------------------------------------------------------------
\r
141 bool PipelineEditor::QNETypePort::
\r
142 isConnected( QNEPort* other )
\r
147 // -------------------------------------------------------------------------
\r
148 PipelineEditor::QNEInputPort::
\r
149 QNEInputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
150 : Superclass( parent, scene ),
\r
151 m_Connection( NULL )
\r
155 // -------------------------------------------------------------------------
\r
156 PipelineEditor::QNEInputPort::
\r
159 if( this->m_Connection != NULL )
\r
160 delete this->m_Connection;
\r
163 // -------------------------------------------------------------------------
\r
164 void PipelineEditor::QNEInputPort::
\r
165 setName( const QString& n )
\r
167 this->Superclass::setName( n );
\r
169 QFontMetrics fm( this->scene( )->font( ) );
\r
170 QRect r = fm.boundingRect( this->m_Name );
\r
171 int rm = this->m_Radius + this->m_Margin;
\r
172 int h = -this->m_Label->boundingRect( ).height( ) / 2;
\r
173 this->m_Label->setPos( rm, h );
\r
176 // -------------------------------------------------------------------------
\r
177 bool PipelineEditor::QNEInputPort::
\r
178 isConnected( QNEPort* other )
\r
180 if( this->m_Connection != NULL )
\r
182 this->m_Connection->port1( ) == other &&
\r
183 this->m_Connection->port2( ) == this
\r
189 // -------------------------------------------------------------------------
\r
190 void PipelineEditor::QNEInputPort::
\r
191 setConnection( QNEConnection* c )
\r
193 this->m_Connection = c;
\r
196 // -------------------------------------------------------------------------
\r
197 QVariant PipelineEditor::QNEInputPort::
\r
198 itemChange( GraphicsItemChange change, const QVariant& value )
\r
200 if( change == ItemScenePositionHasChanged )
\r
202 if( this->m_Connection != NULL )
\r
204 this->m_Connection->updatePosFromPorts( );
\r
205 this->m_Connection->updatePath( );
\r
213 // -------------------------------------------------------------------------
\r
214 PipelineEditor::QNEOutputPort::
\r
215 QNEOutputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
216 : Superclass( parent, scene )
\r
220 // -------------------------------------------------------------------------
\r
221 PipelineEditor::QNEOutputPort::
\r
224 foreach( QNEConnection* conn, this->m_Connections )
\r
228 // -------------------------------------------------------------------------
\r
229 void PipelineEditor::QNEOutputPort::
\r
230 setName( const QString& n )
\r
232 this->Superclass::setName( n );
\r
234 QFontMetrics fm( this->scene( )->font( ) );
\r
235 QRect r = fm.boundingRect( this->m_Name );
\r
236 int rm = this->m_Radius + this->m_Margin;
\r
237 int h = -this->m_Label->boundingRect( ).height( ) / 2;
\r
238 this->m_Label->setPos(
\r
239 -rm - this->m_Label->boundingRect( ).width( ), h
\r
243 // -------------------------------------------------------------------------
\r
244 bool PipelineEditor::QNEOutputPort::
\r
245 isConnected( QNEPort* other )
\r
247 auto i = this->m_Connections.begin( );
\r
249 for( ; i != this->m_Connections.end( ) && !conn; ++i )
\r
250 conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );
\r
254 // -------------------------------------------------------------------------
\r
255 QVariant PipelineEditor::QNEOutputPort::
\r
256 itemChange( GraphicsItemChange change, const QVariant& value )
\r
258 if( change == ItemScenePositionHasChanged )
\r
260 foreach( QNEConnection* conn, this->m_Connections )
\r
262 conn->updatePosFromPorts( );
\r
263 conn->updatePath( );
\r