void ResizeCommand::makeHierarchySnapshot(NodeElement *node, QMap<Id, QRectF> &target) { // Here we remembering all binded items geometries. // Binded items are just element`s hierarchy: // all parents and children (siblings are not considered) makeChildrenSnapshot(node, target); for (NodeElement *parentElement = node; parentElement; parentElement = dynamic_cast<NodeElement *>(parentElement->parentItem())) { target.insert(parentElement->id(), geometryOf(parentElement)); addEdges(parentElement); } }
void SceneGridHandler::drawGuides() { const int drift = 5; // A dirft for scene not to resize from guide lines. const QPointF nodeScenePos = mNode->scenePos(); const QRectF contentsRect = mNode->contentsRect(); const QRectF sceneRect = mNode->scene()->sceneRect().adjusted(drift, drift, -drift, -drift); deleteGuides(); QList<QGraphicsItem *> list = getAdjancedNodes(); qreal myX1 = nodeScenePos.x() + contentsRect.x(); qreal myY1 = nodeScenePos.y() + contentsRect.y(); qreal myX2 = myX1 + contentsRect.width(); qreal myY2 = myY1 + contentsRect.height(); for (QGraphicsItem *graphicsItem : list) { NodeElement *item = dynamic_cast<NodeElement *>(graphicsItem); if (item == nullptr || item->parentItem() != nullptr || item == mNode) { continue; } const QPointF point = item->scenePos(); const QRectF contents = item->contentsRect(); const qreal pointX1 = point.x() + contents.x() - spacing; const qreal pointY1 = point.y() + contents.y() - spacing; const qreal pointX2 = pointX1 + contents.width() + 2 * spacing; const qreal pointY2 = pointY1 + contents.height() + 2 * spacing; if (pointX1 != myX1 || pointY1 != myY1) { const qreal deltaY1 = qAbs(pointY1 - myY1); const qreal deltaY2 = qAbs(pointY2 - myY2); const qreal deltaX1 = qAbs(pointX1 - myX1); const qreal deltaX2 = qAbs(pointX2 - myX2); buildLineY(deltaY1, pointY1, 0, myY1, myY2, sceneRect); buildLineY(deltaY2, pointY2, contentsRect.height(), myY1, myY2, sceneRect); buildLineX(deltaX1, pointX1, 0, myX1, myX2, sceneRect); buildLineX(deltaX2, pointX2, contentsRect.width(), myX1, myX2, sceneRect); buildLineY(qAbs(pointY1 - myY2), pointY1, contentsRect.height(), myY1, myY2, sceneRect); buildLineX(qAbs(pointX1 - myX2), pointX1, contentsRect.width(), myX1, myX2, sceneRect); buildLineY(qAbs(pointY2 - myY1), pointY2, 0, myY1, myY2, sceneRect); buildLineX(qAbs(pointX2 - myX1), pointX2, 0, myX1, myX2, sceneRect); } } }
void SceneGridHandler::drawGuides() { QPointF const nodeScenePos = mNode->scenePos(); QRectF const contentsRect = mNode->contentsRect(); QRectF const sceneRect = mNode->scene()->sceneRect(); delUnusedLines(); QList<QGraphicsItem *> list = getAdjancedNodes(); qreal myX1 = nodeScenePos.x() + contentsRect.x(); qreal myY1 = nodeScenePos.y() + contentsRect.y(); qreal myX2 = myX1 + contentsRect.width(); qreal myY2 = myY1 + contentsRect.height(); foreach (QGraphicsItem *graphicsItem, list) { NodeElement *item = dynamic_cast<NodeElement *>(graphicsItem); if (item == NULL || item->parentItem() != NULL || item == mNode) { continue; } QPointF const point = item->scenePos(); QRectF const contents = item->contentsRect(); qreal const pointX1 = point.x() + contents.x() - spacing; qreal const pointY1 = point.y() + contents.y() - spacing; qreal const pointX2 = pointX1 + contents.width() + 2 * spacing; qreal const pointY2 = pointY1 + contents.height() + 2 * spacing; if (pointX1 != myX1 || pointY1 != myY1) { qreal const deltaY1 = qAbs(pointY1 - myY1); qreal const deltaY2 = qAbs(pointY2 - myY2); qreal const deltaX1 = qAbs(pointX1 - myX1); qreal const deltaX2 = qAbs(pointX2 - myX2); buildLineY(deltaY1, pointY1, 0, myY1, myY2, sceneRect); buildLineY(deltaY2, pointY2, contentsRect.height(), myY1, myY2, sceneRect); buildLineX(deltaX1, pointX1, 0, myX1, myX2, sceneRect); buildLineX(deltaX2, pointX2, contentsRect.width(), myX1, myX2, sceneRect); buildLineY(qAbs(pointY1 - myY2), pointY1, contentsRect.height(), myY1, myY2, sceneRect); buildLineX(qAbs(pointX1 - myX2), pointX1, contentsRect.width(), myX1, myX2, sceneRect); buildLineY(qAbs(pointY2 - myY1), pointY2, 0, myY1, myY2, sceneRect); buildLineX(qAbs(pointX2 - myX1), pointX2, 0, myX1, myX2, sceneRect); } }
QList<NodeElement *> ClipboardHandler::getNodesForCopying() { QList<NodeElement *> nodes; for (QGraphicsItem * const item : mScene.selectedItems()) { NodeElement *node = dynamic_cast<NodeElement *>(item); if (node && !mScene.selectedItems().contains(node->parentItem())) { nodes << node; } } for (NodeElement * const node : nodes) { addChildren(node, nodes); } return nodes; }
void ResizeCommand::resizeHierarchy(QMap<Id, QRectF> const &snapshot) { for (const Id &id : snapshot.keys()) { NodeElement *element = nodeById(id); if (!element->parentItem()) { resizeTree(snapshot, id); } } // Updating linker position if (mScene->selectedItems().size() == 1) { QGraphicsItem *selectedItem = mScene->selectedItems()[0]; NodeElement *selectedNode = dynamic_cast<NodeElement *>(selectedItem); if (selectedNode) { selectedNode->setVisibleEmbeddedLinkers(true); } } }
void NodeElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (dynamic_cast<NodeElement *>(scene()->mouseGrabberItem()) == this) { ungrabMouse(); } if (event->button() == Qt::RightButton) { event->accept(); return; } deleteGuides(); storeGeometry(); if (scene() && (scene()->selectedItems().size() == 1) && isSelected()) { setVisibleEmbeddedLinkers(true); } if (mDragState == None) { Element::mouseReleaseEvent(event); } EditorViewScene *evScene = dynamic_cast<EditorViewScene *>(scene()); commands::InsertIntoEdgeCommand *insertCommand = new commands::InsertIntoEdgeCommand( *evScene, mModels, id(), id(), Id::rootId(), event->scenePos(), boundingRect().bottomRight(), false); bool shouldProcessResize = true; // we should use mHighlightedNode to determine if there is a highlighted node // insert current element into them and set mHighlightedNode to nullptr // but because of mouseRelease twice triggering we can't do it // This may cause more bugs if (flags() & ItemIsMovable) { if (mHighlightedNode) { NodeElement *newParent = mHighlightedNode; Element *insertBefore = mHighlightedNode->getPlaceholderNextElement(); mHighlightedNode->erasePlaceholder(false); // commented because of bug with double event sending (see #204) // mHighlightedNode = nullptr; QPointF newPos = mapToItem(newParent, mapFromScene(scenePos())); AbstractCommand *parentCommand = changeParentCommand(newParent->id(), newPos); mController->execute(parentCommand); // Position change already processed in change parent command shouldProcessResize = parentCommand == nullptr; setPos(newPos); if (insertBefore) { mGraphicalAssistApi.stackBefore(id(), insertBefore->id()); } newParent->resize(); while (newParent) { newParent->mContents = newParent->mContents.normalized(); newParent->storeGeometry(); newParent = dynamic_cast<NodeElement*>(newParent->parentItem()); } } else { AbstractCommand *parentCommand = changeParentCommand(evScene->rootItemId(), scenePos()); mController->execute(parentCommand); // Position change already processed in change parent command shouldProcessResize = parentCommand == nullptr; } } for (EdgeElement* edge : mEdgeList) { edge->layOut(); if (SettingsManager::value("ActivateGrid").toBool()) { edge->alignToGrid(); } } if (shouldProcessResize && mResizeCommand) { mResizeCommand->addPostAction(insertCommand); endResize(); } updateBySelection(); mDragState = None; }