void SelectionTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent * /*event*/) { if (!itemList.isEmpty()) { ResizeHandleItem* resizeHandle = ResizeHandleItem::fromGraphicsItem(itemList.first()); if (resizeHandle) { view()->changeToResizeTool(); return; } if (topSelectedItemIsMovable(itemList)) view()->changeToMoveTool(); } FormEditorItem *topSelectableItem = 0; foreach(QGraphicsItem* item, itemList) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem && !formEditorItem->qmlItemNode().isRootNode() && (formEditorItem->qmlItemNode().hasShowContent() || !m_selectOnlyContentItems)) { topSelectableItem = formEditorItem; break; } }
void AnchorTool::mouseMoveEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent *event) { if (m_anchorManipulator.isActive()) { FormEditorItem *targetItem = 0; AnchorLineHandleItem *anchorLineHandleItem = topAnchorLineHandleItem(itemList); if (anchorLineHandleItem && areAchorable(m_anchorManipulator.beginFormEditorItem(), anchorLineHandleItem->anchorLineController().formEditorItem())) { targetItem = anchorLineHandleItem->anchorLineController().formEditorItem(); } else { FormEditorItem *topFormEditItem = topFormEditorItemWithRootItem(itemList); if (topFormEditItem && areAchorable(m_anchorManipulator.beginFormEditorItem(), topFormEditItem)) { targetItem = topFormEditItem; } else { m_anchorLineIndicator.hide(); m_anchorIndicator.updateTargetPoint(m_anchorManipulator.beginFormEditorItem(), m_anchorManipulator.beginAnchorLine(), event->scenePos()); } } if (targetItem) { targetItem->qmlItemNode().selectNode(); m_anchorLineIndicator.setItem(targetItem); m_anchorLineIndicator.show(m_anchorManipulator.beginFormEditorItem()->qmlItemNode().anchors().possibleAnchorLines(m_anchorManipulator.beginAnchorLine(), targetItem->qmlItemNode())); m_anchorIndicator.updateTargetPoint(m_anchorManipulator.beginFormEditorItem(), m_anchorManipulator.beginAnchorLine(), event->scenePos()); targetItem->qmlItemNode().selectNode(); } } }
foreach (QGraphicsItem *item, itemList) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem && formEditorItem->qmlItemNode().instanceIsMovable() && !formEditorItem->qmlItemNode().instanceIsInPositioner() && selectedNodes.contains(formEditorItem->qmlItemNode())) return true; }
bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList) { QList<QmlItemNode> selectedNodes = view()->selectedQmlItemNodes(); foreach (QGraphicsItem *item, itemList) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem && selectedNodes.contains(formEditorItem->qmlItemNode()) && formEditorItem->qmlItemNode().instanceIsMovable() && !formEditorItem->qmlItemNode().instanceIsInPositioner() && (formEditorItem->qmlItemNode().hasShowContent())) return true; }
void AnchorTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent *event) { m_anchorLineIndicator.clearHighlight(); m_anchorIndicator.clearHighlight(); m_lastMousePosition = event->scenePos(); FormEditorItem *topFormEditItem = 0; AnchorLineHandleItem *anchorLineHandleItem = topAnchorLineHandleItem(itemList); if (anchorLineHandleItem) { anchorLineHandleItem->setHiglighted(true); m_anchorIndicator.highlight(anchorLineHandleItem->anchorLineController().formEditorItem(), anchorLineHandleItem->anchorLineType()); topFormEditItem = anchorLineHandleItem->anchorLineController().formEditorItem(); if (m_hoverTimeLine.state() == QTimeLine::NotRunning) { m_lastAnchorLineHandleItem = anchorLineHandleItem; m_hoverTimeLine.start(); } } else { topFormEditItem = topFormEditorItem(itemList); } if (topFormEditItem) { m_anchorLineIndicator.setItem(topFormEditItem); m_anchorLineIndicator.show(AnchorLine::AllMask); topFormEditItem->qmlItemNode().selectNode(); } else { m_anchorLineIndicator.clear(); } }
void SingleSelectionManipulator::select(SelectionType selectionType, bool selectOnlyContentItems) { QList<QGraphicsItem*> itemList = m_editorView->scene()->items(m_beginPoint); QmlItemNode selectedNode; foreach (QGraphicsItem* item, itemList) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem && formEditorItem->qmlItemNode().isValid() && (formEditorItem->qmlItemNode().instanceHasShowContent() || !selectOnlyContentItems)) { selectedNode = formEditorItem->qmlItemNode(); break; } }
FormEditorItem* DragTool::calculateContainer(const QPointF &point, FormEditorItem * currentItem) { QList<QGraphicsItem *> list = scene()->items(point); foreach (QGraphicsItem *item, list) { FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); if (formEditorItem && formEditorItem != currentItem && formEditorItem->isContainer() && !formEditorItem->qmlItemNode().modelNode().metaInfo().isLayoutable() && !isAncestorOf(currentItem, formEditorItem)) return formEditorItem; }
void SelectionTool::mousePressEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { m_mousePressTimer.start(); FormEditorItem* formEditorItem = nearestFormEditorItem(event->scenePos(), itemList); if (formEditorItem && formEditorItem->qmlItemNode().isValid() && !formEditorItem->qmlItemNode().hasChildren()) { m_singleSelectionManipulator.begin(event->scenePos()); if (event->modifiers().testFlag(Qt::ControlModifier)) m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection); else if (event->modifiers().testFlag(Qt::ShiftModifier)) m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection); else m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection); } else { if (event->modifiers().testFlag(Qt::AltModifier)) { m_singleSelectionManipulator.begin(event->scenePos()); if (event->modifiers().testFlag(Qt::ControlModifier)) m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection); else if (event->modifiers().testFlag(Qt::ShiftModifier)) m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection); else m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection); m_singleSelectionManipulator.end(event->scenePos()); view()->changeToMoveTool(event->scenePos()); } else { m_rubberbandSelectionManipulator.begin(event->scenePos()); } } } AbstractFormEditorTool::mousePressEvent(itemList, event); }
void AnchorTool::checkIfStillHovering() { AnchorLineHandleItem *anchorLineHandleItem = topAnchorLineHandleItem(scene()->items(m_lastMousePosition)); if (anchorLineHandleItem && anchorLineHandleItem == m_lastAnchorLineHandleItem) { FormEditorItem *sourceFormEditItem = anchorLineHandleItem->anchorLineController().formEditorItem(); QmlAnchors anchors(sourceFormEditItem->qmlItemNode().anchors()); if (anchors.instanceHasAnchor(anchorLineHandleItem->anchorLine())) { QmlItemNode targetNode(anchors.instanceAnchor(anchorLineHandleItem->anchorLine()).qmlItemNode()); FormEditorItem *targetFormEditorItem = scene()->itemForQmlItemNode(targetNode); targetFormEditorItem->showAttention(); } } }
void DragTool::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QmlItemNode &parentNode, const QPointF &scenePosition) { MetaInfo metaInfo = MetaInfo::global(); FormEditorItem *parentItem = scene()->itemForQmlItemNode(parentNode); QPointF positonInItemSpace = parentItem->qmlItemNode().instanceSceneContentItemTransform().inverted().map(scenePosition); m_dragNode = QmlItemNode::createQmlItemNode(view(), itemLibraryEntry, positonInItemSpace, parentNode); QList<QmlItemNode> nodeList; nodeList.append(m_dragNode); m_selectionIndicator.setItems(scene()->itemsForQmlItemNodes(nodeList)); }
bool AbstractFormEditorTool::topItemIsMovable(const QList<QGraphicsItem*> & itemList) { QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList); if (firstSelectableItem == 0) return false; FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(firstSelectableItem); QList<QmlItemNode> selectedNodes = view()->selectedQmlItemNodes(); if (formEditorItem != 0 && selectedNodes.contains(formEditorItem->qmlItemNode())) return true; return false; }
void DragTool::createDragNode(const QMimeData *mimeData, const QPointF &scenePosition, const QList<QGraphicsItem*> &itemList) { if (!m_dragNode.hasModelNode()) { FormEditorItem *targetContainerFormEditorItem = targetContainerOrRootItem(itemList); if (targetContainerFormEditorItem) { QmlItemNode targetContainerQmlItemNode; if (targetContainerFormEditorItem) targetContainerQmlItemNode = targetContainerFormEditorItem->qmlItemNode(); if (hasItemLibraryInfo(mimeData)) createQmlItemNode(itemLibraryEntryFromMimeData(mimeData), targetContainerQmlItemNode, scenePosition); else if (hasLibraryResources(mimeData)) createQmlItemNodeFromImage(libraryResourceImageName(mimeData), targetContainerQmlItemNode, scenePosition); m_blockMove = true; m_startPoint = scenePosition; } } }
void AnchorTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent *) { if (m_anchorManipulator.isActive()) { AnchorLineHandleItem *anchorLineHandleItem = topAnchorLineHandleItem(itemList); if (anchorLineHandleItem) { m_anchorManipulator.addAnchor(anchorLineHandleItem->anchorLineController().formEditorItem(), anchorLineHandleItem->anchorLineType()); } else { m_anchorManipulator.removeAnchor(); } } FormEditorItem *topFormEditItem = topFormEditorItem(itemList); if (topFormEditItem) topFormEditItem->qmlItemNode().selectNode(); m_anchorManipulator.clear(); m_anchorLineIndicator.clear(); }
void ResizeManipulator::update(const QPointF& updatePoint, Snapper::Snapping useSnapping) { const double minimumWidth = 0.0; const double minimumHeight = 0.0; deleteSnapLines(); bool snap = useSnapping == Snapper::UseSnapping || useSnapping == Snapper::UseSnappingAndAnchoring; if (m_resizeController.isValid()) { FormEditorItem *formEditorItem = m_resizeController.formEditorItem(); FormEditorItem *containerItem = m_snapper.containerFormEditorItem(); if (!containerItem) return; QPointF updatePointInLocalSpace = m_beginFromSceneToContentItemTransform.map(updatePoint); QmlAnchors anchors(formEditorItem->qmlItemNode().anchors()); QRectF boundingRect(m_beginBoundingRect); if (m_resizeHandle->isBottomRightHandle()) { boundingRect.setBottomRight(updatePointInLocalSpace); if (snap) { double rightOffset = m_snapper.snapRightOffset(boundingRect); if (rightOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= rightOffset; double bottomOffset = m_snapper.snapBottomOffset(boundingRect); if (bottomOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.ry() -= bottomOffset; } boundingRect.setBottomRight(updatePointInLocalSpace); if (anchors.instanceHasAnchor(AnchorLineHorizontalCenter)) boundingRect.setLeft(boundingRect.left() - (updatePointInLocalSpace.x() - m_beginBoundingRect.right())); if (anchors.instanceHasAnchor(AnchorLineVerticalCenter)) boundingRect.setTop(boundingRect.top() - (updatePointInLocalSpace.y() - m_beginBoundingRect.bottom())); if (boundingRect.width() < minimumWidth) boundingRect.setWidth(minimumWidth); if (boundingRect.height() < minimumHeight) boundingRect.setHeight(minimumHeight); formEditorItem->qmlItemNode().setSize(boundingRect.size()); if (anchors.instanceHasAnchor(AnchorLineBottom)) { anchors.setMargin(AnchorLineBottom, m_beginBottomMargin - (m_beginToParentTransform.map(boundingRect.bottomRight()) - m_beginBottomRightPoint).y()); } if (anchors.instanceHasAnchor(AnchorLineRight)) { anchors.setMargin(AnchorLineRight, m_beginRightMargin - (m_beginToParentTransform.map(boundingRect.bottomRight()) - m_beginBottomRightPoint).x()); } } else if (m_resizeHandle->isTopLeftHandle()) { boundingRect.setTopLeft(updatePointInLocalSpace); if (snap) { double leftOffset = m_snapper.snapLeftOffset(boundingRect); if (leftOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= leftOffset; double topOffset = m_snapper.snapTopOffset(boundingRect); if (topOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.ry() -= topOffset; } boundingRect.setTopLeft(updatePointInLocalSpace); if (anchors.instanceHasAnchor(AnchorLineHorizontalCenter)) boundingRect.setRight(boundingRect.right() - (updatePointInLocalSpace.x() - m_beginBoundingRect.left())); if (anchors.instanceHasAnchor(AnchorLineVerticalCenter)) boundingRect.setBottom(boundingRect.bottom() - (updatePointInLocalSpace.y() - m_beginBoundingRect.top())); if (boundingRect.width() < minimumWidth) boundingRect.setLeft(boundingRect.left() - minimumWidth + boundingRect.width()); if (boundingRect.height() < minimumHeight) boundingRect.setTop(boundingRect.top() - minimumHeight + boundingRect.height()); formEditorItem->qmlItemNode().setSize(boundingRect.size()); formEditorItem->qmlItemNode().setPosition(m_beginToParentTransform.map(boundingRect.topLeft())); if (anchors.instanceHasAnchor(AnchorLineTop)) { anchors.setMargin(AnchorLineTop, m_beginTopMargin + (-m_beginToParentTransform.map(m_beginBoundingRect.topLeft()).y() + m_beginToParentTransform.map(boundingRect.topLeft()).y())); } if (anchors.instanceHasAnchor(AnchorLineLeft)) { anchors.setMargin(AnchorLineLeft, m_beginLeftMargin + (-m_beginToParentTransform.map(m_beginBoundingRect.topLeft()).x() + m_beginToParentTransform.map(boundingRect.topLeft()).x())); } } else if (m_resizeHandle->isTopRightHandle()) { boundingRect.setTopRight(updatePointInLocalSpace); if (snap) { double rightOffset = m_snapper.snapRightOffset(boundingRect); if (rightOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= rightOffset; double topOffset = m_snapper.snapTopOffset(boundingRect); if (topOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.ry() -= topOffset; } boundingRect.setTopRight(updatePointInLocalSpace); if (anchors.instanceHasAnchor(AnchorLineHorizontalCenter)) boundingRect.setLeft(boundingRect.left() - (updatePointInLocalSpace.x() - m_beginBoundingRect.right())); if (anchors.instanceHasAnchor(AnchorLineVerticalCenter)) boundingRect.setBottom(boundingRect.bottom() - (updatePointInLocalSpace.y() - m_beginBoundingRect.top())); if (boundingRect.height() < minimumHeight) boundingRect.setTop(boundingRect.top() - minimumHeight + boundingRect.height()); if (boundingRect.width() < minimumWidth) boundingRect.setWidth(minimumWidth); formEditorItem->qmlItemNode().setSize(boundingRect.size()); formEditorItem->qmlItemNode().setPosition( m_beginToParentTransform.map(boundingRect.topLeft())); if (anchors.instanceHasAnchor(AnchorLineTop)) { anchors.setMargin(AnchorLineTop, m_beginTopMargin + (-m_beginToParentTransform.map(m_beginBoundingRect.topLeft()).y() + m_beginToParentTransform.map(boundingRect.topLeft()).y())); } if (anchors.instanceHasAnchor(AnchorLineRight)) { anchors.setMargin(AnchorLineRight, m_beginRightMargin - (m_beginToParentTransform.map(boundingRect.bottomRight()) - m_beginBottomRightPoint).x()); } } else if (m_resizeHandle->isBottomLeftHandle()) { boundingRect.setBottomLeft(updatePointInLocalSpace); if (snap) { double leftOffset = m_snapper.snapLeftOffset(boundingRect); if (leftOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= leftOffset; double bottomOffset = m_snapper.snapBottomOffset(boundingRect); if (bottomOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.ry() -= bottomOffset; } boundingRect.setBottomLeft(updatePointInLocalSpace); if (anchors.instanceHasAnchor(AnchorLineHorizontalCenter)) boundingRect.setRight(boundingRect.right() - (updatePointInLocalSpace.x() - m_beginBoundingRect.left())); if (anchors.instanceHasAnchor(AnchorLineVerticalCenter)) boundingRect.setTop(boundingRect.top() - (updatePointInLocalSpace.y() - m_beginBoundingRect.bottom())); if (boundingRect.height() < minimumHeight) boundingRect.setHeight(minimumHeight); if (boundingRect.width() < minimumWidth) boundingRect.setLeft(boundingRect.left() - minimumWidth + boundingRect.width()); formEditorItem->qmlItemNode().setSize(boundingRect.size()); formEditorItem->qmlItemNode().setPosition(m_beginToParentTransform.map(boundingRect.topLeft())); if (anchors.instanceHasAnchor(AnchorLineLeft)) { anchors.setMargin(AnchorLineLeft, m_beginLeftMargin + (-m_beginToParentTransform.map(m_beginBoundingRect.topLeft()).x() + m_beginToParentTransform.map(boundingRect.topLeft()).x())); } if (anchors.instanceHasAnchor(AnchorLineBottom)) { anchors.setMargin(AnchorLineBottom, m_beginBottomMargin - (m_beginToParentTransform.map(boundingRect.bottomRight()) - m_beginBottomRightPoint).y()); } } else if (m_resizeHandle->isBottomHandle()) { boundingRect.setBottom(updatePointInLocalSpace.y()); if (snap) { double bottomOffset = m_snapper.snapBottomOffset(boundingRect); if (bottomOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.ry() -= bottomOffset; } boundingRect.setBottom(updatePointInLocalSpace.y()); if (anchors.instanceHasAnchor(AnchorLineVerticalCenter)) boundingRect.setTop(boundingRect.top() - (updatePointInLocalSpace.y() - m_beginBoundingRect.bottom())); if (boundingRect.height() < minimumHeight) boundingRect.setHeight(minimumHeight); formEditorItem->qmlItemNode().setSize(boundingRect.size()); if (anchors.instanceHasAnchor(AnchorLineBottom)) { anchors.setMargin(AnchorLineBottom, m_beginBottomMargin - (m_beginToParentTransform.map(boundingRect.bottomRight()) - m_beginBottomRightPoint).y()); } } else if (m_resizeHandle->isTopHandle()) { boundingRect.setTop(updatePointInLocalSpace.y()); if (snap) { double topOffset = m_snapper.snapTopOffset(boundingRect); if (topOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.ry() -= topOffset; } boundingRect.setTop(updatePointInLocalSpace.y()); if (anchors.instanceHasAnchor(AnchorLineVerticalCenter)) boundingRect.setBottom(boundingRect.bottom() - (updatePointInLocalSpace.y() - m_beginBoundingRect.top())); if (boundingRect.height() < minimumHeight) boundingRect.setTop(boundingRect.top() - minimumHeight + boundingRect.height()); formEditorItem->qmlItemNode().setSize(boundingRect.size()); formEditorItem->qmlItemNode().setPosition(m_beginToParentTransform.map(boundingRect.topLeft())); if (anchors.instanceHasAnchor(AnchorLineTop)) { anchors.setMargin(AnchorLineTop, m_beginTopMargin + (-m_beginToParentTransform.map(m_beginBoundingRect.topLeft()).y() + m_beginToParentTransform.map(boundingRect.topLeft()).y())); } } else if (m_resizeHandle->isRightHandle()) { boundingRect.setRight(updatePointInLocalSpace.x()); if (snap) { double rightOffset = m_snapper.snapRightOffset(boundingRect); if (rightOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= rightOffset; } boundingRect.setRight(updatePointInLocalSpace.x()); if (anchors.instanceHasAnchor(AnchorLineHorizontalCenter)) boundingRect.setLeft(boundingRect.left() - (updatePointInLocalSpace.x() - m_beginBoundingRect.right())); if (boundingRect.width() < minimumWidth) boundingRect.setWidth(minimumWidth); formEditorItem->qmlItemNode().setSize(boundingRect.size()); if (anchors.instanceHasAnchor(AnchorLineRight)) { anchors.setMargin(AnchorLineRight, m_beginRightMargin - (m_beginToParentTransform.map(boundingRect.bottomRight()) - m_beginBottomRightPoint).x()); } } else if (m_resizeHandle->isLeftHandle()) { boundingRect.setLeft(updatePointInLocalSpace.x()); if (snap) { double leftOffset = m_snapper.snapLeftOffset(boundingRect); if (leftOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= leftOffset; } boundingRect.setLeft(updatePointInLocalSpace.x()); if (anchors.instanceHasAnchor(AnchorLineHorizontalCenter)) boundingRect.setRight(boundingRect.right() - (updatePointInLocalSpace.x() - m_beginBoundingRect.left())); if (boundingRect.width() < minimumWidth) boundingRect.setLeft(boundingRect.left() - minimumWidth + boundingRect.width()); formEditorItem->qmlItemNode().setSize(boundingRect.size()); formEditorItem->qmlItemNode().setPosition(m_beginToParentTransform.map(boundingRect.topLeft())); if (anchors.instanceHasAnchor(AnchorLineLeft)) { anchors.setMargin(AnchorLineLeft, m_beginLeftMargin + (-m_beginToParentTransform.map(m_beginBoundingRect.topLeft()).x() + m_beginToParentTransform.map(boundingRect.topLeft()).x())); } } if (snap) m_graphicsLineList = m_snapper.generateSnappingLines(boundingRect, m_layerItem.data(), m_beginFromItemToSceneTransform); } }