OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
WQtNetworkArrow Class Reference

This Class is needed for connecting two ports and drawing a line between them. More...

#include <WQtNetworkArrow.h>

+ Inheritance diagram for WQtNetworkArrow:
+ Collaboration diagram for WQtNetworkArrow:

Public Types

enum  { Type = UserType + 4 }
 This customize the return value of type() More...
 

Public Member Functions

 WQtNetworkArrow (WQtNetworkOutputPort *outPort, WQtNetworkInputPort *inPort)
 Constructor. More...
 
 ~WQtNetworkArrow ()
 Destructor. More...
 
int type () const
 Reimplementation from QGraphicsItem. More...
 
void updatePosition (QPointF deviate=QPointF())
 Calculated the new position of the lines endpoints in the scene. More...
 
void updatePosition (QPointF targetPoint, QPointF deviate)
 Calculated the new position of the lines endpoints in the scene. More...
 
WQtNetworkOutputPortgetStartPort ()
 Returns the WQtNetworkOutputPort where the arrow starts. More...
 
WQtNetworkInputPortgetEndPort ()
 Returns the WQtNetworkInputPort where the arrow ends. More...
 
WQtNetworkInputPortfindNearestCompatibleInput (QPointF pos, float maxDistance=100)
 Search the next, compatible input port. More...
 
QRectF boundingRect () const
 Reimplementation form QGraphicsItem, because the arrowhead is added to the line. More...
 
QPainterPath shape () const
 Reimplementation from QGraphicsItem. More...
 
QVariant itemChange (GraphicsItemChange change, const QVariant &value)
 If the item is changed we want to get notified. More...
 
void startDrag (const QPointF &pos)
 Start Drag. More...
 
void moveDrag (const QPointF &pos)
 Update drag position. More...
 
void doneDrag (const QPointF &pos)
 Called when releasing the mouse. More...
 

Protected Member Functions

void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w)
 Draw some customized stuff in the scene. More...
 
void hoverEnterEvent (QGraphicsSceneHoverEvent *event)
 If the cursor enters the arrow, the arrow becomes geen. More...
 
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
 If the cursor leaves the arrow, the arrow gets his default color. More...
 
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *mouseEvent)
 Double click on port. More...
 
void mousePressEvent (QGraphicsSceneMouseEvent *mouseEvent)
 Start drawing an arrow temporary. More...
 
void mouseMoveEvent (QGraphicsSceneMouseEvent *mouseEvent)
 Updates the temporary arrows endpoint. More...
 
void mouseReleaseEvent (QGraphicsSceneMouseEvent *mouseEvent)
 Send a connect request to kernel when start- and endport are connectable. More...
 

Private Member Functions

void changeColor (QColor color)
 This method changes the color of the arrow. More...
 
void changeColor (QColor color, float penWidth)
 Change color and width of the arrow. More...
 

Private Attributes

WQtNetworkOutputPortm_startPort
 the start port More...
 
WQtNetworkInputPortm_endPort
 the end port More...
 
QColor m_color
 the current color More...
 
QPolygonF m_arrowHead
 the arrowhead More...
 
QLineF m_line
 the line representing the arrow More...
 
QPointF m_clickPoint
 position where the click event was created. More...
 
bool m_snappedOff
 gets true once the arrow was pulled far away from original click position. More...
 
bool m_connectionDisconnect
 disconnect if true. More...
 
WQtNetworkInputPortm_connectTo
 connect to this port after mouse release. More...
 

Detailed Description

This Class is needed for connecting two ports and drawing a line between them.

Definition at line 48 of file WQtNetworkArrow.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

This customize the return value of type()

Definition at line 54 of file WQtNetworkArrow.h.

Constructor & Destructor Documentation

◆ WQtNetworkArrow()

WQtNetworkArrow::WQtNetworkArrow ( WQtNetworkOutputPort outPort,
WQtNetworkInputPort inPort 
)
explicit

Constructor.

Parameters
outPortthe outputport that provide the data
inPortthe inputport that recive the data

Definition at line 49 of file WQtNetworkArrow.cpp.

References m_endPort, and m_startPort.

◆ ~WQtNetworkArrow()

WQtNetworkArrow::~WQtNetworkArrow ( )

Destructor.

Definition at line 61 of file WQtNetworkArrow.cpp.

References m_endPort, m_startPort, and WQtNetworkPort::removeArrow().

+ Here is the call graph for this function:

Member Function Documentation

◆ boundingRect()

QRectF WQtNetworkArrow::boundingRect ( ) const

Reimplementation form QGraphicsItem, because the arrowhead is added to the line.

Its needed that QGraphicsView knows which area needs to be redrawn.

Returns
a QRectF that bounds the drawn object

Definition at line 192 of file WQtNetworkArrow.cpp.

References shape().

+ Here is the call graph for this function:

◆ changeColor() [1/2]

void WQtNetworkArrow::changeColor ( QColor  color)
private

This method changes the color of the arrow.

Parameters
colorthe choosen color

Definition at line 225 of file WQtNetworkArrow.cpp.

References m_color.

Referenced by doneDrag(), hoverEnterEvent(), hoverLeaveEvent(), itemChange(), moveDrag(), and startDrag().

+ Here is the caller graph for this function:

◆ changeColor() [2/2]

void WQtNetworkArrow::changeColor ( QColor  color,
float  penWidth 
)
private

Change color and width of the arrow.

Parameters
colorthe color
penWidththe new width.

Definition at line 231 of file WQtNetworkArrow.cpp.

References m_color.

◆ doneDrag()

void WQtNetworkArrow::doneDrag ( const QPointF &  pos)

Called when releasing the mouse.

Parameters
posthe position in scene

Definition at line 313 of file WQtNetworkArrow.cpp.

References changeColor(), WQtNetworkInputPort::getConnector(), WQtNetworkOutputPort::getConnector(), m_connectionDisconnect, m_connectTo, m_endPort, m_startPort, and updatePosition().

Referenced by mouseReleaseEvent(), and WQtNetworkPort::mouseReleaseEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findNearestCompatibleInput()

WQtNetworkInputPort * WQtNetworkArrow::findNearestCompatibleInput ( QPointF  pos,
float  maxDistance = 100 
)

Search the next, compatible input port.

Parameters
posthe current position for which to search
maxDistancethe maximum distance
Returns
the connector, or NULL if none.

Definition at line 75 of file WQtNetworkArrow.cpp.

References WQtNetworkInputPort::getConnector(), WQtNetworkOutputPort::getConnector(), WQtGui::getMainWindow(), WMainWindow::getNetworkEditor(), WQtNetworkEditor::getScene(), and m_startPort.

Referenced by moveDrag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getEndPort()

WQtNetworkInputPort * WQtNetworkArrow::getEndPort ( )

Returns the WQtNetworkInputPort where the arrow ends.

Returns
the WQtNetworkInputPort where the connection ends

Definition at line 159 of file WQtNetworkArrow.cpp.

References m_endPort.

Referenced by WQtNetworkEditor::event(), and mouseDoubleClickEvent().

+ Here is the caller graph for this function:

◆ getStartPort()

WQtNetworkOutputPort * WQtNetworkArrow::getStartPort ( )

Returns the WQtNetworkOutputPort where the arrow starts.

Returns
the WQtNetworkInputPort where the connection starts

Definition at line 154 of file WQtNetworkArrow.cpp.

References m_startPort.

Referenced by WQtNetworkEditor::event(), and mouseDoubleClickEvent().

+ Here is the caller graph for this function:

◆ hoverEnterEvent()

void WQtNetworkArrow::hoverEnterEvent ( QGraphicsSceneHoverEvent *  event)
protected

If the cursor enters the arrow, the arrow becomes geen.

Parameters
eventthe hover event

Definition at line 211 of file WQtNetworkArrow.cpp.

References changeColor().

+ Here is the call graph for this function:

◆ hoverLeaveEvent()

void WQtNetworkArrow::hoverLeaveEvent ( QGraphicsSceneHoverEvent *  event)
protected

If the cursor leaves the arrow, the arrow gets his default color.

Parameters
eventthe hover event

Definition at line 218 of file WQtNetworkArrow.cpp.

References changeColor().

+ Here is the call graph for this function:

◆ itemChange()

QVariant WQtNetworkArrow::itemChange ( GraphicsItemChange  change,
const QVariant &  value 
)

If the item is changed we want to get notified.

Parameters
change
value
Returns

Definition at line 164 of file WQtNetworkArrow.cpp.

References changeColor().

+ Here is the call graph for this function:

◆ mouseDoubleClickEvent()

void WQtNetworkArrow::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent *  mouseEvent)
protected

Double click on port.

Parameters
mouseEventthe event

Definition at line 237 of file WQtNetworkArrow.cpp.

References WQtNetworkOutputPort::getConnector(), getEndPort(), and getStartPort().

+ Here is the call graph for this function:

◆ mouseMoveEvent()

void WQtNetworkArrow::mouseMoveEvent ( QGraphicsSceneMouseEvent *  mouseEvent)
protected

Updates the temporary arrows endpoint.

Arrow is colored green when connection possible, red if no connection is possible, or black when cursor doesent covers an WQtNetworkPort.

Parameters
mouseEventthe mouse event

Definition at line 367 of file WQtNetworkArrow.cpp.

References moveDrag().

+ Here is the call graph for this function:

◆ mousePressEvent()

void WQtNetworkArrow::mousePressEvent ( QGraphicsSceneMouseEvent *  mouseEvent)
protected

Start drawing an arrow temporary.

Parameters
mouseEventthe mouse event

Definition at line 355 of file WQtNetworkArrow.cpp.

References startDrag().

+ Here is the call graph for this function:

◆ mouseReleaseEvent()

void WQtNetworkArrow::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  mouseEvent)
protected

Send a connect request to kernel when start- and endport are connectable.

Parameters
mouseEventthe mouse event

Definition at line 373 of file WQtNetworkArrow.cpp.

References doneDrag().

+ Here is the call graph for this function:

◆ moveDrag()

void WQtNetworkArrow::moveDrag ( const QPointF &  pos)

Update drag position.

Parameters
posthe position in scene

Definition at line 273 of file WQtNetworkArrow.cpp.

References changeColor(), findNearestCompatibleInput(), m_clickPoint, m_connectionDisconnect, m_connectTo, m_endPort, m_snappedOff, and updatePosition().

Referenced by mouseMoveEvent(), and WQtNetworkPort::mouseMoveEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ paint()

void WQtNetworkArrow::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  w 
)
protected

Draw some customized stuff in the scene.

Parameters
painter
option
w

Definition at line 174 of file WQtNetworkArrow.cpp.

References m_arrowHead, m_color, and m_line.

◆ shape()

QPainterPath WQtNetworkArrow::shape ( ) const

Reimplementation from QGraphicsItem.

Return the shape of this item as a QPainterPath in local coordinates

Returns
shape as QPainterPath of this object

Definition at line 204 of file WQtNetworkArrow.cpp.

References m_arrowHead.

Referenced by boundingRect().

+ Here is the caller graph for this function:

◆ startDrag()

void WQtNetworkArrow::startDrag ( const QPointF &  pos)

Start Drag.

Parameters
posthe position in scene

Definition at line 260 of file WQtNetworkArrow.cpp.

References changeColor(), m_clickPoint, m_connectionDisconnect, m_connectTo, and m_snappedOff.

Referenced by mousePressEvent(), and WQtNetworkPort::mousePressEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ type()

int WQtNetworkArrow::type ( ) const

Reimplementation from QGraphicsItem.

Returns
the type of the item as int

Definition at line 70 of file WQtNetworkArrow.cpp.

◆ updatePosition() [1/2]

void WQtNetworkArrow::updatePosition ( QPointF  deviate = QPointF())

Calculated the new position of the lines endpoints in the scene.

Is called everytime the parentItem is changed or after construction.

Parameters
deviatepull the line into this direction.

Definition at line 122 of file WQtNetworkArrow.cpp.

References m_endPort, and m_startPort.

Referenced by doneDrag(), WQtNetworkEditor::event(), moveDrag(), and WQtNetworkPort::updateArrows().

+ Here is the caller graph for this function:

◆ updatePosition() [2/2]

void WQtNetworkArrow::updatePosition ( QPointF  targetPoint,
QPointF  deviate 
)

Calculated the new position of the lines endpoints in the scene.

Is called everytime the parentItem is changed or after construction.

Parameters
deviatepull the line into this direction.
targetPointthe point where to point to.

Definition at line 127 of file WQtNetworkArrow.cpp.

References m_line, and m_startPort.

Member Data Documentation

◆ m_arrowHead

QPolygonF WQtNetworkArrow::m_arrowHead
private

the arrowhead

Definition at line 238 of file WQtNetworkArrow.h.

Referenced by paint(), and shape().

◆ m_clickPoint

QPointF WQtNetworkArrow::m_clickPoint
private

position where the click event was created.

Definition at line 242 of file WQtNetworkArrow.h.

Referenced by moveDrag(), and startDrag().

◆ m_color

QColor WQtNetworkArrow::m_color
private

the current color

Definition at line 236 of file WQtNetworkArrow.h.

Referenced by changeColor(), and paint().

◆ m_connectionDisconnect

bool WQtNetworkArrow::m_connectionDisconnect
private

disconnect if true.

Definition at line 246 of file WQtNetworkArrow.h.

Referenced by doneDrag(), moveDrag(), and startDrag().

◆ m_connectTo

WQtNetworkInputPort* WQtNetworkArrow::m_connectTo
private

connect to this port after mouse release.

Definition at line 248 of file WQtNetworkArrow.h.

Referenced by doneDrag(), moveDrag(), and startDrag().

◆ m_endPort

WQtNetworkInputPort* WQtNetworkArrow::m_endPort
private

the end port

Definition at line 234 of file WQtNetworkArrow.h.

Referenced by doneDrag(), getEndPort(), moveDrag(), updatePosition(), WQtNetworkArrow(), and ~WQtNetworkArrow().

◆ m_line

QLineF WQtNetworkArrow::m_line
private

the line representing the arrow

Definition at line 240 of file WQtNetworkArrow.h.

Referenced by paint(), and updatePosition().

◆ m_snappedOff

bool WQtNetworkArrow::m_snappedOff
private

gets true once the arrow was pulled far away from original click position.

Definition at line 244 of file WQtNetworkArrow.h.

Referenced by moveDrag(), and startDrag().

◆ m_startPort

WQtNetworkOutputPort* WQtNetworkArrow::m_startPort
private

The documentation for this class was generated from the following files: