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 QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( this->m_Port1 );
\r
52 op->connections( ).remove( op->connections( ).indexOf( this ) );
\r
54 QNEInputPort* ip = dynamic_cast< QNEInputPort* >( this->m_Port2 );
\r
56 ip->setConnection( NULL );
\r
59 // -------------------------------------------------------------------------
\r
60 void PipelineEditor::QNEConnection::
\r
61 setPos1( const QPointF& p )
\r
66 // -------------------------------------------------------------------------
\r
67 void PipelineEditor::QNEConnection::
\r
68 setPos2( const QPointF& p )
\r
73 // -------------------------------------------------------------------------
\r
74 void PipelineEditor::QNEConnection::
\r
75 setPort1( QNEPort* p )
\r
77 QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( p );
\r
80 op->connections( ).append( this );
\r
86 // -------------------------------------------------------------------------
\r
87 void PipelineEditor::QNEConnection::
\r
88 setPort2( QNEPort* p )
\r
90 QNEInputPort* ip = dynamic_cast< QNEInputPort* >( p );
\r
93 if( ip->connection( ) == NULL )
\r
95 ip->setConnection( this );
\r
103 // -------------------------------------------------------------------------
\r
104 void PipelineEditor::QNEConnection::
\r
105 updatePosFromPorts( )
\r
107 this->m_Pos1 = this->m_Port1->scenePos( );
\r
108 this->m_Pos2 = this->m_Port2->scenePos( );
\r
111 // -------------------------------------------------------------------------
\r
112 void PipelineEditor::QNEConnection::
\r
116 p.moveTo( this->m_Pos1 );
\r
118 qreal dx = this->m_Pos2.x( ) - this->m_Pos1.x( );
\r
119 qreal dy = this->m_Pos2.y( ) - this->m_Pos1.y( );
\r
120 QPointF c1( this->m_Pos1.x( ) + dx * 0.25, this->m_Pos1.y( ) + dy * 0.1 );
\r
121 QPointF c2( this->m_Pos1.x( ) + dx * 0.75, this->m_Pos1.y( ) + dy * 0.9 );
\r
122 p.cubicTo( c1, c2, this->m_Pos2 );
\r
124 this->setPath( p );
\r
127 // -------------------------------------------------------------------------
\r
128 PipelineEditor::QNEPort* PipelineEditor::QNEConnection::
\r
131 return( this->m_Port1 );
\r
134 // -------------------------------------------------------------------------
\r
135 PipelineEditor::QNEPort* PipelineEditor::QNEConnection::
\r
138 return( this->m_Port2 );
\r