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); } }