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
29 #include "QNEPort.h"
\r
33 #include <QGraphicsScene>
\r
35 // -------------------------------------------------------------------------
\r
36 PipelineEditor::QNEConnection::
\r
37 QNEConnection( QGraphicsItem* parent, QGraphicsScene* scene )
\r
38 : Superclass( parent, scene )
\r
40 this->setPen( QPen( Qt::black, 2 ) );
\r
41 this->setBrush( Qt::NoBrush );
\r
42 this->setZValue( -1 );
\r
47 // -------------------------------------------------------------------------
\r
48 PipelineEditor::QNEConnection::
\r
51 if ( this->m_Port1 )
\r
52 this->m_Port1->connections( ).remove(
\r
53 this->m_Port1->connections( ).indexOf( this )
\r
55 if ( this->m_Port2 )
\r
56 this->m_Port2->connections( ).remove(
\r
57 this->m_Port2->connections( ).indexOf( this )
\r
61 // -------------------------------------------------------------------------
\r
62 void PipelineEditor::QNEConnection::
\r
63 setPos1( const QPointF& p )
\r
68 // -------------------------------------------------------------------------
\r
69 void PipelineEditor::QNEConnection::
\r
70 setPos2( const QPointF& p )
\r
75 // -------------------------------------------------------------------------
\r
76 void PipelineEditor::QNEConnection::
\r
77 setPort1( QNEPort* p )
\r
80 this->m_Port1->connections( ).append( this );
\r
83 // -------------------------------------------------------------------------
\r
84 void PipelineEditor::QNEConnection::
\r
85 setPort2( QNEPort* p )
\r
88 this->m_Port2->connections( ).append( this );
\r
91 // -------------------------------------------------------------------------
\r
92 void PipelineEditor::QNEConnection::
\r
93 updatePosFromPorts( )
\r
95 this->m_Pos1 = this->m_Port1->scenePos( );
\r
96 this->m_Pos2 = this->m_Port2->scenePos( );
\r
99 // -------------------------------------------------------------------------
\r
100 void PipelineEditor::QNEConnection::
\r
105 p.moveTo( this->m_Pos1 );
\r
107 qreal dx = this->m_Pos2.x( ) - this->m_Pos1.x( );
\r
108 qreal dy = this->m_Pos2.y( ) - this->m_Pos1.y( );
\r
110 QPointF ctr1( this->m_Pos1.x( ) + dx * 0.25, this->m_Pos1.y( ) + dy * 0.1 );
\r
111 QPointF ctr2( this->m_Pos1.x( ) + dx * 0.75, this->m_Pos1.y( ) + dy * 0.9 );
\r
113 p.cubicTo( ctr1, ctr2, this->m_Pos2 );
\r
115 this->setPath( p );
\r
118 // -------------------------------------------------------------------------
\r
119 PipelineEditor::QNEPort* PipelineEditor::QNEConnection::
\r
122 return( this->m_Port1 );
\r
125 // -------------------------------------------------------------------------
\r
126 PipelineEditor::QNEPort* PipelineEditor::QNEConnection::
\r
129 return( this->m_Port2 );
\r