29 #include "graphicsportitem.h"
30 #include "graphicslinkitem.h"
31 #include "graphicscomponentitem.h"
32 #include "graphicsinvocationitem.h"
33 #include "invocationdialog.h"
34 #include "sheetview.h"
35 #include <arcs/arcssheet.h>
37 #include <QGraphicsSceneMouseEvent>
39 #include <QGraphicsScene>
43 #include <QMetaObject>
44 #include <QMessageBox>
45 #include <QStyleOptionGraphicsItem>
47 #include <QInputDialog>
49 GraphicsPortItem::GraphicsPortItem(QGraphicsItem *parent)
50 : QGraphicsPathItem(parent)
52 markedForDeletion=
false;
53 linkInConstruction = 0;
55 #if QT_VERSION >= 0x050000
56 setAcceptHoverEvents(
true);
58 setAcceptsHoverEvents(
true);
60 setFlag(QGraphicsItem::ItemIsSelectable);
61 setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
65 br.setStyle(Qt::SolidPattern);
66 br.setColor(Qt::white);
72 pp.addRect(-5,-5,10,10);
82 setAcceptHoverEvents(
true);
83 rectOperation =
new QGraphicsRectItem(
this);
84 textOperation =
new QGraphicsSimpleTextItem(rectOperation);
85 rectOperation->setVisible(
false);
86 rectOperation->setRect(textOperation->boundingRect());
87 rectOperation->setBrush(QBrush(Qt::yellow));
92 GraphicsPortItem::~GraphicsPortItem()
97 for(i=0; i < links.count(); i++)
99 if (markedForDeletion)
100 links[i]->markForDeletion();
105 if (markedForDeletion)
107 #if QT_VERSION >= 0x050000
108 QList<QGraphicsItem*> items = childItems();
110 QList<QGraphicsItem*> items = children();
112 for (i=0; i < items.count(); i++ )
114 if (items[i]->type() == GraphicsInvocationItem::Type)
115 dynamic_cast<GraphicsInvocationItem*>(items[i])->markForDeletion();
122 parentComponent->removePort(textOperation->text());
126 void GraphicsPortItem::updateView()
128 textOperation->setText(operationName);
129 rectOperation->setRect(textOperation->boundingRect().adjusted(-2,-2,2,2));
130 QSizeF s = rectOperation->rect().size();
132 if (operationType == Slot)
133 rectOperation->setPos(-s.width()-15,-s.height() -10);
135 rectOperation->setPos(15,-s.height()-10);
139 void GraphicsPortItem::hoverEnterEvent ( QGraphicsSceneHoverEvent * )
144 void GraphicsPortItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * )
149 void GraphicsPortItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
153 if (operationType== Slot)
154 linkInConstruction->setDestination(
this);
156 linkInConstruction->setSource(
this);
158 QGraphicsPathItem::mousePressEvent(event);
162 void GraphicsPortItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
164 if (linkInConstruction)
166 linkInConstruction->setCurrentPoint(event->pos());
173 void GraphicsPortItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
177 QList<QGraphicsItem*> items = scene()->items(event->scenePos(), Qt::IntersectsItemBoundingRect, Qt::DescendingOrder);
178 QGraphicsItem* item = 0;
179 for (
int i=0; i < items.count(); i++)
181 if (items[i]->type() == GraphicsPortItem::Type)
186 if (item && item !=
this)
191 if (portItem->getType() != this->getType())
193 if ( portItem->getType() == Slot)
194 linkInConstruction->setDestination(portItem);
196 linkInConstruction->setSource(portItem);
199 if (!QMetaObject::checkConnectArgs(
200 qPrintable(linkInConstruction->getDestination()->getName()),
201 qPrintable(linkInConstruction->getSource()->getName()) ) )
203 if ( QMessageBox::question(0,
"Connect argument mismatch",
204 "Arguments from your signal and your slot mismatch. Do you want to continue ?",
205 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
207 delete linkInConstruction;
208 linkInConstruction = 0;
213 linkInConstruction->finalize();
214 links.append(linkInConstruction);
215 portItem->links.append(linkInConstruction);
221 QGraphicsPathItem::mouseReleaseEvent(event);
227 if (!linkInConstruction->isFinalized())
229 delete linkInConstruction;
230 linkInConstruction = 0;
236 void GraphicsPortItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
238 if (operationType == Signal)
241 menu.addAction(
"Add invocation");
244 QAction* selectedAction = menu.exec(event->screenPos());
255 if (dialog.exec() == QDialog::Accepted)
262 ARCSSheet& sheet = sheetView->getSheet();
264 switch(dialog.getInvocationType())
266 case GraphicsInvocationItem::Pre:
268 operationName,dialog.getTypeName(),dialog.getValue());
270 case GraphicsInvocationItem::Post:
272 operationName,dialog.getTypeName(),dialog.getValue());
274 case GraphicsInvocationItem::Cleanup:
276 operationName,dialog.getTypeName(),dialog.getValue());
284 std::cout <<
"invocation added" << std::endl;
288 QVariant GraphicsPortItem::itemChange(GraphicsItemChange change,
const QVariant &value)
290 if (change == ItemChildRemovedChange)
293 return QGraphicsItem::itemChange(change,value);
297 void GraphicsPortItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
299 QStyleOptionGraphicsItem myOptions(*option);
300 if (myOptions.state & (QStyle::State_Selected))
302 QPen myPen(Qt::darkRed);
303 myPen.setCapStyle(Qt::RoundCap);
306 myOptions.state = myOptions.state ^ QStyle::State_Selected ;
312 QGraphicsPathItem::paint(painter,& myOptions, widget );
315 void GraphicsPortItem::setName(QString s)
322 void GraphicsPortItem::fireUpdate()
325 for (
int i=0; i< links.count(); i++)
334 links.removeAll(item);
ARCSInit & addCleanup(QString dst, QString slt, QString t, QString val)
Adds a cleanup invocation to the sheet structure.
ARCSInit & addPreconnect(QString dst, QString slt, QString t, QString val)
Adds a pre-connection initialisation to the sheet structure.
Desribes an initialization over a component.
QVariant getProperty(QString name)
Gets a meta-property from this component.
ARCSInit & addPostconnect(QString dst, QString slt, QString t, QString val)
Adds a post-connection initialisation to the sheet structure.
Maintains connections between objects.