bool Connection::areInspectorsValid() const { return areNodesValid() && gscene()->getInspector(startNode()) && (drag_state != CONNECTED || gscene()->getInspector(endNode())); }
void Connection::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { QGraphicsObject::mouseReleaseEvent(event); if (drag_state == CONNECTED) return; ungrabMouse(); clearFocus(); setFlag(QGraphicsItem::ItemIsFocusable, false); InputPort* target = gscene()->getInputPortAt(endPos()); Datum* datum = target ? target->getDatum() : NULL; if (target && datum->acceptsLink(link)) { datum->addLink(link); drag_state = CONNECTED; connect(endInspector(), &NodeInspector::moved, this, &Connection::onInspectorMoved); connect(endInspector(), &NodeInspector::hiddenChanged, this, &Connection::onHiddenChanged); App::instance()->pushStack(new UndoAddLinkCommand(link)); } else { link->deleteLater(); } prepareGeometryChange(); }
NodeInspector* Connection::endInspector() const { Q_ASSERT(drag_state == CONNECTED); NodeInspector* i = gscene()->getInspector(endNode()); Q_ASSERT(i); return i; }
void Connection::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { QGraphicsObject::mouseReleaseEvent(event); if (drag_state == CONNECTED) return; ungrabMouse(); clearFocus(); setFlag(QGraphicsItem::ItemIsFocusable, false); InputPort* t = gscene()->getInputPortAt(endPos()); Datum* datum = target ? target->getDatum() : NULL; if (t && datum->acceptsLink(source->getDatum())) { target = t; t->install(this); datum->installLink(source->getDatum()); drag_state = CONNECTED; App::instance()->pushStack( new UndoAddLinkCommand(source->getDatum(), datum)); onPortsMoved(); emit(changed()); } else { deleteLater(); } prepareGeometryChange(); }
void Connection::checkDragTarget() { target = gscene()->getInputPortAt(endPos()); if (target && target->getDatum()->acceptsLink(link)) drag_state = VALID; else if (target) drag_state = INVALID; else drag_state = NONE; }
void Connection::updateSnap() { if (Port* p = gscene()->getInputPortNear(drag_pos, link)) { has_snap_pos = true; snap_pos = p->mapToScene(p->boundingRect().center()); } else { has_snap_pos = false; } }
void Connection::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (drag_state == CONNECTED) return; drag_pos = event->pos(); if (snapping) updateSnap(); gscene()->raiseInspectorAt(drag_pos); checkDragTarget(); prepareGeometryChange(); }
NodeInspector* Connection::startInspector() const { NodeInspector* i = gscene()->getInspector(startNode()); Q_ASSERT(i); return i; }