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* _fromInterfaceItem,
42 InterfaceItem* _toInterfaceItem,
43 Dispatcher* _dispatcher,
45 ConnectionItem (const ConnectionItem & copy);
49 QRectF boundingRect() const;
50 QPainterPath shape() const;
55 inline GroupScene* getScene() { return (GroupScene*)(scene()); }
56 inline InterfaceItem* getToInterfaceItem(){ return toInterfaceItem; }
57 inline InterfaceItem* getFromInterfaceItem(){ return fromInterfaceItem; }
58 inline int getId(){ return id; }
61 inline void setToInterfaceItem(InterfaceItem *iface){ toInterfaceItem = iface; }
62 inline void setFromInterfaceItem(InterfaceItem* iface){ fromInterfaceItem = iface; }
63 inline void setId(int id){ this->id = id; }
64 void setSelected(bool selected);
65 inline void setVisible(bool state) { visible = state; }
68 inline bool isSelected() { return selected; }
69 inline bool isVisible() { return visible; }
72 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
76 * setPath() allows to compute the graphical shape of the ConnectionItem
77 * taking into account the position/direction of from and to interface items.
78 * Depending on their vlaue, it calls on of the dedicated methods.
80 * CAUTION: this method calls prepareGeometryChange() so that the scene
81 * can automatically updates and redraw the ConnectionItem. Thus, there is
82 * no need to call update() after the termination of this method.
86 void addInterPoint(QPointF point);
91 void mousePressEvent(QGraphicsSceneMouseEvent *event);
92 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
93 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
94 void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
97 void computeEsse(int orientationFrom);
98 void computeStaircase(int orientationFrom);
99 void computeHookSmallEnd(int orientationFrom, int orientationTo);
100 void computeHookSmallStart(int orientationFrom, int orientationTo);
101 void computeOpenRect(int orientationFrom, int orientationTo);
102 void computeElle(int orientationFrom);
103 void computeCorner(int orientationFrom);
107 QList<QPointF> interPoints;
113 QPainterPath pathPaint;
114 QPainterPath pathShape;
115 QPainterPathStroker pps;
116 Dispatcher* dispatcher;
118 InterfaceItem* fromInterfaceItem;
119 InterfaceItem* toInterfaceItem;
126 friend QDataStream &operator << (QDataStream &out, ConnectionItem &c);
127 friend QDataStream &operator >> (QDataStream &in, ConnectionItem &c);