void FormEditorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (!painter->isActive()) return; if (!qmlItemNode().isValid()) return; painter->save(); if (qmlItemNode().instanceIsRenderPixmapNull() || !isContentVisible()) { if (scene()->showBoundingRects() && m_boundingRect.width() > 15 && m_boundingRect.height() > 15) paintPlaceHolderForInvisbleItem(painter); } else { if (m_blurContent) painter->drawPixmap(boundingRect().topLeft(), qmlItemNode().instanceBlurredRenderPixmap()); else painter->drawPixmap(boundingRect().topLeft(), qmlItemNode().instanceRenderPixmap()); } if (!qmlItemNode().isRootModelNode()) paintBoundingRect(painter); // if (qmlItemNode().modelNode().metaInfo().isSubclassOf("QtQuick.Loader", -1, -1)) // paintComponentContentVisualisation(painter, boundingRect()); painter->restore(); }
void QmlAnchors::removeMargin(AnchorLine::Type sourceAnchorLineType) { if (qmlItemNode().isInBaseState()) { QString propertyName = marginPropertyName(sourceAnchorLineType); qmlItemNode().modelNode().removeProperty(propertyName); } }
bool QmlAnchors::instanceHasAnchor(AnchorLine::Type sourceAnchorLine) const { const QString propertyName = anchorPropertyName(sourceAnchorLine); if (sourceAnchorLine & AnchorLine::Fill) return qmlItemNode().nodeInstance().hasAnchor(propertyName) || qmlItemNode().nodeInstance().hasAnchor("anchors.fill"); if (sourceAnchorLine & AnchorLine::Center) return qmlItemNode().nodeInstance().hasAnchor(propertyName) || qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn"); return qmlItemNode().nodeInstance().hasAnchor(propertyName); }
bool QmlAnchors::canAnchor(const QmlItemNode &targetModelNode) const { if (!qmlItemNode().isInBaseState()) return false; if (targetModelNode == qmlItemNode().instanceParent()) return true; if (qmlItemNode().instanceParent() == targetModelNode.instanceParent()) return true; return false; }
void FormEditorItem::paintPlaceHolderForInvisbleItem(QPainter *painter) const { qreal stripesWidth = 12; QRegion innerRegion = QRegion(m_boundingRect.adjusted(stripesWidth, stripesWidth, -stripesWidth, -stripesWidth).toRect()); QRegion outerRegion = QRegion(m_boundingRect.toRect()) - innerRegion; painter->setClipRegion(outerRegion); painter->setClipping(true); painter->fillRect(m_boundingRect.adjusted(1, 1, -1, -1), Qt::BDiagPattern); painter->setClipping(false); QString displayText = qmlItemNode().id(); if (displayText.isEmpty()) displayText = qmlItemNode().simplifiedTypeName(); QTextOption textOption; textOption.setAlignment(Qt::AlignTop); textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); if (m_boundingRect.height() > 60) { painter->save(); QFont font; font.setStyleHint(QFont::SansSerif); font.setBold(true); font.setPixelSize(12); painter->setFont(font); QFontMetrics fm(font); painter->rotate(90); if (fm.width(displayText) > (m_boundingRect.height() - 32) && displayText.length() > 4) { displayText = fm.elidedText(displayText, Qt::ElideRight, m_boundingRect.height() - 32, Qt::TextShowMnemonic); } QRectF rotatedBoundingBox; rotatedBoundingBox.setWidth(m_boundingRect.height()); rotatedBoundingBox.setHeight(12); rotatedBoundingBox.setY(-m_boundingRect.width() + 12); rotatedBoundingBox.setX(20); painter->setFont(font); painter->setPen(QColor(48, 48, 96, 255)); painter->drawText(rotatedBoundingBox, displayText, textOption); painter->restore(); } }
void FormEditorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (!qmlItemNode().isValid()) return; painter->save(); if (isContentVisible()) qmlItemNode().paintInstance(painter); if (!qmlItemNode().isRootModelNode()) paintBoundingRect(painter); painter->restore(); }
void FormEditorItem::paintPlaceHolderForInvisbleItem(QPainter *painter) const { qreal stripesWidth = 12; QRegion innerRegion = QRegion(boundingRect().adjusted(stripesWidth, stripesWidth, -stripesWidth, -stripesWidth).toRect()); QRegion outerRegion = QRegion(boundingRect().toRect()) - innerRegion; painter->setClipRegion(outerRegion); painter->setClipping(true); painter->fillRect(boundingRect().adjusted(1, 1, -1, -1), Qt::BDiagPattern); painter->setClipping(false); QString displayText = qmlItemNode().id(); if (displayText.isEmpty()) displayText = qmlItemNode().simplifiedTypeName(); QTextOption textOption; textOption.setAlignment(Qt::AlignCenter); textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); if (boundingRect().width() > 60) { painter->save(); QFont font; font.setStyleHint(QFont::SansSerif); font.setBold(true); font.setPixelSize(14); painter->setFont(font); QFontMetrics fm(font); if (fm.width(displayText) > (boundingRect().width() - 22) && displayText.length() > 4) { displayText = fm.elidedText(displayText, Qt::ElideRight, boundingRect().width() - 22, Qt::TextShowMnemonic); } painter->setPen(QColor(255, 255, 255, 128)); painter->setCompositionMode(QPainter::CompositionMode_Exclusion); painter->drawText(boundingRect().adjusted(-2, -2, 0,0), displayText, textOption); painter->setFont(font); painter->setPen(QColor(0, 0, 0, 255)); painter->drawText(boundingRect(), displayText, textOption); painter->restore(); } }
void ResizeManipulator::moveBy(double deltaX, double deltaY) { if (resizeHandle() && m_resizeController.isValid()) { QmlItemNode qmlItemNode(m_resizeController.formEditorItem()->qmlItemNode()); QmlAnchors anchors(qmlItemNode.anchors()); if (m_resizeController.isLeftHandle(resizeHandle()) || m_resizeController.isTopLeftHandle(resizeHandle()) || m_resizeController.isBottomLeftHandle(resizeHandle())) { qmlItemNode.setVariantProperty("x", round((qmlItemNode.instanceValue("x").toDouble() + deltaX), 4)); qmlItemNode.setVariantProperty("width", round(qmlItemNode.instanceValue("width").toDouble() - deltaX, 4)); if (anchors.instanceHasAnchor(AnchorLineLeft)) anchors.setMargin(AnchorLineLeft, anchors.instanceMargin(AnchorLineLeft) + deltaX); if (anchors.instanceHasAnchor(AnchorLineHorizontalCenter)) qmlItemNode.setVariantProperty("width", round(qmlItemNode.instanceValue("width").toDouble() - (deltaX * 2), 4)); } if (m_resizeController.isRightHandle(resizeHandle()) || m_resizeController.isTopRightHandle(resizeHandle()) || m_resizeController.isBottomRightHandle(resizeHandle())) { qmlItemNode.setVariantProperty("width", round(qmlItemNode.instanceValue("width").toDouble() + deltaX, 4)); if (anchors.instanceHasAnchor(AnchorLineRight)) anchors.setMargin(AnchorLineRight, round(anchors.instanceMargin(AnchorLineRight) - deltaX, 4)); if (anchors.instanceHasAnchor(AnchorLineHorizontalCenter)) qmlItemNode.setVariantProperty("width", round(qmlItemNode.instanceValue("width").toDouble() + (deltaX * 2), 4)); } if (m_resizeController.isTopHandle(resizeHandle()) || m_resizeController.isTopLeftHandle(resizeHandle()) || m_resizeController.isTopRightHandle(resizeHandle())) { qmlItemNode.setVariantProperty("y", round(qmlItemNode.instanceValue("y").toDouble() + deltaY, 4)); qmlItemNode.setVariantProperty("height", round(qmlItemNode.instanceValue("height").toDouble() - deltaY, 4)); if (anchors.instanceHasAnchor(AnchorLineTop)) anchors.setMargin(AnchorLineTop, anchors.instanceMargin(AnchorLineTop) + deltaY); if (anchors.instanceHasAnchor(AnchorLineVerticalCenter)) qmlItemNode.setVariantProperty("height", round(qmlItemNode.instanceValue("height").toDouble() - (deltaY * 2), 4)); } if (m_resizeController.isBottomHandle(resizeHandle()) || m_resizeController.isBottomLeftHandle(resizeHandle()) || m_resizeController.isBottomRightHandle(resizeHandle())) { qmlItemNode.setVariantProperty("height", round(qmlItemNode.instanceValue("height").toDouble() + deltaY, 4)); if (anchors.instanceHasAnchor(AnchorLineBottom)) anchors.setMargin(AnchorLineBottom, anchors.instanceMargin(AnchorLineBottom) - deltaY); if (anchors.instanceHasAnchor(AnchorLineVerticalCenter)) qmlItemNode.setVariantProperty("height", round(qmlItemNode.instanceValue("height").toDouble() + (deltaY * 2), 4)); } } }
void QmlAnchors::centerIn() { if (instanceHasAnchors()) removeAnchors(); qmlItemNode().modelNode().bindingProperty("anchors.centerIn").setExpression("parent"); }
void FormEditorView::nodeAboutToBeRemoved(const ModelNode &removedNode) { QmlItemNode qmlItemNode(removedNode); removeNodeFromScene(qmlItemNode); QmlModelView::nodeAboutToBeRemoved(removedNode); }
AnchorLine::Type QmlAnchors::possibleAnchorLines(AnchorLine::Type sourceAnchorLineType, const QmlItemNode &targetQmlItemNode) const { if (!canAnchor(targetQmlItemNode)) return AnchorLine::Invalid; if (AnchorLine::isHorizontalAnchorLine(sourceAnchorLineType)) { if (!detectHorizontalCycle(targetQmlItemNode, QList<ModelNode>() << qmlItemNode().modelNode())) return AnchorLine::HorizontalMask; } if (AnchorLine::isVerticalAnchorLine(sourceAnchorLineType)) { if (!detectVerticalCycle(targetQmlItemNode, QList<ModelNode>() << qmlItemNode().modelNode())) return AnchorLine::VerticalMask; } return AnchorLine::Invalid; }
void QmlAnchors::removeMargins() { RewriterTransaction transaction = qmlItemNode().qmlModelView()->beginRewriterTransaction(); removeMargin(AnchorLine::Left); removeMargin(AnchorLine::Right); removeMargin(AnchorLine::Top); removeMargin(AnchorLine::Bottom); removeMargin(AnchorLine::HorizontalCenter); removeMargin(AnchorLine::VerticalCenter); }
void FormEditorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (!qmlItemNode().isValid()) return; painter->save(); if (qmlItemNode().instanceIsRenderPixmapNull()) { if (scene()->showBoundingRects() && boundingRect().width() > 15 && boundingRect().height() > 15) paintPlaceHolderForInvisbleItem(painter); } else { qmlItemNode().paintInstance(painter); } if (!qmlItemNode().isRootModelNode()) paintBoundingRect(painter); painter->restore(); }
void QmlAnchors::removeMargins() { RewriterTransaction transaction = qmlItemNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchors::removeMargins")); removeMargin(AnchorLineLeft); removeMargin(AnchorLineRight); removeMargin(AnchorLineTop); removeMargin(AnchorLineBottom); removeMargin(AnchorLineHorizontalCenter); removeMargin(AnchorLineVerticalCenter); }
void FormEditorItem::setAttentionScale(double sinusScale) { if (!qFuzzyIsNull(sinusScale)) { double scale = std::sqrt(sinusScale); m_attentionTransform.reset(); QPointF centerPoint(qmlItemNode().instanceBoundingRect().center()); m_attentionTransform.translate(centerPoint.x(), centerPoint.y()); m_attentionTransform.scale(scale * 0.15 + 1.0, scale * 0.15 + 1.0); m_attentionTransform.translate(-centerPoint.x(), -centerPoint.y()); m_inverseAttentionTransform = m_attentionTransform.inverted(); prepareGeometryChange(); setTransform(qmlItemNode().instanceTransform()); setTransform(m_attentionTransform, true); } else { m_attentionTransform.reset(); prepareGeometryChange(); setTransform(qmlItemNode().instanceTransform()); } }
void FormEditorItem::paintBoundingRect(QPainter *painter) const { if (!boundingRect().isValid() || (QGraphicsItem::parentItem() == scene()->formLayerItem() && qFuzzyIsNull(m_borderWidth))) return; QPen pen; pen.setJoinStyle(Qt::MiterJoin); switch(scene()->paintMode()) { case FormEditorScene::AnchorMode: { pen.setColor(Qt::black); pen.setWidth(m_borderWidth); } break; case FormEditorScene::NormalMode: { QColor frameColor("#AAAAAA"); if (qmlItemNode().anchors().instanceHasAnchors()) frameColor = QColor("#ffff00"); if (scene()->showBoundingRects()) { if (m_highlightBoundingRect) pen.setColor(frameColor); else pen.setColor(frameColor.darker(150)); } else { if (m_highlightBoundingRect) pen.setColor(frameColor); else pen.setColor(Qt::transparent); } } break; } painter->setPen(pen); // int offset = m_borderWidth / 2; painter->drawRect(boundingRect().adjusted(0., 0., -1., -1.)); }
void FormEditorView::nodeAboutToBeRemoved(const ModelNode &removedNode) { QmlItemNode qmlItemNode(removedNode); if (qmlItemNode.isValid()) { FormEditorItem *item = m_scene->itemForQmlItemNode(qmlItemNode); QList<QmlItemNode> nodeList; nodeList.append(qmlItemNode.allSubModelNodes()); nodeList.append(qmlItemNode); QList<FormEditorItem*> removedItemList; removedItemList.append(scene()->itemsForQmlItemNodes(nodeList)); m_currentTool->itemsAboutToRemoved(removedItemList); delete item; } QmlModelView::nodeAboutToBeRemoved(removedNode); }
void FormEditorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList) { foreach(const AbstractProperty &property, propertyList) { if (property.isNodeAbstractProperty()) { NodeAbstractProperty nodeAbstractProperty = property.toNodeAbstractProperty(); QList<FormEditorItem*> removedItemList; foreach(const ModelNode &modelNode, nodeAbstractProperty.allSubNodes()) { QmlItemNode qmlItemNode(modelNode); if (qmlItemNode.isValid() && m_scene->hasItemForQmlItemNode(qmlItemNode)) { FormEditorItem *item = m_scene->itemForQmlItemNode(qmlItemNode); removedItemList.append(item); delete item; } } m_currentTool->itemsAboutToRemoved(removedItemList); } }
void QmlAnchors::setAnchor(AnchorLine::Type sourceAnchorLine, const QmlItemNode &targetQmlItemNode, AnchorLine::Type targetAnchorLine) { RewriterTransaction transaction = qmlItemNode().qmlModelView()->beginRewriterTransaction(); if (qmlItemNode().isInBaseState()) { if ((qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLine::Fill)) || ((qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLine::Center)))) { removeAnchor(sourceAnchorLine); } const QString propertyName = anchorPropertyName(sourceAnchorLine); QString targetExpression = targetQmlItemNode.modelNode().validId(); if (targetQmlItemNode.modelNode() == qmlItemNode().modelNode().parentProperty().parentModelNode()) targetExpression = "parent"; targetExpression = targetExpression + QLatin1Char('.') + lineTypeToString(targetAnchorLine); qmlItemNode().modelNode().bindingProperty(propertyName).setExpression(targetExpression); } }
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 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); }
double QmlAnchors::instanceRightAnchorLine() const { return contentRect(qmlItemNode().nodeInstance()).x() + contentRect(qmlItemNode().nodeInstance()).width(); }
double QmlAnchors::instanceBottomAnchorLine() const { return contentRect(qmlItemNode().nodeInstance()).y() + contentRect(qmlItemNode().nodeInstance()).height(); }
double QmlAnchors::instanceTopAnchorLine() const { return contentRect(qmlItemNode().nodeInstance()).y(); }
double QmlAnchors::instanceMargin(AnchorLine::Type sourceAnchorLineType) const { return qmlItemNode().nodeInstance().property(marginPropertyName(sourceAnchorLineType)).toDouble(); }
void QmlAnchors::setMargin(AnchorLine::Type sourceAnchorLineType, double margin) const { QString propertyName = marginPropertyName(sourceAnchorLineType); qmlItemNode().setVariantProperty(propertyName, qRound(margin)); }
void QmlAnchors::removeAnchors() { RewriterTransaction transaction = qmlItemNode().qmlModelView()->beginRewriterTransaction(); if (qmlItemNode().nodeInstance().hasAnchor("anchors.fill")) qmlItemNode().modelNode().removeProperty("anchors.fill"); if (qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn")) qmlItemNode().modelNode().removeProperty("anchors.centerIn"); if (qmlItemNode().nodeInstance().hasAnchor("anchors.top")) qmlItemNode().modelNode().removeProperty("anchors.top"); if (qmlItemNode().nodeInstance().hasAnchor("anchors.left")) qmlItemNode().modelNode().removeProperty("anchors.left"); if (qmlItemNode().nodeInstance().hasAnchor("anchors.right")) qmlItemNode().modelNode().removeProperty("anchors.right"); if (qmlItemNode().nodeInstance().hasAnchor("anchors.bottom")) qmlItemNode().modelNode().removeProperty("anchors.bottom"); if (qmlItemNode().nodeInstance().hasAnchor("anchors.horizontalCenter")) qmlItemNode().modelNode().removeProperty("anchors.horizontalCenter"); if (qmlItemNode().nodeInstance().hasAnchor("anchors.verticalCenter")) qmlItemNode().modelNode().removeProperty("anchors.verticalCenter"); if (qmlItemNode().nodeInstance().hasAnchor("anchors.baseline")) qmlItemNode().modelNode().removeProperty("anchors.baseline"); }
void QmlAnchors::removeAnchor(AnchorLine::Type sourceAnchorLine) { RewriterTransaction transaction = qmlItemNode().qmlModelView()->beginRewriterTransaction(); if (qmlItemNode().isInBaseState()) { const QString propertyName = anchorPropertyName(sourceAnchorLine); if (qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLine::Fill)) { qmlItemNode().modelNode().removeProperty("anchors.fill"); qmlItemNode().modelNode().bindingProperty("anchors.top").setExpression("parent.top"); qmlItemNode().modelNode().bindingProperty("anchors.left").setExpression("parent.left"); qmlItemNode().modelNode().bindingProperty("anchors.bottom").setExpression("parent.bottom"); qmlItemNode().modelNode().bindingProperty("anchors.right").setExpression("parent.right"); } else if (qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLine::Center)) { qmlItemNode().modelNode().removeProperty("anchors.centerIn"); qmlItemNode().modelNode().bindingProperty("anchors.horizontalCenter").setExpression("parent.horizontalCenter"); qmlItemNode().modelNode().bindingProperty("anchors.verticalCenter").setExpression("parent.verticalCenter"); } qmlItemNode().modelNode().removeProperty(propertyName); } }