27 #include <QGraphicsSceneMouseEvent>
29 #include "WQtNetworkColors.h"
30 #include "WQtNetworkEditorGlobals.h"
31 #include "WQtNetworkInputPort.h"
32 #include "WQtNetworkOutputPort.h"
33 #include "WQtNetworkPort.h"
34 #include "core/kernel/combiner/WApplyCombiner.h"
36 WQtNetworkPort::WQtNetworkPort():
39 setRect( 0.0, 0.0, WNETWORKPORT_SIZEX, WNETWORKPORT_SIZEY );
40 setPen( QPen( Qt::black, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
43 setAcceptHoverEvents(
true );
47 WQtNetworkPort::~WQtNetworkPort()
60 setBrush( WQtNetworkColors::OutputConnector );
64 setBrush( WQtNetworkColors::InputConnector );
68 QGraphicsRectItem::paint( painter, option, widget );
82 QGraphicsItem::mouseDoubleClickEvent( mouseEvent );
85 if( mouseEvent->button() != Qt::LeftButton )
92 if( !startItem.isEmpty() )
109 mouseEvent->ignore();
115 if( mouseEvent->button() != Qt::LeftButton )
117 mouseEvent->ignore();
121 if( !startItem.isEmpty() )
123 mouseEvent->accept();
124 if( startItem.first()->type() == WQtNetworkOutputPort::Type &&
125 startItem.first()->parentItem()->isEnabled() ==
true )
135 mouseEvent->ignore();
149 Q_UNUSED( mouseEvent );
154 scene()->removeItem(
m_arrow );
161 if( outPort ==
false )
163 setPos( rect.width() / ( size + 1 ) * portNumber - 5.0, -this->rect().height() / 2 + 3 );
165 else if( outPort ==
true )
167 setPos( rect.width() / ( size + 1 ) * portNumber - 5.0, rect.height() - this->rect().height() / 2 - 3 );
173 return ( 5 + WNETWORKPORT_SIZEX ) * nbPorts;
178 int index =
m_arrows.indexOf( arrow );
190 int index =
m_arrows.indexOf( arrow );
This Class is needed for connecting two ports and drawing a line between them.
void updatePosition(QPointF deviate=QPointF())
Calculated the new position of the lines endpoints in the scene.
void doneDrag(const QPointF &pos)
Called when releasing the mouse.
void moveDrag(const QPointF &pos)
Update drag position.
void startDrag(const QPointF &pos)
Start Drag.
This class represents the ports a module have.
std::shared_ptr< WModuleOutputConnector > getConnector()
Returns the WModuleOutputConnecter that belongs to this object.
void alignPosition(int size, int portNumber, QRectF rect, bool outPort)
Calculates the position inside a item for each port to get a correct alignment.
static float getMultiplePortWidth(size_t nbPorts)
Calculates the spaced needed for the given amount of ports.
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
Updates the temporary arrows endpoint.
virtual void removeArrow(WQtNetworkArrow *arrow)
Removes a specific arrow.
WQtNetworkArrow * m_arrow
The arrow used to connect items.
QList< WQtNetworkArrow * > m_arrows
the connected arrows
QString m_name
the portname
virtual void updateArrows()
The position of every arrow connected with this port is updating its position in the scene.
virtual void removeArrows()
Removes all connected arrows.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
Send a connect request to kernel when start- and endport are connectable.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
Double click on port.
bool m_isOutPort
is the port an outport
virtual void setOutPort(bool type)
Set the type of the port.
virtual bool isOutPort()
Returns the porttype - true if outputport, false if inputport.
bool m_brushNotSet
used to indicate that the correct brush was not yet set.
virtual QString getPortName()
Returns the portname.
virtual void setPortName(QString str)
Set the Name.
virtual int type() const =0
Reimplementation from QGraphicsItem.
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
Start drawing an arrow temporary.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Actually paints the port.
virtual QList< WQtNetworkArrow * > getArrowList()
Get a QList of all arrows connected to this port.
virtual void addArrow(WQtNetworkArrow *arrow)
Adds an arrow to the port.
virtual int getNumberOfArrows()
Return the number of connections.