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 };
27 enum LockType { NoLock = 0, Position = 1, Dimension = 2, Interfaces = 4, Names = 8};
29 AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, LockType _lock = NoLock, QGraphicsItem* parent = Q_NULLPTR);
30 AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, LockType _lock = NoLock, QGraphicsItem* parent = Q_NULLPTR);
32 virtual ~AbstractBoxItem();
35 inline AbstractBlock* getRefBlock() { return refBlock; }
36 inline int getWidth() { return boxWidth;}
37 inline int getHeight() { return boxHeight;}
38 inline int getTotalWidth() { return totalWidth;}
39 inline int getTotalHeight() { return totalHeight; }
40 inline QList<InterfaceItem* > getInterfaces() { return interfaces; }
41 inline InterfaceItem *getCurrentInterface() { return currentInterface; }
42 inline int getId(){ return id; }
43 inline GroupScene* getScene() { return (GroupScene*)(scene()); }
44 inline int getIfaceMargin() { return ifaceMargin; }
45 inline int getNameMargin() { return nameMargin; }
46 inline QPointF getOriginPoint() { return originPoint; }
49 void setRefBlock(AbstractBlock* _refBlock);
50 inline void setId(int _id){ id = _id; }
51 inline void setSelected(bool _selected) { selected = _selected; }
52 void setRstClkVisible(bool b);
53 void setWishboneVisible(bool b);
54 void setDimension(int x, int y);
55 inline void setCurrentInterface(InterfaceItem* iface) { currentInterface = iface; }
56 inline void setLock(int _lock) { lock = _lock; }
57 inline void lockPosition() { lock = lock | Position; }
58 inline void unlockPosition() { lock = (lock&Position)^lock; }
59 inline void lockDimension() { lock = lock | Dimension; }
60 inline void unlockDimension() { lock = (lock&Dimension)^lock; }
61 inline void lockInterfaces() { lock = lock | Interfaces; }
62 inline void unlockInterfaces() { lock = (lock&Interfaces)^lock; }
63 inline void lockNames() { lock = lock | Names; }
64 inline void unlockNames() { lock = (lock&Names)^lock; }
67 virtual bool isBoxItem();
68 virtual bool isGroupItem();
69 virtual bool isSourceItem();
70 inline bool isSelected() { return selected; }
71 inline bool isRstClkVisible(){ return rstClkVisible;}
72 inline bool isWishboneVisible(){ return wishboneVisible;}
73 bool isInterfaces(int orientation) const;
74 inline bool isPositionLock() { return (lock&Position)!=0?true:false; }
75 inline bool isDimensionLock() { return (lock&Dimension)!=0?true:false; }
76 inline bool isInterfacesLock() { return (lock&Interfaces)!=0?true:false; }
77 inline bool isNamesLock() { return (lock&Names)!=0?true:false; }
79 QRectF boundingRectInScene();
80 virtual void nameChanged() = 0; // called when an interface or box name have changed
81 void addInterfaceItem(InterfaceItem* i, bool resetPosition = false);
82 void removeInterfaceItem(InterfaceItem* i);
83 void resetInterfaceItemsPosition();
85 * \brief moveInterfaceTo
86 * \param pos the new position (in scene) of the interface
88 * This method is called when user moves an InterfaceItem.
89 * see BoxItem::mouseMoveEvent() and GroupItem::mouseMoveEvent()
91 void moveInterfaceItemTo(QPointF pos);
93 * \brief updateInterfacesAndConnections
95 * This method allows to recompute the absolute position of the interfaces of this box
96 * taking into account their relative position (see positionRatio atribute) in the width/height
97 * of the box border they are located on. It allows update the shape of all ConnectionItem
98 * connected to this box.
100 * CAUTION: this method supposes that before its call, a call to prepareGeometryChange() hase been
101 * done for the BoxItem that owns this InterfaceItem, so that the scene will readraw automatically
102 * the BoxItem. For the connections, the call to prepareGeometryChange() is done within setPath()
103 * that is called in this method. Thus, there is no need to call update() after the termination of
106 void updateInterfaceAndConnectionItems();
108 InterfaceItem *searchInterfaceItemByName(QString name);
109 InterfaceItem *searchInterfaceItemByRef(ConnectedInterface* ref);
110 InterfaceItem* getInterfaceItemFromCursor(qreal x, qreal y);
113 Dispatcher *dispatcher;
115 QList<InterfaceItem*> interfaces;
116 /* NOTE : the reference block may be a FunctionalBlock or a GroupBlock, depending on the fact
117 that the real instace will be of FunctionalBlock or GroupBlock
119 AbstractBlock *refBlock;
121 InterfaceItem* currentInterface; // currently clicked interface in ItemEdition mode
123 BorderType currentBorder; // which border cursor is on
124 QPointF cursorPosition;
127 int boxWidth; // the width of the main box (without interface, title, ...)
128 int boxHeight; // the height of the main box (without interface, title, ...)
129 int minimumBoxWidth; // minimum width of the main box: may be recomputed if position/number of interface changes
130 int minimumBoxHeight; // minimum height of the main box: may be recomputed if position/number of interface changes
131 int totalWidth; // width and heigth taking into account interfaces,title, ...
133 int nameWidth; // the width of the box (group or block) name in Arial 10
134 int nameHeight; // the height of the name in Arial 10
135 int nameMargin; // the margin around each side of the name
136 int ifaceMargin; // the margin around each side of interfaces' name
137 QPointF originPoint; // the left-top point that is the origin of the bounding box, in the item coordinates
141 bool rstClkVisible; //! true if clock/reset interfaces are visible
142 bool wishboneVisible; //! true if wishbone interfaces are visible
144 QPointF currentPosition; // the start point for resize, i.e. the position of the lef-top corner of the box, in the scene coordinates
146 virtual void updateMinimumSize() = 0; // modify the minimum size
147 virtual bool updateGeometry(ChangeType type) = 0; // modify the originPoint and the total dimension
149 QRectF boundingRect() const;
150 /* pure virtual method inherited from QGraphicsItem :
151 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) =0;
152 virtual QRectF boundingRect() const =0;
155 void initInterfaceItems();
156 int nbInterfacesByOrientation(int orientation);
159 #endif // __ABSTRACTBOXITEM_H__