Example #1
0
void NodeList_sV::moveHandle(const NodeHandle_sV *handle, Node_sV relPos)
{
    Node_sV otherNode;
    Node_sV *currentNode = const_cast<Node_sV*>(handle->parentNode());

    int nodeIndex = indexOf(handle->parentNode());
    Q_ASSERT(nodeIndex >= 0);
    Q_ASSERT(nodeIndex < m_list.size());

    if (handle == &currentNode->leftNodeHandle()) {
        //  o------[]
        if (nodeIndex > 0) {
            // Ensure that it does not overlap with the left node's handle (injectivity)
            otherNode = m_list.at(nodeIndex-1);
            qDebug() << "Left node: " << otherNode;
            qDebug() << "Right node: " << currentNode;
            qDebug() << "Before overlapping check: " << relPos;
            relPos.setX(qMax(relPos.x(), -(currentNode->x() - otherNode.x() - otherNode.rightNodeHandle().x())));
            qDebug() << "After overlapping check: " << relPos;
            qDebug() << "Space left: " << currentNode->x() + relPos.x() - (otherNode.x() + otherNode.rightNodeHandle().x());
        }
        // Additionally the handle has to stay on the left of its node
        relPos.setX(qMin(relPos.x(), .0));

        currentNode->setLeftNodeHandle(relPos.x(), relPos.y());

    } else {
        // []-------o
        if (nodeIndex+1 < m_list.size()) {
            otherNode = m_list.at(nodeIndex+1);
            relPos.setX(qMin(relPos.x(), otherNode.x() - currentNode->x() + otherNode.leftNodeHandle().x()));
        }
        relPos.setX(qMax(relPos.x(), .0));

        currentNode->setRightNodeHandle(relPos.x(), relPos.y());
    }
    validate();
}