foreach (FormEditorItem *formEditorItem, itemList) { if (formEditorItem == m_formEditorItem) { QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode(); if (!sourceQmlItemNode.modelNode().isRootNode()) { QmlAnchors qmlAnchors = formEditorItem->qmlItemNode().anchors(); if (qmlAnchors.modelHasAnchor(AnchorLine::Top)) { if (m_indicatorTopShape.isNull()) m_indicatorTopShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorTopShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Top), qmlAnchors.modelAnchor(AnchorLine::Top)); } else { delete m_indicatorTopShape; } if (qmlAnchors.modelHasAnchor(AnchorLine::Bottom)) { if (m_indicatorBottomShape.isNull()) m_indicatorBottomShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorBottomShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Bottom), qmlAnchors.modelAnchor(AnchorLine::Bottom)); } else { delete m_indicatorBottomShape; } if (qmlAnchors.modelHasAnchor(AnchorLine::Left)) { if (m_indicatorLeftShape.isNull()) m_indicatorLeftShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorLeftShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Left), qmlAnchors.modelAnchor(AnchorLine::Left)); } else { delete m_indicatorLeftShape; } if (qmlAnchors.modelHasAnchor(AnchorLine::Right)) { if (m_indicatorRightShape.isNull()) m_indicatorRightShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorRightShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Right), qmlAnchors.modelAnchor(AnchorLine::Right)); } else { delete m_indicatorRightShape; } } return; } }
AnchorLine QmlAnchors::instanceAnchor(AnchorLine::Type sourceAnchorLine) const { QPair<QString, NodeInstance> targetAnchorLinePair; if (qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLine::Fill)) { targetAnchorLinePair = qmlItemNode().nodeInstance().anchor("anchors.fill"); targetAnchorLinePair.first = lineTypeToString(sourceAnchorLine); } else if (qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLine::Center)) { targetAnchorLinePair = qmlItemNode().nodeInstance().anchor("anchors.centerIn"); targetAnchorLinePair.first = lineTypeToString(sourceAnchorLine); } else { targetAnchorLinePair = qmlItemNode().nodeInstance().anchor(anchorPropertyName(sourceAnchorLine)); } AnchorLine::Type targetAnchorLine = propertyNameToLineType(targetAnchorLinePair.first); if (targetAnchorLine == AnchorLine::Invalid ) return AnchorLine(); Q_ASSERT(targetAnchorLinePair.second.isValid()); return AnchorLine(QmlItemNode(qmlItemNode().nodeForInstance(targetAnchorLinePair.second)), targetAnchorLine); }
AnchorLine QmlAnchors::instanceAnchor(AnchorLine::Type sourceAnchorLine) const { QPair<QString, qint32> targetAnchorLinePair; if (qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLine::Fill)) { targetAnchorLinePair = qmlItemNode().nodeInstance().anchor("anchors.fill"); targetAnchorLinePair.first = lineTypeToString(sourceAnchorLine); // TODO: looks wrong } else if (qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLine::Center)) { targetAnchorLinePair = qmlItemNode().nodeInstance().anchor("anchors.centerIn"); targetAnchorLinePair.first = lineTypeToString(sourceAnchorLine); } else { targetAnchorLinePair = qmlItemNode().nodeInstance().anchor(anchorPropertyName(sourceAnchorLine)); } AnchorLine::Type targetAnchorLine = propertyNameToLineType(targetAnchorLinePair.first); if (targetAnchorLine == AnchorLine::Invalid ) return AnchorLine(); if (targetAnchorLinePair.second < 0) //there might be no node instance for the parent return AnchorLine(); return AnchorLine(QmlItemNode(qmlItemNode().nodeForInstance(qmlItemNode().qmlModelView()->nodeInstanceView()->instanceForId(targetAnchorLinePair.second))), targetAnchorLine); }
AnchorLine AnchorHandleItem::targetAnchorLine() const { QmlAnchors anchors(anchorController().formEditorItem()->qmlItemNode().anchors()); if (isTopHandle()) return anchors.instanceAnchor(AnchorLine::Top); if (isBottomHandle()) return anchors.instanceAnchor(AnchorLine::Bottom); if (isLeftHandle()) return anchors.instanceAnchor(AnchorLine::Left); if (isRightHandle()) return anchors.instanceAnchor(AnchorLine::Right); return AnchorLine(); }
void AnchorIndicator::setItems(const QList<FormEditorItem *> &itemList) { clear(); if (itemList.count() == 1) { m_formEditorItem = itemList.first(); QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode(); if (!sourceQmlItemNode.modelNode().isRootNode()) { QmlAnchors qmlAnchors = sourceQmlItemNode.anchors(); if (qmlAnchors.modelHasAnchor(AnchorLine::Top)) { m_indicatorTopShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorTopShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Top), qmlAnchors.modelAnchor(AnchorLine::Top)); } if (qmlAnchors.modelHasAnchor(AnchorLine::Bottom)) { m_indicatorBottomShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorBottomShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Bottom), qmlAnchors.modelAnchor(AnchorLine::Bottom)); } if (qmlAnchors.modelHasAnchor(AnchorLine::Left)) { m_indicatorLeftShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorLeftShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Left), qmlAnchors.modelAnchor(AnchorLine::Left)); } if (qmlAnchors.modelHasAnchor(AnchorLine::Right)) { m_indicatorRightShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); m_indicatorRightShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Right), qmlAnchors.modelAnchor(AnchorLine::Right)); } } } }