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