32 #include <QGraphicsLineItem>
33 #include <QGraphicsPathItem>
34 #include <QPainterPath>
35 #include <QStyleOptionGraphicsItem>
37 #include "../WMainWindow.h"
38 #include "../WQtGui.h"
39 #include "WQtNetworkArrow.h"
40 #include "WQtNetworkEditor.h"
41 #include "WQtNetworkInputPort.h"
42 #include "WQtNetworkOutputPort.h"
43 #include "WQtNetworkScene.h"
44 #include "core/kernel/combiner/WApplyCombiner.h"
46 const QColor owRed( 248, 87, 87 );
47 const QColor owGreen( 115, 225, 115 );
55 setFlag( QGraphicsItem::ItemIsSelectable,
true );
56 setPen( QPen( Qt::black, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
58 setAcceptHoverEvents(
true );
81 static_cast< qreal
>( pos.y() - ( maxDistance / 2.0 ) ),
82 static_cast< qreal
>( maxDistance ),
83 static_cast< qreal
>( maxDistance ),
84 Qt::IntersectsItemShape,
89 float nearestDist = maxDistance;
90 for(
int i = 0; i < items.size(); ++i )
108 QPointF conPos = mapFromItem( con, con->rect().bottomRight() * 0.5 );
109 QPointF vec = pos - conPos;
110 float dist = sqrt( ( vec.x() * vec.x() ) + ( vec.y() * vec.y() ) );
112 if( nearestDist >= dist )
130 QLineF tmpLine( mapFromItem(
m_startPort, sRect.bottomRight() * 0.5 ),
133 m_line = QLineF( tmpLine.x1(), tmpLine.y1()+5, tmpLine.x2(), tmpLine.y2()-5 );
135 QPainterPath path(
m_line.p1() );
139 double dx = std::abs(
m_line.dx() );
140 double dy = std::abs(
m_line.dy() );
141 double minCDist = 50.0;
142 double maxCDist = 250.0;
144 dy = std::min( maxCDist, std::max( minCDist, std::max( dx * 0.5, dy ) * 0.5 ) );
146 QPointF c1(
m_line.p1() + QPointF( 0, +dy ) );
147 QPointF c2(
m_line.p2() + QPointF( 0, -dy ) );
150 path.cubicTo( c1, c2 + deviate,
m_line.p2() );
165 const QVariant &value )
167 if( change == QGraphicsItem::ItemSelectedHasChanged )
176 QStyleOptionGraphicsItem *o =
const_cast<QStyleOptionGraphicsItem*
>( option );
177 o->state &= ~QStyle::State_Selected;
179 QGraphicsPathItem::paint( painter, o, w );
181 qreal arrowSize = 10;
182 QPointF arrowP1 =
m_line.p2() + QPointF( 0.5 * arrowSize, -arrowSize );
183 QPointF arrowP2 =
m_line.p2() + QPointF( -0.5 * arrowSize, -arrowSize );
187 painter->setPen( QPen(
m_color, 1, Qt::SolidLine ) );
194 QRectF rect =
shape().boundingRect();
198 qreal extra = ( penWidth + 10 ) / 2.0;
199 rect.adjust( -extra, -extra, extra, extra );
206 QPainterPath path = QGraphicsPathItem::shape();
228 setPen( QPen(
m_color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
234 setPen( QPen(
m_color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
239 QGraphicsItem::mouseDoubleClickEvent( mouseEvent );
242 if( mouseEvent->button() != Qt::LeftButton )
244 mouseEvent->ignore();
249 if( !startItem.isEmpty() )
251 mouseEvent->accept();
256 mouseEvent->ignore();
278 QPointF currentPoint = pos;
282 float l = sqrt( ( deviate.x() * deviate.x() ) + ( deviate.y() * deviate.y() ) );
298 updatePosition( mapFromItem( nearestPort, nearestPort->rect().bottomRight() * 0.5 ), QPointF() );
357 if( mouseEvent->button() != Qt::LeftButton )
359 mouseEvent->ignore();
362 mouseEvent->accept();
369 mouseEvent->accept();
375 if( mouseEvent->button() != Qt::LeftButton )
377 mouseEvent->ignore();
380 mouseEvent->accept();
Base class for all combiners which apply one connection between two connectors of two modules.
WQtNetworkEditor * getNetworkEditor()
Returns a pointer to the network editor object.
static WMainWindow * getMainWindow()
Returns the current main window instance or NULL if not existent.
WQtNetworkInputPort * getEndPort()
Returns the WQtNetworkInputPort where the arrow ends.
void updatePosition(QPointF deviate=QPointF())
Calculated the new position of the lines endpoints in the scene.
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
If the cursor enters the arrow, the arrow becomes geen.
WQtNetworkArrow(WQtNetworkOutputPort *outPort, WQtNetworkInputPort *inPort)
Constructor.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
Double click on port.
void changeColor(QColor color)
This method changes the color of the arrow.
bool m_snappedOff
gets true once the arrow was pulled far away from original click position.
WQtNetworkInputPort * m_endPort
the end port
~WQtNetworkArrow()
Destructor.
WQtNetworkOutputPort * getStartPort()
Returns the WQtNetworkOutputPort where the arrow starts.
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
Start drawing an arrow temporary.
QPointF m_clickPoint
position where the click event was created.
QPainterPath shape() const
Reimplementation from QGraphicsItem.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
Send a connect request to kernel when start- and endport are connectable.
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
If the item is changed we want to get notified.
void doneDrag(const QPointF &pos)
Called when releasing the mouse.
QRectF boundingRect() const
Reimplementation form QGraphicsItem, because the arrowhead is added to the line.
int type() const
Reimplementation from QGraphicsItem.
QColor m_color
the current color
WQtNetworkInputPort * m_connectTo
connect to this port after mouse release.
bool m_connectionDisconnect
disconnect if true.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w)
Draw some customized stuff in the scene.
QPolygonF m_arrowHead
the arrowhead
WQtNetworkOutputPort * m_startPort
the start port
QLineF m_line
the line representing the arrow
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
If the cursor leaves the arrow, the arrow gets his default color.
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
Updates the temporary arrows endpoint.
void moveDrag(const QPointF &pos)
Update drag position.
WQtNetworkInputPort * findNearestCompatibleInput(QPointF pos, float maxDistance=100)
Search the next, compatible input port.
void startDrag(const QPointF &pos)
Start Drag.
WQtNetworkScene * getScene()
Returns the current scene.
This class represents the ports a module have.
std::shared_ptr< WModuleOutputConnector > getConnector()
Returns the WModuleOutputConnecter that belongs to this object.
virtual void removeArrow(WQtNetworkArrow *arrow)
Removes a specific arrow.
The scene containing the whole graph.