1 #ifndef __CONNECTIONITEM_H__
2 #define __CONNECTIONITEM_H__
8 #include <QGraphicsItem>
18 /*! \brief ConnectionItem class
20 A ConnectionItem represents a graphical link between two interface items.
21 Even if it links two in/out interfaces, it is always oriented.
22 The orientation depends on the type and direction of linked interfaces :
24 If interfaces are owned by blocks (group or func) that are within the same
25 parent group, then src must be an output, and dest an input, or both are in/out
26 and src/dest may be interchanged.
28 If one interface I1 is owend by a block, and the other I2 by the parent group of that block,
29 then they have the same direction. If this direction is input, then src = I2 and dest = I1,
30 if it is output, then src = I1, dest = I2, and if it is in/out, no order matters.
32 In order to simplify other methods, the constructor of ConnectionItem
33 checks these cases in order to retrieve the good src and dest if they are
34 not provided in the good order.
37 class ConnectionItem : public QGraphicsItem {
41 ConnectionItem(InterfaceItem* _iface1,
42 InterfaceItem* _iface2,
43 Dispatcher* _dispatcher,
45 QGraphicsItem* _parent);
46 ConnectionItem (const ConnectionItem & copy);
50 QRectF boundingRect() const;
51 QPainterPath shape() const;
55 inline GroupScene* getScene() { return (GroupScene*)(scene()); }
56 inline InterfaceItem* getToInterfaceItem(){ return toInterfaceItem; }
57 inline void setToInterfaceItem(InterfaceItem *iface){ toInterfaceItem = iface; }
58 inline InterfaceItem* getFromInterfaceItem(){ return fromInterfaceItem; }
59 inline void setFromInterfaceItem(InterfaceItem* iface){ fromInterfaceItem = iface; }
60 inline int getId(){ return id; }
61 inline void setId(int id){ this->id = id; }
62 inline bool isSelected() { return selected; }
63 void setSelected(bool selected);
65 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
69 * setPath() allows to compute the graphical shape of the ConnectionItem
70 * taking into account the position/direction of from and to interface items.
71 * Depending on their vlaue, it calls on of the dedicated methods.
73 * CAUTION: this method calls prepareGeometryChange() so that the scene
74 * can automatically updates and redraw the ConnectionItem. Thus, there is
75 * no need to call update() after the termination of this method.
79 void addInterPoint(QPointF point);
84 void mousePressEvent(QGraphicsSceneMouseEvent *event);
85 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
86 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
87 void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
93 QList<QPointF> interPoints;
99 QPainterPath pathPaint;
100 QPainterPath pathShape;
101 QPainterPathStroker pps;
102 Dispatcher* dispatcher;
104 InterfaceItem* fromInterfaceItem;
105 InterfaceItem* toInterfaceItem;
109 void computeEsse(int orientationFrom);
110 void computeStaircase(int orientationFrom);
111 void computeHookSmallEnd(int orientationFrom, int orientationTo);
112 void computeHookSmallStart(int orientationFrom, int orientationTo);
113 void computeOpenRect(int orientationFrom, int orientationTo);
114 void computeElle(int orientationFrom);
115 void computeCorner(int orientationFrom);
117 friend QDataStream &operator << (QDataStream &out, ConnectionItem &c);
118 friend QDataStream &operator >> (QDataStream &in, ConnectionItem &c);