45#include <QGraphicsSceneMouseEvent>
46#include <QGraphicsScene>
48#include "elementInOut.hh"
49#include "elementInput.hh"
50#include "elementOutput.hh"
51#include "connection.hh"
52#include "connectionPoint.hh"
53#include "graphicsScene.hh"
54#include "elementArea.hh"
68 QGraphicsPathItem (dynamic_cast<
GraphicsScene *>(_scene)->elementArea ()),
79 p.setCapStyle (Qt::RoundCap);
80 p.setColor (QColor (128, 128, 128));
91 QGraphicsPathItem (dynamic_cast<
GraphicsScene *>(_scene)->elementArea ()),
100 p.setCapStyle (Qt::RoundCap);
117 p.setColor (QColor (0, 0, 0));
134void Connection::mouseMoveEvent (QGraphicsSceneMouseEvent *_event)
142 p.setColor (QColor (0, 255, 0));
144 p.setColor (QColor (255, 0, 0));
147 p.setColor (QColor (128, 128, 128));
150 way_ = scene_->
wayFind ()->
findWay (
this, p1_->
connectPos ().toPoint (), elementArea_->mapFromScene (_event->scenePos ()).toPoint ());
155void Connection::mousePressEvent (QGraphicsSceneMouseEvent *_event)
162 QPointF p = p1_->
connectPos () - _event->scenePos ();
163 qreal d1 = (p.x () * p.x()) + (p.y () * p.y ());
165 qreal d2 = (p.x () * p.x()) + (p.y () * p.y ());
173 way_ = scene_->
wayFind ()->
findWay (
this, p1_->
connectPos ().toPoint (), elementArea_->mapFromScene (_event->scenePos ()).toPoint ());
178void Connection::mouseReleaseEvent (QGraphicsSceneMouseEvent *_event)
182 p2_ = cPointAt (_event->scenePos ());
199 p.setColor (QColor (0, 0, 0));
213ConnectionPoint *Connection::cPointAt (QPointF _pnt)
216 ConnectionPoint *pnt = 0;
218 foreach (QGraphicsItem *i, scene ()->items (_pnt))
220 ConnectionPoint *pt =
dynamic_cast<ConnectionPoint *
>(i);
266 setPath (QPainterPath ());
270void Connection::updateLine()
274 if (way_.size () <= 1)
279 else if (way_.size () == 2)
281 path.addPolygon(way_);
286 path.moveTo (way_[0]);
290 for (
int i = 2; i < way_.size (); i++)
296 QLineF l1 (a,b), l2 (b,c);
298 int rad = qMin (40.0, qMin (l1.length() / 2, l2.length() / 2));
303 if (a.x () == b.x ())
307 path.lineTo (b.x (), b.y () + rad);
310 path.arcTo (b.x (), b.y (), 2 * rad, 2 * rad, 180, -90);
314 path.arcTo (b.x () - (rad * 2), b.y (), 2 * rad, 2 * rad, 0, 90);
319 path.lineTo (b.x (), b.y () - rad);
322 path.arcTo (b.x (), b.y () - (rad * 2), 2 * rad, 2 * rad, 180, 90);
326 path.arcTo (b.x () - (rad * 2), b.y () - (rad * 2), 2 * rad, 2 * rad, 0, -90);
334 path.lineTo (b.x () + rad, b.y ());
337 path.arcTo (b.x (), b.y (), 2 * rad, 2 * rad, 90, 90);
341 path.arcTo (b.x (), b.y () - (rad * 2), 2 * rad, 2 * rad, 270, -90);
346 path.lineTo (b.x () - rad, b.y ());
349 path.arcTo (b.x () - (rad * 2), b.y (), 2 * rad, 2 * rad, 90, -90);
353 path.arcTo (b.x () - (rad * 2), b.y () - (rad * 2), 2 * rad, 2 * rad, 270, 90);
QPointF connectPos()
Position for connections.
ElementInOut * inOut() const
Input/output element.
ElementInput * input()
Input of this connection.
void updatePositions()
called to update position on element movement
void invalidate()
invalidate way
ElementOutput * output()
Output of this connection.
const QPolygonF & way() const
way of the connection
Connection(ConnectionPoint *_start, QGraphicsScene *_scene)
Constructor.
InOut * inOut() const
InOut context object.
virtual void removeConnection(Connection *_conn)
Remove the Connection.
bool validConnection(ElementInOut *_e)
Can this input/output be connected to _e.
virtual void addConnection(Connection *_conn)
Add the connection.
void contentChange()
handle content changes
WayFind * wayFind()
WayFind object.
void setActiveConnection(Connection *_conn)
Sets the active connection.
ElementArea * elementArea() const
Element area.
QString typeString() const
Type.
QPolygonF findWay(Connection *_conn, QPoint _from, QPoint _to)
Finds a way from _from to _to ignoring any already existent connections from _conn.