29 #include "graphicsinvocationitem.h"
31 #include <QStyleOptionGraphicsItem>
32 #include <QGraphicsRectItem>
33 #include <QGraphicsSimpleTextItem>
35 #include "sheetview.h"
38 QGraphicsPathItem(parent), init(i)
40 #if QT_VERSION >= 0x050000
41 setAcceptHoverEvents(
true);
43 setAcceptsHoverEvents(
true);
45 setFlag(ItemIsSelectable,
true);
46 invocationType = itype;
49 markedForDeletion =
false;
50 rectInvocation =
new QGraphicsRectItem(
this);
51 textInvocation =
new QGraphicsSimpleTextItem(rectInvocation);
52 textNumber =
new QGraphicsSimpleTextItem(
this);
53 rectInvocation->setVisible(
false);
54 QString invocationTypeName;
56 switch(invocationType)
59 invocationTypeName =
"Pre-connection" ;
62 invocationTypeName =
"Post-connection" ;
65 invocationTypeName =
"Clean-up invocation";
70 textInvocation->setText(invocationTypeName +
71 "\nType:\"" + init.getValueType() +
72 "\";\nValue:\"" + init.getValueString() +
"\"");
73 rectInvocation->setBrush(QBrush(Qt::lightGray));
74 rectInvocation->setRect(textInvocation->boundingRect().adjusted(-2,-2,2,2));
75 QSizeF s = rectInvocation->rect().size();
76 rectInvocation->setPos(-s.width()-15,10);
80 GraphicsInvocationItem::~GraphicsInvocationItem()
83 if (markedForDeletion)
89 std::cout <<
"We shall remove this initialisation from sheet" << std::endl;
91 switch(invocationType)
94 view->getSheet().removePreconnect(init);
97 view->getSheet().removePostconnect(init);
100 view->getSheet().removeCleanup(init);
108 void GraphicsInvocationItem::drawPath()
112 switch(invocationType)
116 QBrush br(Qt::white);
131 QBrush br(Qt::black);
136 pp.addEllipse(QPointF(-15,0),5,5);
142 QBrush br(Qt::white);
146 pp.addEllipse(QPointF(-15,0),5,5);
147 pp.moveTo(-11.47,3.03);
148 pp.lineTo(-18.53,-3.03);
149 pp.moveTo(-18.53,3.03);
150 pp.lineTo(-11.47,-3.03);
158 void GraphicsInvocationItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
160 QStyleOptionGraphicsItem myOptions(*option);
161 if (myOptions.state & (QStyle::State_Selected))
165 myPen.setColor(Qt::darkRed);
167 myOptions.state = myOptions.state ^ QStyle::State_Selected ;
173 QGraphicsPathItem::paint(painter,& myOptions, widget );
177 void GraphicsInvocationItem::hoverEnterEvent(QGraphicsSceneHoverEvent *)
184 switch(invocationType)
187 idx = view->getSheet().getPreconnectIndex(init);
190 idx = view->getSheet().getPostconnectIndex(init);
193 idx = view->getSheet().getCleanupIndex(init);
197 textNumber->setText(QString::number(idx));
198 QFont font = textNumber->font();
200 textNumber->setFont(font);
201 textNumber->setBrush(QBrush(Qt::darkMagenta));
202 QSizeF s = textNumber->boundingRect().size();
203 textNumber->setPos(-s.width()-25,-s.height()/2);
205 textNumber->setVisible(
true);
206 rectInvocation->setVisible(
true);
209 void GraphicsInvocationItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
211 textNumber->setVisible(
false);
212 rectInvocation->setVisible(
false);
Desribes an initialization over a component.