1 #ifndef __ABSTRACTBOXITEM_H__
2 #define __ABSTRACTBOXITEM_H__
8 #include <QGraphicsItem>
15 class ConnectedInterface;
17 #define ABI_TO_BI(ptr) ((BoxItem*)ptr)
18 #define ABI_TO_GI(ptr) ((GroupItem*)ptr)
19 #define ABI_TO_SI(ptr) ((SourceItem*)ptr)
21 class AbstractBoxItem : public QGraphicsItem {
25 enum BorderType { NoBorder = 0, BorderEast, BorderNorth, BorderWest, BorderSouth, CornerSouthEast, Title};
26 enum ChangeType { Resize = 0, InterfaceMove };
28 AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem* parent = Q_NULLPTR);
29 AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem* parent = Q_NULLPTR);
31 virtual ~AbstractBoxItem();
34 inline AbstractBlock* getRefBlock() { return refBlock; }
35 inline int getWidth() { return boxWidth;}
36 inline int getHeight() { return boxHeight;}
37 inline int getTotalWidth() { return totalWidth;}
38 inline int getTotalHeight() { return totalHeight; }
39 inline QList<InterfaceItem* > getInterfaces() { return interfaces; }
40 inline InterfaceItem *getCurrentInterface() { return currentInterface; }
41 inline int getId(){ return id; }
42 inline GroupScene* getScene() { return (GroupScene*)(scene()); }
43 inline int getIfaceMargin() { return ifaceMargin; }
44 inline int getNameMargin() { return nameMargin; }
45 inline QPointF getOriginPoint() { return originPoint; }
48 void setRefBlock(AbstractBlock* _refBlock);
49 inline void setId(int _id){ id = _id; }
50 inline void setSelected(bool _selected) { selected = _selected; }
51 void setRstClkVisible(bool b);
52 void setWishboneVisible(bool b);
53 void setDimension(int x, int y);
54 inline void setCurrentInterface(InterfaceItem* iface) { currentInterface = iface; }
57 virtual bool isBoxItem();
58 virtual bool isGroupItem();
59 virtual bool isSourceItem();
60 inline bool isSelected() { return selected; }
61 inline bool isRstClkVisible(){ return rstClkVisible;}
62 inline bool isWishboneVisible(){ return wishboneVisible;}
63 bool isInterfaces(int orientation) const;
66 QRectF boundingRectInScene();
67 virtual void nameChanged() = 0; // called when an interface or box name have changed
68 void addInterfaceItem(InterfaceItem* i, bool resetPosition = false);
69 void removeInterfaceItem(InterfaceItem* i);
70 void resetInterfaceItemsPosition();
72 * \brief moveInterfaceTo
73 * \param pos the new position (in scene) of the interface
75 * This method is called when user moves an InterfaceItem.
76 * see BoxItem::mouseMoveEvent() and GroupItem::mouseMoveEvent()
78 void moveInterfaceItemTo(QPointF pos);
80 * \brief updateInterfacesAndConnections
82 * This method allows to recompute the absolute position of the interfaces of this box
83 * taking into account their relative position (see positionRatio atribute) in the width/height
84 * of the box border they are located on. It allows update the shape of all ConnectionItem
85 * connected to this box.
87 * CAUTION: this method supposes that before its call, a call to prepareGeometryChange() hase been
88 * done for the BoxItem that owns this InterfaceItem, so that the scene will readraw automatically
89 * the BoxItem. For the connections, the call to prepareGeometryChange() is done within setPath()
90 * that is called in this method. Thus, there is no need to call update() after the termination of
93 void updateInterfaceAndConnectionItems();
95 InterfaceItem *searchInterfaceItemByName(QString name);
96 InterfaceItem *searchInterfaceItemByRef(ConnectedInterface* ref);
97 InterfaceItem* getInterfaceItemFromCursor(qreal x, qreal y);
100 Dispatcher *dispatcher;
102 QList<InterfaceItem*> interfaces;
103 /* NOTE : the reference block may be a FunctionalBlock or a GroupBlock, depending on the fact
104 that the real instace will be of FunctionalBlock or GroupBlock
106 AbstractBlock *refBlock;
108 InterfaceItem* currentInterface; // currently clicked interface in ItemEdition mode
110 BorderType currentBorder; // which border cursor is on
111 QPointF cursorPosition;
114 int boxWidth; // the width of the main box (without interface, title, ...)
115 int boxHeight; // the height of the main box (without interface, title, ...)
116 int minimumBoxWidth; // minimum width of the main box: may be recomputed if position/number of interface changes
117 int minimumBoxHeight; // minimum height of the main box: may be recomputed if position/number of interface changes
118 int totalWidth; // width and heigth taking into account interfaces,title, ...
120 int nameWidth; // the width of the box (group or block) name in Arial 10
121 int nameHeight; // the height of the name in Arial 10
122 int nameMargin; // the margin around each side of the name
123 int ifaceMargin; // the margin around each side of interfaces' name
124 QPointF originPoint; // the left-top point that is the origin of the bounding box, in the item coordinates
127 bool rstClkVisible; //! true if clock/reset interfaces are visible
128 bool wishboneVisible; //! true if wishbone interfaces are visible
130 QPointF currentPosition; // the start point for resize, i.e. the position of the lef-top corner of the box, in the scene coordinates
132 virtual void updateMinimumSize() = 0; // modify the minimum size
133 virtual bool updateGeometry(ChangeType type) = 0; // modify the originPoint and the total dimension
135 QRectF boundingRect() const;
136 /* pure virtual method inherited from QGraphicsItem :
137 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) =0;
138 virtual QRectF boundingRect() const =0;
141 void initInterfaceItems();
142 int nbInterfacesByOrientation(int orientation);
145 #endif // __ABSTRACTBOXITEM_H__