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
29 #include <QGraphicsScene>
\r
30 #include <QFontMetrics>
\r
33 #include "QNEConnection.h"
\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
46 -this->m_Radius, -this->m_Radius,
\r
47 2 * this->m_Radius, 2 * this->m_Radius
\r
51 this->setPen( QPen( Qt::darkRed ) );
\r
52 this->setBrush( Qt::red );
\r
53 this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges );
\r
54 this->m_PortFlags = 0;
\r
57 // -------------------------------------------------------------------------
\r
58 PipelineEditor::QNEPort::
\r
61 foreach( QNEConnection* conn, this->m_Connections )
\r
65 // -------------------------------------------------------------------------
\r
66 void PipelineEditor::QNEPort::
\r
67 setNEBlock( QNEBlock *b )
\r
72 // -------------------------------------------------------------------------
\r
73 void PipelineEditor::QNEPort::
\r
74 setName( const QString &n )
\r
77 this->m_Label->setPlainText( n );
\r
80 // -------------------------------------------------------------------------
\r
81 void PipelineEditor::QNEPort::
\r
82 setIsOutput( bool o )
\r
84 this->m_IsOutput = o;
\r
86 QFontMetrics fm( this->scene( )->font( ) );
\r
87 QRect r = fm.boundingRect( this->m_Name );
\r
89 int rm = this->m_Radius + this->m_Margin;
\r
90 int h = -this->m_Label->boundingRect( ).height( ) / 2;
\r
91 if( this->m_IsOutput )
\r
92 this->m_Label->setPos(
\r
93 -rm - this->m_Label->boundingRect( ).width( ), h
\r
96 this->m_Label->setPos( rm, h );
\r
99 // -------------------------------------------------------------------------
\r
100 int PipelineEditor::QNEPort::
\r
103 return( this->m_Radius );
\r
106 // -------------------------------------------------------------------------
\r
107 bool PipelineEditor::QNEPort::
\r
110 return( this->m_IsOutput );
\r
113 // -------------------------------------------------------------------------
\r
114 QVector< PipelineEditor::QNEConnection* >& PipelineEditor::QNEPort::
\r
117 return( this->m_Connections );
\r
120 // -------------------------------------------------------------------------
\r
121 void PipelineEditor::QNEPort::
\r
122 setPortFlags( int f )
\r
124 this->m_PortFlags = f;
\r
126 if( this->m_PortFlags & Self::TypePort )
\r
128 QFont font( this->scene( )->font( ) );
\r
129 font.setItalic( true );
\r
130 this->m_Label->setFont( font );
\r
131 this->setPath( QPainterPath( ) );
\r
133 else if( this->m_PortFlags & Self::NamePort )
\r
135 QFont font( this->scene( )->font( ) );
\r
136 font.setBold( true );
\r
137 this->m_Label->setFont( font );
\r
138 this->setPath( QPainterPath( ) );
\r
143 // -------------------------------------------------------------------------
\r
144 PipelineEditor::QNEBlock* PipelineEditor::QNEPort::
\r
147 return( this->m_Block );
\r
150 // -------------------------------------------------------------------------
\r
151 quint64 PipelineEditor::QNEPort::
\r
154 return( this->m_Ptr );
\r
157 // -------------------------------------------------------------------------
\r
158 void PipelineEditor::QNEPort::
\r
159 setPtr( quint64 p )
\r
164 // -------------------------------------------------------------------------
\r
165 bool PipelineEditor::QNEPort::
\r
166 isConnected( QNEPort* other )
\r
168 foreach( QNEConnection* conn, this->m_Connections )
\r
169 if( conn->port1( ) == other || conn->port2( ) == other )
\r
174 // -------------------------------------------------------------------------
\r
175 QVariant PipelineEditor::QNEPort::
\r
176 itemChange( GraphicsItemChange change, const QVariant& value )
\r
178 if( change == ItemScenePositionHasChanged )
\r
180 foreach( QNEConnection* conn, this->m_Connections )
\r
182 conn->updatePosFromPorts( );
\r
183 conn->updatePath( );
\r