51 #include <QGraphicsSceneMouseEvent> 52 #include <QGraphicsScene> 54 #include "elementInOut.hh" 55 #include "elementInput.hh" 56 #include "elementOutput.hh" 57 #include "connection.hh" 58 #include "connectionPoint.hh" 59 #include "graphicsScene.hh" 60 #include "elementArea.hh" 74 QGraphicsPathItem (dynamic_cast<
GraphicsScene *>(_scene)->elementArea ()),
85 p.setCapStyle (Qt::RoundCap);
86 p.setColor (QColor (128, 128, 128));
97 QGraphicsPathItem (dynamic_cast<
GraphicsScene *>(_scene)->elementArea ()),
106 p.setCapStyle (Qt::RoundCap);
123 p.setColor (QColor (0, 0, 0));
140 void Connection::mouseMoveEvent (QGraphicsSceneMouseEvent *_event)
148 p.setColor (QColor (0, 255, 0));
150 p.setColor (QColor (255, 0, 0));
153 p.setColor (QColor (128, 128, 128));
156 way_ = scene_->
wayFind ()->
findWay (
this, p1_->
connectPos ().toPoint (), elementArea_->mapFromScene (_event->scenePos ()).toPoint ());
161 void Connection::mousePressEvent (QGraphicsSceneMouseEvent *_event)
168 QPointF p = p1_->
connectPos () - _event->scenePos ();
169 qreal d1 = (p.x () * p.x()) + (p.y () * p.y ());
171 qreal d2 = (p.x () * p.x()) + (p.y () * p.y ());
179 way_ = scene_->
wayFind ()->
findWay (
this, p1_->
connectPos ().toPoint (), elementArea_->mapFromScene (_event->scenePos ()).toPoint ());
184 void Connection::mouseReleaseEvent (QGraphicsSceneMouseEvent *_event)
188 p2_ = cPointAt (_event->scenePos ());
205 p.setColor (QColor (0, 0, 0));
224 foreach (QGraphicsItem *i, scene ()->items (_pnt))
272 setPath (QPainterPath ());
276 void Connection::updateLine()
280 if (way_.size () <= 1)
285 else if (way_.size () == 2)
287 path.addPolygon(way_);
292 path.moveTo (way_[0]);
296 for (
int i = 2; i < way_.size (); i++)
302 QLineF l1 (a,b), l2 (b,c);
304 int rad = qMin (40.0, qMin (l1.length() / 2, l2.length() / 2));
309 if (a.x () == b.x ())
313 path.lineTo (b.x (), b.y () + rad);
316 path.arcTo (b.x (), b.y (), 2 * rad, 2 * rad, 180, -90);
320 path.arcTo (b.x () - (rad * 2), b.y (), 2 * rad, 2 * rad, 0, 90);
325 path.lineTo (b.x (), b.y () - rad);
328 path.arcTo (b.x (), b.y () - (rad * 2), 2 * rad, 2 * rad, 180, 90);
332 path.arcTo (b.x () - (rad * 2), b.y () - (rad * 2), 2 * rad, 2 * rad, 0, -90);
340 path.lineTo (b.x () + rad, b.y ());
343 path.arcTo (b.x (), b.y (), 2 * rad, 2 * rad, 90, 90);
347 path.arcTo (b.x (), b.y () - (rad * 2), 2 * rad, 2 * rad, 270, -90);
352 path.lineTo (b.x () - rad, b.y ());
355 path.arcTo (b.x () - (rad * 2), b.y (), 2 * rad, 2 * rad, 90, -90);
359 path.arcTo (b.x () - (rad * 2), b.y () - (rad * 2), 2 * rad, 2 * rad, 270, 90);
QPolygonF findWay(Connection *_conn, QPoint _from, QPoint _to)
Finds a way from _from to _to ignoring any already existent connections from _conn.
const QPolygonF & way() const
way of the connection
QString typeString() const
Type.
ElementArea * elementArea() const
Element area.
void invalidate()
invalidate way
bool validConnection(ElementInOut *_e)
Can this input/output be connected to _e.
QPointF connectPos()
Position for connections.
virtual void addConnection(Connection *_conn)
Add the connection.
Connection(ConnectionPoint *_start, QGraphicsScene *_scene)
Constructor.
void contentChange()
handle content changes
void updatePositions()
called to update position on element movement
virtual void removeConnection(Connection *_conn)
Remove the Connection.
ElementInput * input()
Input of this connection.
InOut * inOut() const
InOut context object.
void setActiveConnection(Connection *_conn)
Sets the active connection.
ElementOutput * output()
Output of this connection.
WayFind * wayFind()
WayFind object.
ElementInOut * inOut() const
Input/output element.