Esempio n. 1
0
bool Connection::areInspectorsValid() const
{
    return areNodesValid() &&
        gscene()->getInspector(startNode()) &&
        (drag_state != CONNECTED ||
         gscene()->getInspector(endNode()));
}
Esempio n. 2
0
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();
}
Esempio n. 3
0
NodeInspector* Connection::endInspector() const
{
    Q_ASSERT(drag_state == CONNECTED);
    NodeInspector* i = gscene()->getInspector(endNode());
    Q_ASSERT(i);
    return i;
}
Esempio n. 4
0
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();
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
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;
    }
}
Esempio n. 7
0
void Connection::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (drag_state == CONNECTED)
        return;

    drag_pos = event->pos();
    if (snapping)
        updateSnap();

    gscene()->raiseInspectorAt(drag_pos);

    checkDragTarget();
    prepareGeometryChange();
}
Esempio n. 8
0
NodeInspector* Connection::startInspector() const
{
    NodeInspector* i = gscene()->getInspector(startNode());
    Q_ASSERT(i);
    return i;
}