1 #ifndef __ABSTRACTBOXITEM_H__
2 #define __ABSTRACTBOXITEM_H__
8 #include <QGraphicsItem>
12 #include "Parameters.h"
16 class ConnectedInterface;
18 #define ABI_TO_BI(ptr) ((BoxItem*)ptr)
19 #define ABI_TO_GI(ptr) ((GroupItem*)ptr)
20 #define ABI_TO_SI(ptr) ((SourceItem*)ptr)
22 class AbstractBoxItem : public QGraphicsItem {
26 enum BorderType { NoBorder = 0, BorderEast, BorderNorth, BorderWest, BorderSouth, CornerSouthEast, Title};
27 enum ChangeType { Creation = 0, Resize, InterfaceMove };
32 static int Interfaces;
35 AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, int _lock = NoLock, QGraphicsItem* parent = Q_NULLPTR);
36 AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, int _lock = NoLock, QGraphicsItem* parent = Q_NULLPTR);
38 virtual ~AbstractBoxItem();
41 inline AbstractBlock* getRefBlock() { return refBlock; }
42 inline int getWidth() { return boxWidth;}
43 inline int getHeight() { return boxHeight;}
44 inline int getTotalWidth() { return totalWidth;}
45 inline int getTotalHeight() { return totalHeight; }
46 inline QList<InterfaceItem* > getInterfaces() { return interfaces; }
47 inline InterfaceItem *getCurrentInterface() { return currentInterface; }
48 inline int getId(){ return id; }
49 inline GroupScene* getScene() { return (GroupScene*)(scene()); }
50 inline int getIfaceMargin() { return ifaceMargin; }
51 inline int getNameMargin() { return nameMargin; }
52 inline QPointF getOriginPoint() { return originPoint; }
53 inline int getMinimumBoxWidth() { return minimumBoxWidth; }
54 inline int getMinimumBoxHeight() { return minimumBoxHeight; }
57 void setRefBlock(AbstractBlock* _refBlock);
58 inline void setId(int _id){ id = _id; }
59 inline void setSelected(bool _selected) { selected = _selected; }
60 void setRstClkVisible(bool b);
61 void setWishboneVisible(bool b);
62 void setDimension(int x, int y);
63 inline void setWidth(int width) { boxWidth = width; }
64 inline void setHeight(int height) {boxHeight = height; }
65 inline void setCurrentInterface(InterfaceItem* iface) { currentInterface = iface; }
66 inline void setLock(int _lock) { lock = _lock; }
67 inline void lockPosition() { lock = lock | Position; }
68 inline void unlockPosition() { lock = (lock&Position)^lock; }
69 inline void lockDimension() { lock = lock | Dimension; }
70 inline void unlockDimension() { lock = (lock&Dimension)^lock; }
71 inline void lockInterfaces() { lock = lock | Interfaces; }
72 inline void unlockInterfaces() { lock = (lock&Interfaces)^lock; }
73 inline void lockNames() { lock = lock | Names; }
74 inline void unlockNames() { lock = (lock&Names)^lock; }
77 virtual bool isBoxItem();
78 virtual bool isGroupItem();
79 virtual bool isSourceItem();
80 inline bool isSelected() { return selected; }
81 inline bool isRstClkVisible(){ return rstClkVisible;}
82 inline bool isWishboneVisible(){ return wishboneVisible;}
83 bool isInterfaces(int orientation) const;
84 inline bool isPositionLock() { return (lock&Position)!=0?true:false; }
85 inline bool isDimensionLock() { return (lock&Dimension)!=0?true:false; }
86 inline bool isInterfacesLock() { return (lock&Interfaces)!=0?true:false; }
87 inline bool isNamesLock() { return (lock&Names)!=0?true:false; }
89 QRectF boundingRectInScene();
90 virtual void nameChanged() = 0; // called when an interface or box name have changed
91 void addInterfaceItem(InterfaceItem* i, bool resetPosition = false);
92 void removeInterfaceItem(InterfaceItem* i);
93 void resetInterfaceItemsPosition();
95 * \brief moveInterfaceTo
96 * \param pos the new position (in scene) of the interface
98 * This method is called when user moves an InterfaceItem.
99 * see BoxItem::mouseMoveEvent() and GroupItem::mouseMoveEvent()
101 void moveInterfaceItemTo(QPointF pos);
103 * \brief updateInterfacesAndConnections
105 * This method allows to recompute the absolute position of the interfaces of this box
106 * taking into account their relative position (see positionRatio atribute) in the width/height
107 * of the box border they are located on. It allows update the shape of all ConnectionItem
108 * connected to this box.
110 * CAUTION: this method supposes that before its call, a call to prepareGeometryChange() hase been
111 * done for the BoxItem that owns this InterfaceItem, so that the scene will readraw automatically
112 * the BoxItem. For the connections, the call to prepareGeometryChange() is done within setPath()
113 * that is called in this method. Thus, there is no need to call update() after the termination of
116 void updateInterfaceAndConnectionItems();
118 InterfaceItem *searchInterfaceItemByName(QString name);
119 InterfaceItem *searchInterfaceItemByRef(ConnectedInterface* ref);
120 InterfaceItem* getInterfaceItemFromCursor(qreal x, qreal y);
122 QRectF boundingRect() const;
125 Dispatcher *dispatcher;
127 QList<InterfaceItem*> interfaces;
128 /* NOTE : the reference block may be a FunctionalBlock or a GroupBlock, depending on the fact
129 that the real instace will be of FunctionalBlock or GroupBlock
131 AbstractBlock *refBlock;
133 InterfaceItem* currentInterface; // currently clicked interface in ItemEdition mode
135 BorderType currentBorder; // which border cursor is on
136 QPointF cursorPosition;
139 int boxWidth; // the width of the main box (without interface, title, ...)
140 int boxHeight; // the height of the main box (without interface, title, ...)
141 int minimumBoxWidth; // minimum width of the main box: may be recomputed if position/number of interface changes
142 int minimumBoxHeight; // minimum height of the main box: may be recomputed if position/number of interface changes
143 int totalWidth; // width and heigth taking into account interfaces,title, ...
145 int nameWidth; // the width of the box (group or block) name in Arial 10
146 int nameHeight; // the height of the name in Arial 10
147 int nameMargin; // the margin around each side of the name
148 int ifaceMargin; // the margin around each side of interfaces' name
149 QPointF originPoint; // the left-top point that is the origin of the bounding box, in the item coordinates
153 bool rstClkVisible; //! true if clock/reset interfaces are visible
154 bool wishboneVisible; //! true if wishbone interfaces are visible
156 QPointF currentPosition; // the start point for resize, i.e. the position of the lef-top corner of the box, in the scene coordinates
158 virtual void updateMinimumSize() = 0; // modify the minimum size
159 virtual bool updateGeometry(ChangeType type) = 0; // modify the originPoint and the total dimension
162 /* pure virtual method inherited from QGraphicsItem :
163 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) =0;
164 virtual QRectF boundingRect() const =0;
167 void createInterfaceItems(Parameters::Direction posInputs = Parameters::West, Parameters::Direction posOutputs = Parameters::East, Parameters::Direction posBidirs = Parameters::South);
168 int nbInterfacesByOrientation(int orientation);
171 #endif // __ABSTRACTBOXITEM_H__