diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp index b3935fdf82e..3a70283589d 100644 --- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp +++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp @@ -1112,6 +1112,12 @@ bool singleSelectionItemIsNotAnchoredAndSingleSelectionNotRoot(const SelectionCo && singleSelectionNotRoot(context); } +bool singleSelectionItemHasNoFillAnchorAndSingleSelectionNotRoot(const SelectionContext &context) +{ + return singleSelection(context) && !singleSelectionItemHasAnchor(context, AnchorLineFill) + && singleSelectionNotRoot(context); +} + bool selectionNotEmptyAndHasXorYProperty(const SelectionContext &context) { return selectionNotEmpty(context) @@ -1528,15 +1534,15 @@ void DesignerActionManager::createDefaultDesignerActions() &anchorsMenuEnabled)); addDesignerAction(new ModelNodeAction( - anchorsFillCommandId, - anchorsFillDisplayName, - Utils::Icon({{":/qmldesigner/images/anchor_fill.png", Utils::Theme::IconsBaseColor}}).icon(), - anchorsFillToolTip, - anchorsCategory, - QKeySequence(QKeySequence("shift+f")), - 2, - &anchorsFill, - &singleSelectionItemIsNotAnchoredAndSingleSelectionNotRoot)); + anchorsFillCommandId, + anchorsFillDisplayName, + Utils::Icon({{":/qmldesigner/images/anchor_fill.png", Utils::Theme::IconsBaseColor}}).icon(), + anchorsFillToolTip, + anchorsCategory, + QKeySequence(QKeySequence("shift+f")), + 2, + &anchorsFill, + &singleSelectionItemHasNoFillAnchorAndSingleSelectionNotRoot)); addDesignerAction(new ModelNodeAction( anchorsResetCommandId, diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.cpp index d2b49fc3faf..db7f0363268 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.cpp @@ -68,6 +68,16 @@ bool singleSelectionItemIsNotAnchored(const SelectionContext &selectionState) return false; } +bool singleSelectionItemHasAnchor(const SelectionContext &selectionState, AnchorLineType anchor) +{ + QmlItemNode itemNode(selectionState.currentSingleSelectedNode()); + if (selectionState.isInBaseState() && itemNode.isValid()) { + bool hasAnchor = itemNode.instanceHasAnchor(anchor); + return hasAnchor; + } + return false; +} + bool selectionHasSameParent(const SelectionContext &selectionState) { return !selectionState.selectedModelNodes().isEmpty() && itemsHaveSameParent(selectionState.selectedModelNodes()); diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h index 5affb7adf8d..95cf541340b 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h @@ -178,6 +178,7 @@ bool selectionIsEditableComponent(const SelectionContext &selectionState); bool singleSelectionItemIsAnchored(const SelectionContext &selectionState); bool singleSelectionItemIsNotAnchored(const SelectionContext &selectionState); bool selectionIsImported3DAsset(const SelectionContext &selectionState); +bool singleSelectionItemHasAnchor(const SelectionContext &selectionState, AnchorLineType anchor); } // namespace SelectionStateFunctors diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index cc739c9f9cf..b4b136d3ec9 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -398,6 +398,11 @@ void anchorsFill(const SelectionContext &selectionState) backupPropertyAndRemove(modelNode, "y"); backupPropertyAndRemove(modelNode, "width"); backupPropertyAndRemove(modelNode, "height"); + + node.anchors().removeMargin(AnchorLineRight); + node.anchors().removeMargin(AnchorLineLeft); + node.anchors().removeMargin(AnchorLineTop); + node.anchors().removeMargin(AnchorLineBottom); } }); } diff --git a/src/plugins/qmldesigner/qmltools/qmlitemnode.cpp b/src/plugins/qmldesigner/qmltools/qmlitemnode.cpp index e01ac1d3a55..ae05cd3ee26 100644 --- a/src/plugins/qmldesigner/qmltools/qmlitemnode.cpp +++ b/src/plugins/qmldesigner/qmltools/qmlitemnode.cpp @@ -325,6 +325,11 @@ bool QmlItemNode::hasResources() const return !resources().isEmpty(); } +bool QmlItemNode::instanceHasAnchor(AnchorLineType sourceAnchorLineType) const +{ + return anchors().instanceHasAnchor(sourceAnchorLineType); +} + bool QmlItemNode::instanceHasAnchors() const { return anchors().instanceHasAnchors();