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 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; }
71 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
75 * setPath() allows to compute the graphical shape of the ConnectionItem
76 * taking into account the position/direction of from and to interface items.
77 * Depending on their vlaue, it calls on of the dedicated methods.
79 * CAUTION: this method calls prepareGeometryChange() so that the scene
80 * can automatically updates and redraw the ConnectionItem. Thus, there is
81 * no need to call update() after the termination of this method.
85 void addInterPoint(QPointF point);
90 void mousePressEvent(QGraphicsSceneMouseEvent *event);
91 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
92 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
93 void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
96 void computeEsse(int orientationFrom);
97 void computeStaircase(int orientationFrom);
98 void computeHookSmallEnd(int orientationFrom, int orientationTo);
99 void computeHookSmallStart(int orientationFrom, int orientationTo);
100 void computeOpenRect(int orientationFrom, int orientationTo);
101 void computeElle(int orientationFrom);
102 void computeCorner(int orientationFrom);
106 QList<QPointF> interPoints;
112 QPainterPath pathPaint;
113 QPainterPath pathShape;
114 QPainterPathStroker pps;
115 Dispatcher* dispatcher;
117 InterfaceItem* fromInterfaceItem;
118 InterfaceItem* toInterfaceItem;
125 friend QDataStream &operator << (QDataStream &out, ConnectionItem &c);
126 friend QDataStream &operator >> (QDataStream &in, ConnectionItem &c);