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
53 this->m_PortFlags = 0;
\r
56 // -------------------------------------------------------------------------
\r
57 PipelineEditor::QNEPort::
\r
60 foreach( QNEConnection* conn, this->m_Connections )
\r
64 // -------------------------------------------------------------------------
\r
65 void PipelineEditor::QNEPort::
\r
66 setNEBlock( QNEBlock *b )
\r
71 // -------------------------------------------------------------------------
\r
72 void PipelineEditor::QNEPort::
\r
73 setName( const QString &n )
\r
76 this->m_Label->setPlainText( n );
\r
79 // -------------------------------------------------------------------------
\r
80 void PipelineEditor::QNEPort::
\r
81 setIsOutput( bool o )
\r
83 this->m_IsOutput = o;
\r
85 QFontMetrics fm( this->scene( )->font( ) );
\r
86 QRect r = fm.boundingRect( this->m_Name );
\r
88 int rm = this->m_Radius + this->m_Margin;
\r
89 int h = -this->m_Label->boundingRect( ).height( ) / 2;
\r
90 if( this->m_IsOutput )
\r
91 this->m_Label->setPos(
\r
92 -rm - this->m_Label->boundingRect( ).width( ), h
\r
95 this->m_Label->setPos( rm, h );
\r
98 // -------------------------------------------------------------------------
\r
99 int PipelineEditor::QNEPort::
\r
102 return( this->m_Radius );
\r
105 // -------------------------------------------------------------------------
\r
106 bool PipelineEditor::QNEPort::
\r
109 return( this->m_IsOutput );
\r
112 // -------------------------------------------------------------------------
\r
113 QVector< PipelineEditor::QNEConnection* >& PipelineEditor::QNEPort::
\r
116 return( this->m_Connections );
\r
119 // -------------------------------------------------------------------------
\r
120 void PipelineEditor::QNEPort::
\r
121 setPortFlags( int f )
\r
123 this->m_PortFlags = f;
\r
125 if( this->m_PortFlags & Self::TypePort )
\r
127 QFont font( this->scene( )->font( ) );
\r
128 font.setItalic( true );
\r
129 this->m_Label->setFont( font );
\r
130 this->setPath( QPainterPath( ) );
\r
132 else if( this->m_PortFlags & Self::NamePort )
\r
134 QFont font( this->scene( )->font( ) );
\r
135 font.setBold( true );
\r
136 this->m_Label->setFont( font );
\r
137 this->setPath( QPainterPath( ) );
\r
142 // -------------------------------------------------------------------------
\r
143 PipelineEditor::QNEBlock* PipelineEditor::QNEPort::
\r
146 return( this->m_Block );
\r
149 // -------------------------------------------------------------------------
\r
150 quint64 PipelineEditor::QNEPort::
\r
153 return( this->m_Ptr );
\r
156 // -------------------------------------------------------------------------
\r
157 void PipelineEditor::QNEPort::
\r
158 setPtr( quint64 p )
\r
163 // -------------------------------------------------------------------------
\r
164 bool PipelineEditor::QNEPort::
\r
165 isConnected( QNEPort* other )
\r
167 foreach( QNEConnection* conn, this->m_Connections )
\r
168 if( conn->port1( ) == other || conn->port2( ) == other )
\r
173 // -------------------------------------------------------------------------
\r
174 QVariant PipelineEditor::QNEPort::
\r
175 itemChange( GraphicsItemChange change, const QVariant& value )
\r
177 if( change == ItemScenePositionHasChanged )
\r
179 foreach( QNEConnection* conn, this->m_Connections )
\r
181 conn->updatePosFromPorts( );
\r
182 conn->updatePath( );
\r