OpenWalnut
1.5.0dev
|
This Class is needed for connecting two ports and drawing a line between them. More...
#include <WQtNetworkArrow.h>
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... | |
WQtNetworkOutputPort * | getStartPort () |
Returns the WQtNetworkOutputPort where the arrow starts. More... | |
WQtNetworkInputPort * | getEndPort () |
Returns the WQtNetworkInputPort where the arrow ends. More... | |
WQtNetworkInputPort * | findNearestCompatibleInput (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 | |
WQtNetworkOutputPort * | m_startPort |
the start port More... | |
WQtNetworkInputPort * | m_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... | |
WQtNetworkInputPort * | m_connectTo |
connect to this port after mouse release. More... | |
This Class is needed for connecting two ports and drawing a line between them.
Definition at line 48 of file WQtNetworkArrow.h.
anonymous enum |
This customize the return value of type()
Definition at line 54 of file WQtNetworkArrow.h.
|
explicit |
Constructor.
outPort | the outputport that provide the data |
inPort | the inputport that recive the data |
Definition at line 49 of file WQtNetworkArrow.cpp.
References m_endPort, and m_startPort.
WQtNetworkArrow::~WQtNetworkArrow | ( | ) |
Destructor.
Definition at line 61 of file WQtNetworkArrow.cpp.
References m_endPort, m_startPort, and WQtNetworkPort::removeArrow().
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.
Definition at line 192 of file WQtNetworkArrow.cpp.
References shape().
|
private |
This method changes the color of the arrow.
color | the choosen color |
Definition at line 225 of file WQtNetworkArrow.cpp.
References m_color.
Referenced by doneDrag(), hoverEnterEvent(), hoverLeaveEvent(), itemChange(), moveDrag(), and startDrag().
|
private |
Change color and width of the arrow.
color | the color |
penWidth | the new width. |
Definition at line 231 of file WQtNetworkArrow.cpp.
References m_color.
void WQtNetworkArrow::doneDrag | ( | const QPointF & | pos | ) |
Called when releasing the mouse.
pos | the 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().
WQtNetworkInputPort * WQtNetworkArrow::findNearestCompatibleInput | ( | QPointF | pos, |
float | maxDistance = 100 |
||
) |
Search the next, compatible input port.
pos | the current position for which to search |
maxDistance | the maximum distance |
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().
WQtNetworkInputPort * WQtNetworkArrow::getEndPort | ( | ) |
Returns the WQtNetworkInputPort where the arrow ends.
Definition at line 159 of file WQtNetworkArrow.cpp.
References m_endPort.
Referenced by WQtNetworkEditor::event(), and mouseDoubleClickEvent().
WQtNetworkOutputPort * WQtNetworkArrow::getStartPort | ( | ) |
Returns the WQtNetworkOutputPort where the arrow starts.
Definition at line 154 of file WQtNetworkArrow.cpp.
References m_startPort.
Referenced by WQtNetworkEditor::event(), and mouseDoubleClickEvent().
|
protected |
If the cursor enters the arrow, the arrow becomes geen.
event | the hover event |
Definition at line 211 of file WQtNetworkArrow.cpp.
References changeColor().
|
protected |
If the cursor leaves the arrow, the arrow gets his default color.
event | the hover event |
Definition at line 218 of file WQtNetworkArrow.cpp.
References changeColor().
QVariant WQtNetworkArrow::itemChange | ( | GraphicsItemChange | change, |
const QVariant & | value | ||
) |
If the item is changed we want to get notified.
change | |
value |
Definition at line 164 of file WQtNetworkArrow.cpp.
References changeColor().
|
protected |
Double click on port.
mouseEvent | the event |
Definition at line 237 of file WQtNetworkArrow.cpp.
References WQtNetworkOutputPort::getConnector(), getEndPort(), and getStartPort().
|
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.
mouseEvent | the mouse event |
Definition at line 367 of file WQtNetworkArrow.cpp.
References moveDrag().
|
protected |
Start drawing an arrow temporary.
mouseEvent | the mouse event |
Definition at line 355 of file WQtNetworkArrow.cpp.
References startDrag().
|
protected |
Send a connect request to kernel when start- and endport are connectable.
mouseEvent | the mouse event |
Definition at line 373 of file WQtNetworkArrow.cpp.
References doneDrag().
void WQtNetworkArrow::moveDrag | ( | const QPointF & | pos | ) |
Update drag position.
pos | the 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().
|
protected |
Draw some customized stuff in the scene.
painter | |
option | |
w |
Definition at line 174 of file WQtNetworkArrow.cpp.
References m_arrowHead, m_color, and m_line.
QPainterPath WQtNetworkArrow::shape | ( | ) | const |
Reimplementation from QGraphicsItem.
Return the shape of this item as a QPainterPath in local coordinates
Definition at line 204 of file WQtNetworkArrow.cpp.
References m_arrowHead.
Referenced by boundingRect().
void WQtNetworkArrow::startDrag | ( | const QPointF & | pos | ) |
Start Drag.
pos | the 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().
int WQtNetworkArrow::type | ( | ) | const |
Reimplementation from QGraphicsItem.
Definition at line 70 of file WQtNetworkArrow.cpp.
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.
deviate | pull 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().
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.
deviate | pull the line into this direction. |
targetPoint | the point where to point to. |
Definition at line 127 of file WQtNetworkArrow.cpp.
References m_line, and m_startPort.
|
private |
|
private |
position where the click event was created.
Definition at line 242 of file WQtNetworkArrow.h.
Referenced by moveDrag(), and startDrag().
|
private |
the current color
Definition at line 236 of file WQtNetworkArrow.h.
Referenced by changeColor(), and paint().
|
private |
disconnect if true.
Definition at line 246 of file WQtNetworkArrow.h.
Referenced by doneDrag(), moveDrag(), and startDrag().
|
private |
connect to this port after mouse release.
Definition at line 248 of file WQtNetworkArrow.h.
Referenced by doneDrag(), moveDrag(), and startDrag().
|
private |
the end port
Definition at line 234 of file WQtNetworkArrow.h.
Referenced by doneDrag(), getEndPort(), moveDrag(), updatePosition(), WQtNetworkArrow(), and ~WQtNetworkArrow().
|
private |
the line representing the arrow
Definition at line 240 of file WQtNetworkArrow.h.
Referenced by paint(), and updatePosition().
|
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().
|
private |
the start port
Definition at line 232 of file WQtNetworkArrow.h.
Referenced by doneDrag(), findNearestCompatibleInput(), getStartPort(), updatePosition(), WQtNetworkArrow(), and ~WQtNetworkArrow().