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 "QNEConnection.h"
\r
28 #include "QNEPort.h"
\r
32 #include <QGraphicsScene>
\r
34 // -------------------------------------------------------------------------
\r
35 PipelineEditor::QNEConnection::
\r
36 QNEConnection( QGraphicsItem* parent, QGraphicsScene* scene )
\r
37 : Superclass( parent, scene )
\r
39 this->setPen( QPen( Qt::black, 2 ) );
\r
40 this->setBrush( Qt::NoBrush );
\r
41 this->setZValue( -1 );
\r
42 this->m_Port1 = NULL;
\r
43 this->m_Port2 = NULL;
\r
46 // -------------------------------------------------------------------------
\r
47 PipelineEditor::QNEConnection::
\r
50 if( this->m_Port1 != NULL )
\r
51 this->m_Port1->connections( ).
\r
52 remove( this->m_Port1->connections( ).indexOf( this ) );
\r
54 if( this->m_Port2 != NULL )
\r
55 this->m_Port2->setConnection( NULL );
\r
58 // -------------------------------------------------------------------------
\r
59 void PipelineEditor::QNEConnection::
\r
60 setPos1( const QPointF& p )
\r
65 // -------------------------------------------------------------------------
\r
66 void PipelineEditor::QNEConnection::
\r
67 setPos2( const QPointF& p )
\r
72 // -------------------------------------------------------------------------
\r
73 void PipelineEditor::QNEConnection::
\r
74 setPort1( QNEOutputPort* p )
\r
78 p->connections( ).append( this );
\r
84 // -------------------------------------------------------------------------
\r
85 void PipelineEditor::QNEConnection::
\r
86 setPort2( QNEInputPort* p )
\r
90 if( p->connection( ) == NULL )
\r
92 p->setConnection( this );
\r
100 // -------------------------------------------------------------------------
\r
101 void PipelineEditor::QNEConnection::
\r
102 updatePosFromPorts( )
\r
104 this->m_Pos1 = this->m_Port1->scenePos( );
\r
105 this->m_Pos2 = this->m_Port2->scenePos( );
\r
108 // -------------------------------------------------------------------------
\r
109 void PipelineEditor::QNEConnection::
\r
113 p.moveTo( this->m_Pos1 );
\r
115 qreal dx = this->m_Pos2.x( ) - this->m_Pos1.x( );
\r
116 qreal dy = this->m_Pos2.y( ) - this->m_Pos1.y( );
\r
117 QPointF c1( this->m_Pos1.x( ) + dx * 0.25, this->m_Pos1.y( ) + dy * 0.1 );
\r
118 QPointF c2( this->m_Pos1.x( ) + dx * 0.75, this->m_Pos1.y( ) + dy * 0.9 );
\r
119 p.cubicTo( c1, c2, this->m_Pos2 );
\r
121 this->setPath( p );
\r
124 // -------------------------------------------------------------------------
\r
125 PipelineEditor::QNEOutputPort* PipelineEditor::QNEConnection::
\r
128 return( this->m_Port1 );
\r
131 // -------------------------------------------------------------------------
\r
132 PipelineEditor::QNEInputPort* PipelineEditor::QNEConnection::
\r
135 return( this->m_Port2 );
\r