1 #ifndef __ABSTRACTBOXITEM_H__
2 #define __ABSTRACTBOXITEM_H__
8 #include <QGraphicsItem>
15 class ConnectedInterface;
17 class AbstractBoxItem : public QGraphicsItem {
21 enum BorderType { NoBorder = 0, BorderEast, BorderNorth, BorderWest, BorderSouth, CornerSouthEast, Title};
22 enum ChangeType { Resize = 0, InterfaceMove };
24 AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem* parent = Q_NULLPTR);
26 virtual ~AbstractBoxItem();
29 inline AbstractBlock* getRefBlock() { return refBlock; }
30 inline int getWidth() { return boxWidth;}
31 inline int getHeight() { return boxHeight;}
32 inline int getTotalWidth() { return totalWidth;}
33 inline int getTotalHeight() { return totalHeight; }
34 inline QList<InterfaceItem* > getInterfaces() { return interfaces; }
35 inline InterfaceItem *getCurrentInterface() { return currentInterface; }
36 inline int getId(){ return id; }
37 inline GroupScene* getScene() { return (GroupScene*)(scene()); }
38 inline int getIfaceMargin() { return ifaceMargin; }
39 inline int getNameMargin() { return nameMargin; }
40 inline QPointF getOriginPoint() { return originPoint; }
43 inline void setId(int id){ this->id = id; }
44 inline void setSelected(bool _selected) { selected = _selected; }
45 inline void setRstClkVisible(bool b){ rstClkVisible = b;}
46 void setDimension(int x, int y);
47 inline void setCurrentInterface(InterfaceItem* iface) { currentInterface = iface; }
50 virtual bool isBoxItem();
51 virtual bool isGroupItem();
52 inline bool isSelected() { return selected; }
53 inline bool isRstClkVisible(){ return rstClkVisible;}
54 bool isInterfaces(int orientation) const;
58 void addInterface(InterfaceItem* i, bool resetPosition = false);
59 void removeInterface(InterfaceItem* i);
60 void resetInterfacesPosition();
62 * \brief moveInterfaceTo
63 * \param pos the new position (in scene) of the interface
65 * This method is called when user moves an InterfaceItem.
66 * see BoxItem::mouseMoveEvent() and GroupItem::mouseMoveEvent()
68 void moveInterfaceTo(QPointF pos);
70 * \brief updateInterfacesAndConnections
72 * This method allows to recompute the absolute position of the interfaces of this box
73 * taking into account their relative position (see positionRatio atribute) in the width/height
74 * of the box border they are located on. It allows update the shape of all ConnectionItem
75 * connected to this box.
77 * CAUTION: this method supposes that before its call, a call to prepareGeometryChange() hase been
78 * done for the BoxItem that owns this InterfaceItem, so that the scene will readraw automatically
79 * the BoxItem. For the connections, the call to prepareGeometryChange() is done within setPath()
80 * that is called in this method. Thus, there is no need to call update() after the termination of
83 void updateInterfacesAndConnections();
85 InterfaceItem *searchInterfaceByName(QString name);
86 InterfaceItem *searchInterfaceByRef(ConnectedInterface* ref);
87 InterfaceItem* getInterfaceFromCursor(qreal x, qreal y);
90 Dispatcher *dispatcher;
92 QList<InterfaceItem*> interfaces;
93 /* NOTE : the reference block may be a FunctionalBlock or a GroupBlock, depending on the fact
94 that the real instace will be of FunctionalBlock or GroupBlock
96 AbstractBlock *refBlock;
98 InterfaceItem* currentInterface; // currently clicked interface in ItemEdition mode
100 BorderType currentBorder; // which border cursor is on
101 QPointF cursorPosition;
104 int boxWidth; // the width of the main box (without interface, title, ...)
105 int boxHeight; // the height of the main box (without interface, title, ...)
106 int minimumBoxWidth; // minimum width of the main box: may be recomputed if position/number of interface changes
107 int minimumBoxHeight; // minimum height of the main box: may be recomputed if position/number of interface changes
108 int totalWidth; // width and heigth taking into account interfaces,title, ...
110 int nameWidth; // the width of the box (group or block) name in Arial 10
111 int nameHeight; // the height of the name in Arial 10
112 int nameMargin; // the margin around each side of the name
113 int ifaceMargin; // the margin around each side of interfaces' name
114 QPointF originPoint; // the left-top point that is the origin of the bounding box
119 QPointF currentPosition; // the start point for resize
121 virtual void updateMinimumSize() = 0; // modify the minimum size
122 virtual bool updateGeometry(ChangeType type) = 0; // modify the originPoint and the total dimension
124 QRectF boundingRect() const;
125 /* pure virtual method inherited from QGraphicsItem :
126 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) =0;
127 virtual QRectF boundingRect() const =0;
129 void initInterfaces();
130 int nbInterfacesByOrientation(int orientation);
133 #endif // __ABSTRACTBOXITEM_H__