Пример #1
0
void
NodeGraph::moveSelectedNodesBy(bool shiftdown,
                               bool controlDown,
                               const QPointF& lastMousePosScene,
                               const QPointF& newPos,
                               const QRectF& visibleSceneR,
                               bool userEdit)
{
    if ( _imp->_selection.empty() ) {
        return;
    }


    //Get the nodes to move, taking into account the backdrops
    std::list<std::pair<NodeGuiPtr, bool> > nodesToMove;
    for (NodesGuiList::iterator it = _imp->_selection.begin();
            it != _imp->_selection.end(); ++it) {
        const NodeGuiPtr& node = *it;
        nodesToMove.push_back( std::make_pair(node, false) );

        std::map<NodeGuiPtr, NodesGuiList>::iterator foundBd = _imp->_nodesWithinBDAtPenDown.find(*it);
        if ( !controlDown && ( foundBd != _imp->_nodesWithinBDAtPenDown.end() ) ) {
            for (NodesGuiList::iterator it2 = foundBd->second.begin();
                    it2 != foundBd->second.end(); ++it2) {
                ///add it only if it's not already in the list
                bool found = false;
                for (std::list<std::pair<NodeGuiPtr, bool> >::iterator it3 = nodesToMove.begin();
                        it3 != nodesToMove.end(); ++it3) {
                    if (it3->first == *it2) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    nodesToMove.push_back( std::make_pair(*it2, true) );
                }
            }
        }
    }

    //The delta
    double dxScene = newPos.x() - lastMousePosScene.x();
    double dyScene = newPos.y() - lastMousePosScene.y();


    //Move all nodes
    bool deltaSet = false;
    for (std::list<std::pair<NodeGuiPtr, bool> >::iterator it = nodesToMove.begin();
            it != nodesToMove.end(); ++it) {
        //The current position
        QPointF pos = it->first->getPos_mt_safe();

        //if ignoreMagnet == true, we do not snap nodes to horizontal/vertical positions
        bool ignoreMagnet = it->second || nodesToMove.size() > 1;
        it->first->refreshPosition(pos.x() + dxScene, pos.y() + dyScene, ignoreMagnet, newPos);

        //The new position
        QPointF newNodePos = it->first->getPos_mt_safe();
        if (!ignoreMagnet) {
            //Magnet only works when selection is only for a single node
            //Adjust the delta since mouse press by the new position after snapping
            assert(nodesToMove.size() == 1);
            _imp->_deltaSinceMousePress.rx() += newNodePos.x() - pos.x();
            _imp->_deltaSinceMousePress.ry() += newNodePos.y() - pos.y();
            deltaSet = true;
        }
    }

    if (!deltaSet) {
        _imp->_deltaSinceMousePress.rx() += dxScene;
        _imp->_deltaSinceMousePress.ry() += dyScene;
    }

    if (!userEdit) {
        //For !userEdit do not do auto-scroll and connections hints
        return;
    }

    //Start auto-scolling if nearby the edges
    checkAndStartAutoScrollTimer(newPos);

    //Set the hand cursor
    _imp->cursorSet = true;
    setCursor(Qt::ClosedHandCursor);

    //The lines below are trying to
    if (_imp->_selection.size() != 1) {
        return;
    }

    checkForHints(shiftdown, controlDown, _imp->_selection.front(), visibleSceneR);
} // NodeGraph::moveSelectedNodesBy
Пример #2
0
void
NodeGraph::moveSelectedNodesBy(bool shiftdown,
                               bool controlDown,
                               const QPointF& lastMousePosScene,
                               const QPointF& newPos,
                               const QRectF& visibleSceneR,
                               bool userEdit)
{
    if ( _imp->_selection.empty() ) {
        return;
    }


    //Get the nodes to move, taking into account the backdrops
    bool ignoreMagnet = false;
    std::set<NodeGuiPtr> nodesToMove;
    for (NodesGuiWList::iterator it = _imp->_selection.begin();
         it != _imp->_selection.end(); ++it) {
        NodeGuiPtr node = it->lock();
        if (!node) {
            continue;
        }
        nodesToMove.insert(node);

        std::map<NodeGuiPtr, NodesGuiList>::iterator foundBd = _imp->_nodesWithinBDAtPenDown.find(node);
        if ( !controlDown && ( foundBd != _imp->_nodesWithinBDAtPenDown.end() ) ) {
            ignoreMagnet = true; // we move a backdrop, ignore magnet
            for (NodesGuiList::iterator it2 = foundBd->second.begin();
                 it2 != foundBd->second.end(); ++it2) {
                ///add it only if it's not already in the list
                nodesToMove.insert(*it2);

            }
        }
    }

    if (!ignoreMagnet && nodesToMove.size() > 1) {
        ignoreMagnet = true;
    }

    //The delta
    double dxScene = newPos.x() - lastMousePosScene.x();
    double dyScene = newPos.y() - lastMousePosScene.y();


    //Move all nodes
    bool deltaSet = false;
    for (std::set<NodeGuiPtr>::iterator it = nodesToMove.begin();
         it != nodesToMove.end(); ++it) {
        //The current position
        QPointF pos = (*it)->pos();

        //if ignoreMagnet == true, we do not snap nodes to horizontal/vertical positions
        (*it)->refreshPosition(pos.x() + dxScene, pos.y() + dyScene, ignoreMagnet, newPos);

        //The new position
        QPointF newNodePos = (*it)->pos();
        if (!ignoreMagnet) {
            //Magnet only works when selection is only for a single node
            //Adjust the delta since mouse press by the new position after snapping
            assert(nodesToMove.size() == 1);
            _imp->_deltaSinceMousePress.rx() += newNodePos.x() - pos.x();
            _imp->_deltaSinceMousePress.ry() += newNodePos.y() - pos.y();
            deltaSet = true;
        }
    }

    if (!deltaSet) {
        _imp->_deltaSinceMousePress.rx() += dxScene;
        _imp->_deltaSinceMousePress.ry() += dyScene;
    }

    if (!userEdit) {
        //For !userEdit do not do auto-scroll and connections hints
        return;
    }

    //Start auto-scolling if nearby the edges
    checkAndStartAutoScrollTimer(newPos);

    //The lines below are trying to
    if (_imp->_selection.size() != 1) {
        return;
    }

    checkForHints(shiftdown, controlDown, _imp->_selection.front().lock(), visibleSceneR);
} // NodeGraph::moveSelectedNodesBy