static void updateAnchorLinePoints(QPointF *firstPoint, QPointF *secondPoint, const AnchorLine &anchorLine) { QRectF boundingRectangle = anchorLine.qmlItemNode().instanceBoundingRect().adjusted(0., 0., 1., 1.); switch (anchorLine.type()) { case AnchorLine::Top: *firstPoint = boundingRectangle.topLeft(); *secondPoint = boundingRectangle.topRight(); break; case AnchorLine::Bottom: *firstPoint = boundingRectangle.bottomLeft(); *secondPoint = boundingRectangle.bottomRight(); break; case AnchorLine::Left: *firstPoint = boundingRectangle.topLeft(); *secondPoint = boundingRectangle.bottomLeft(); break; case AnchorLine::Right: *firstPoint = boundingRectangle.topRight(); *secondPoint = boundingRectangle.bottomRight(); break; default: break; } *firstPoint = anchorLine.qmlItemNode().instanceSceneTransform().map(*firstPoint); *secondPoint = anchorLine.qmlItemNode().instanceSceneTransform().map(*secondPoint); }
static bool checkForHorizontalCycleRecusive(const QmlAnchors &anchors, QList<QmlItemNode> &visitedItems) { visitedItems.append(anchors.qmlItemNode()); if (anchors.instanceHasAnchor(AnchorLineLeft)) { AnchorLine leftAnchorLine = anchors.instanceAnchor(AnchorLineLeft); if (visitedItems.contains(leftAnchorLine.qmlItemNode()) || checkForHorizontalCycleRecusive(leftAnchorLine.qmlItemNode().anchors(), visitedItems)) return true; } if (anchors.instanceHasAnchor(AnchorLineRight)) { AnchorLine rightAnchorLine = anchors.instanceAnchor(AnchorLineRight); if (visitedItems.contains(rightAnchorLine.qmlItemNode()) || checkForHorizontalCycleRecusive(rightAnchorLine.qmlItemNode().anchors(), visitedItems)) return true; } if (anchors.instanceHasAnchor(AnchorLineHorizontalCenter)) { AnchorLine horizontalCenterAnchorLine = anchors.instanceAnchor(AnchorLineHorizontalCenter); if (visitedItems.contains(horizontalCenterAnchorLine.qmlItemNode()) || checkForHorizontalCycleRecusive(horizontalCenterAnchorLine.qmlItemNode().anchors(), visitedItems)) return true; } return false; }
static bool checkForVerticalCycleRecusive(const QmlAnchors &anchors, QList<QmlItemNode> &visitedItems) { visitedItems.append(anchors.qmlItemNode()); if (anchors.instanceHasAnchor(AnchorLineTop)) { AnchorLine topAnchorLine = anchors.instanceAnchor(AnchorLineTop); if (visitedItems.contains(topAnchorLine.qmlItemNode()) || checkForVerticalCycleRecusive(topAnchorLine.qmlItemNode().anchors(), visitedItems)) return true; } if (anchors.instanceHasAnchor(AnchorLineBottom)) { AnchorLine bottomAnchorLine = anchors.instanceAnchor(AnchorLineBottom); if (visitedItems.contains(bottomAnchorLine.qmlItemNode()) || checkForVerticalCycleRecusive(bottomAnchorLine.qmlItemNode().anchors(), visitedItems)) return true; } if (anchors.instanceHasAnchor(AnchorLineVerticalCenter)) { AnchorLine verticalCenterAnchorLine = anchors.instanceAnchor(AnchorLineVerticalCenter); if (visitedItems.contains(verticalCenterAnchorLine.qmlItemNode()) || checkForVerticalCycleRecusive(verticalCenterAnchorLine.qmlItemNode().anchors(), visitedItems)) return true; } return false; }
void AnchorIndicatorGraphicsItem::updateAnchorIndicator(const AnchorLine &sourceAnchorLine, const AnchorLine targetAnchorLine) { m_sourceAnchorLineType = sourceAnchorLine.type(); m_targetAnchorLineType = targetAnchorLine.type(); m_startPoint = createAnchorPoint(sourceAnchorLine.qmlItemNode(), sourceAnchorLine.type()); if (targetAnchorLine.qmlItemNode() == sourceAnchorLine.qmlItemNode().instanceParentItem()) m_endPoint = createParentAnchorPoint(targetAnchorLine.qmlItemNode(), targetAnchorLine.type(), sourceAnchorLine.qmlItemNode()); else m_endPoint = createAnchorPoint(targetAnchorLine.qmlItemNode(), targetAnchorLine.type()); m_firstControlPoint = createControlPoint(m_startPoint, sourceAnchorLine.type(), m_endPoint); m_secondControlPoint = createControlPoint(m_endPoint, targetAnchorLine.type(), m_startPoint); updateAnchorLinePoints(&m_sourceAnchorLineFirstPoint, &m_sourceAnchorLineSecondPoint, sourceAnchorLine); updateAnchorLinePoints(&m_targetAnchorLineFirstPoint, &m_targetAnchorLineSecondPoint, targetAnchorLine); updateBoundingRect(); update(); }