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
35 // -------------------------------------------------------------------------
\r
36 PipelineEditor::QNEPort::
\r
37 QNEPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
38 : Superclass( parent, scene ),
\r
42 this->m_Label = new QGraphicsTextItem( this );
\r
43 this->m_ExtendedLabel = new QGraphicsTextItem( this );
\r
44 this->setExtend( false );
\r
47 p.addEllipse( 0, 0, 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
72 this->m_Label->setPlainText( n );
\r
73 this->_updateLabels( );
\r
76 // -------------------------------------------------------------------------
\r
77 void PipelineEditor::QNEPort::
\r
78 setExtendedName( const QString& n )
\r
80 this->m_ExtendedLabel->setPlainText( n );
\r
81 this->_updateLabels( );
\r
84 // -------------------------------------------------------------------------
\r
85 void PipelineEditor::QNEPort::
\r
86 setExtend( bool extend )
\r
89 this->m_IsExtended = false;
\r
90 this->m_ExtendedLabel->setVisible( false );
\r
93 // -------------------------------------------------------------------------
\r
94 void PipelineEditor::QNEPort::
\r
97 const QStyleOptionGraphicsItem* option,
\r
101 Q_UNUSED( option );
\r
102 Q_UNUSED( widget );
\r
104 if( this->isExtended( ) )
\r
106 painter->setPen( QPen( Qt::darkBlue ) );
\r
107 painter->setBrush( Qt::blue );
\r
111 painter->setPen( QPen( Qt::darkRed ) );
\r
112 painter->setBrush( Qt::red );
\r
115 painter->drawPath( this->path( ) );
\r
118 // -------------------------------------------------------------------------
\r
119 PipelineEditor::QNENamePort::
\r
120 QNENamePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
121 : Superclass( parent, scene )
\r
125 // -------------------------------------------------------------------------
\r
126 PipelineEditor::QNENamePort::
\r
131 // -------------------------------------------------------------------------
\r
132 void PipelineEditor::QNENamePort::
\r
135 QFont font( this->scene( )->font( ) );
\r
136 font.setBold( true );
\r
137 this->m_Label->setFont( font );
\r
138 this->m_ExtendedLabel->setFont( font );
\r
139 this->setPath( QPainterPath( ) );
\r
142 // -------------------------------------------------------------------------
\r
143 bool PipelineEditor::QNENamePort::
\r
144 isConnected( QNEPort* other )
\r
149 // -------------------------------------------------------------------------
\r
150 PipelineEditor::QNETypePort::
\r
151 QNETypePort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
152 : Superclass( parent, scene )
\r
156 // -------------------------------------------------------------------------
\r
157 PipelineEditor::QNETypePort::
\r
162 // -------------------------------------------------------------------------
\r
163 void PipelineEditor::QNETypePort::
\r
166 QFont font( this->scene( )->font( ) );
\r
167 font.setItalic( true );
\r
168 this->m_Label->setFont( font );
\r
169 this->m_ExtendedLabel->setFont( font );
\r
170 this->setPath( QPainterPath( ) );
\r
173 // -------------------------------------------------------------------------
\r
174 bool PipelineEditor::QNETypePort::
\r
175 isConnected( QNEPort* other )
\r
180 // -------------------------------------------------------------------------
\r
181 PipelineEditor::QNEInputPort::
\r
182 QNEInputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
183 : Superclass( parent, scene ),
\r
184 m_Connection( NULL )
\r
188 // -------------------------------------------------------------------------
\r
189 PipelineEditor::QNEInputPort::
\r
192 if( this->m_Connection != NULL )
\r
193 delete this->m_Connection;
\r
196 // -------------------------------------------------------------------------
\r
197 void PipelineEditor::QNEInputPort::
\r
200 QFontMetrics fm( this->scene( )->font( ) );
\r
201 this->m_Label->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
202 this->m_ExtendedLabel->setPos(
\r
203 -fm.width( this->extendedName( ) ) - this->m_Radius * 2,
\r
208 // -------------------------------------------------------------------------
\r
209 void PipelineEditor::QNEInputPort::
\r
210 setExtend( bool extend )
\r
212 if( this->m_Connection == NULL )
\r
214 this->m_IsExtended = extend;
\r
215 this->m_ExtendedLabel->setVisible( extend );
\r
218 this->Superclass::setExtend( false );
\r
221 // -------------------------------------------------------------------------
\r
222 bool PipelineEditor::QNEInputPort::
\r
223 isConnected( QNEPort* other )
\r
225 if( this->m_Connection != NULL )
\r
227 this->m_Connection->port1( ) == other &&
\r
228 this->m_Connection->port2( ) == this
\r
234 // -------------------------------------------------------------------------
\r
235 void PipelineEditor::QNEInputPort::
\r
236 setConnection( QNEConnection* c )
\r
238 this->m_Connection = c;
\r
241 // -------------------------------------------------------------------------
\r
242 QVariant PipelineEditor::QNEInputPort::
\r
243 itemChange( GraphicsItemChange change, const QVariant& value )
\r
245 if( change == ItemScenePositionHasChanged )
\r
247 if( this->m_Connection != NULL )
\r
249 this->m_Connection->updatePosFromPorts( );
\r
250 this->m_Connection->updatePath( );
\r
258 // -------------------------------------------------------------------------
\r
259 PipelineEditor::QNEOutputPort::
\r
260 QNEOutputPort( QGraphicsItem* parent, QGraphicsScene* scene )
\r
261 : Superclass( parent, scene )
\r
265 // -------------------------------------------------------------------------
\r
266 PipelineEditor::QNEOutputPort::
\r
269 foreach( QNEConnection* conn, this->m_Connections )
\r
273 // -------------------------------------------------------------------------
\r
274 void PipelineEditor::QNEOutputPort::
\r
277 QFontMetrics fm( this->scene( )->font( ) );
\r
278 this->m_Label->setPos(
\r
279 -fm.width( this->name( ) ) - this->m_Radius * 2, -fm.height( ) / 2
\r
281 this->m_ExtendedLabel->setPos( this->m_Radius * 2, -fm.height( ) / 2 );
\r
285 // -------------------------------------------------------------------------
\r
286 void PipelineEditor::QNEOutputPort::
\r
287 setExtend( bool extend )
\r
289 this->m_IsExtended = extend;
\r
290 this->m_ExtendedLabel->setVisible( extend );
\r
293 // -------------------------------------------------------------------------
\r
294 bool PipelineEditor::QNEOutputPort::
\r
295 isConnected( QNEPort* other )
\r
297 auto i = this->m_Connections.begin( );
\r
299 for( ; i != this->m_Connections.end( ) && !conn; ++i )
\r
300 conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );
\r
304 // -------------------------------------------------------------------------
\r
305 QVariant PipelineEditor::QNEOutputPort::
\r
306 itemChange( GraphicsItemChange change, const QVariant& value )
\r
308 if( change == ItemScenePositionHasChanged )
\r
310 foreach( QNEConnection* conn, this->m_Connections )
\r
312 conn->updatePosFromPorts( );
\r
313 conn->updatePath( );
\r