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);
25 AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem* parent = Q_NULLPTR);
27 virtual ~AbstractBoxItem();
30 inline AbstractBlock* getRefBlock() { return refBlock; }
31 inline int getWidth() { return boxWidth;}
32 inline int getHeight() { return boxHeight;}
33 inline int getTotalWidth() { return totalWidth;}
34 inline int getTotalHeight() { return totalHeight; }
35 inline QList<InterfaceItem* > getInterfaces() { return interfaces; }
36 inline InterfaceItem *getCurrentInterface() { return currentInterface; }
37 inline int getId(){ return id; }
38 inline GroupScene* getScene() { return (GroupScene*)(scene()); }
39 inline int getIfaceMargin() { return ifaceMargin; }
40 inline int getNameMargin() { return nameMargin; }
41 inline QPointF getOriginPoint() { return originPoint; }
44 void setRefBlock(AbstractBlock* _refBlock);
45 inline void setId(int _id){ id = _id; }
46 inline void setSelected(bool _selected) { selected = _selected; }
47 void setRstClkVisible(bool b);
48 void setWishboneVisible(bool b);
49 void setDimension(int x, int y);
50 inline void setCurrentInterface(InterfaceItem* iface) { currentInterface = iface; }
53 virtual bool isBoxItem();
54 virtual bool isGroupItem();
55 virtual bool isSourceItem();
56 inline bool isSelected() { return selected; }
57 inline bool isRstClkVisible(){ return rstClkVisible;}
58 inline bool isWishboneVisible(){ return wishboneVisible;}
59 bool isInterfaces(int orientation) const;
62 QRectF boundingRectInScene();
63 virtual void nameChanged() = 0; // called when an interface or box name have changed
64 void addInterface(InterfaceItem* i, bool resetPosition = false);
65 void removeInterface(InterfaceItem* i);
66 void resetInterfacesPosition();
68 * \brief moveInterfaceTo
69 * \param pos the new position (in scene) of the interface
71 * This method is called when user moves an InterfaceItem.
72 * see BoxItem::mouseMoveEvent() and GroupItem::mouseMoveEvent()
74 void moveInterfaceTo(QPointF pos);
76 * \brief updateInterfacesAndConnections
78 * This method allows to recompute the absolute position of the interfaces of this box
79 * taking into account their relative position (see positionRatio atribute) in the width/height
80 * of the box border they are located on. It allows update the shape of all ConnectionItem
81 * connected to this box.
83 * CAUTION: this method supposes that before its call, a call to prepareGeometryChange() hase been
84 * done for the BoxItem that owns this InterfaceItem, so that the scene will readraw automatically
85 * the BoxItem. For the connections, the call to prepareGeometryChange() is done within setPath()
86 * that is called in this method. Thus, there is no need to call update() after the termination of
89 void updateInterfacesAndConnections();
91 InterfaceItem *searchInterfaceByName(QString name);
92 InterfaceItem *searchInterfaceByRef(ConnectedInterface* ref);
93 InterfaceItem* getInterfaceFromCursor(qreal x, qreal y);
96 Dispatcher *dispatcher;
98 QList<InterfaceItem*> interfaces;
99 /* NOTE : the reference block may be a FunctionalBlock or a GroupBlock, depending on the fact
100 that the real instace will be of FunctionalBlock or GroupBlock
102 AbstractBlock *refBlock;
104 InterfaceItem* currentInterface; // currently clicked interface in ItemEdition mode
106 BorderType currentBorder; // which border cursor is on
107 QPointF cursorPosition;
110 int boxWidth; // the width of the main box (without interface, title, ...)
111 int boxHeight; // the height of the main box (without interface, title, ...)
112 int minimumBoxWidth; // minimum width of the main box: may be recomputed if position/number of interface changes
113 int minimumBoxHeight; // minimum height of the main box: may be recomputed if position/number of interface changes
114 int totalWidth; // width and heigth taking into account interfaces,title, ...
116 int nameWidth; // the width of the box (group or block) name in Arial 10
117 int nameHeight; // the height of the name in Arial 10
118 int nameMargin; // the margin around each side of the name
119 int ifaceMargin; // the margin around each side of interfaces' name
120 QPointF originPoint; // the left-top point that is the origin of the bounding box, in the item coordinates
123 bool rstClkVisible; //! true if clock/reset interfaces are visible
124 bool wishboneVisible; //! true if wishbone interfaces are visible
126 QPointF currentPosition; // the start point for resize, i.e. the position of the lef-top corner of the box, in the scene coordinates
128 virtual void updateMinimumSize() = 0; // modify the minimum size
129 virtual bool updateGeometry(ChangeType type) = 0; // modify the originPoint and the total dimension
131 QRectF boundingRect() const;
132 /* pure virtual method inherited from QGraphicsItem :
133 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) =0;
134 virtual QRectF boundingRect() const =0;
137 void initInterfaces();
138 int nbInterfacesByOrientation(int orientation);
141 #endif // __ABSTRACTBOXITEM_H__