From 61070038b6682d2c298823338492514682419e33 Mon Sep 17 00:00:00 2001 From: Karol Herda Date: Fri, 20 Dec 2024 12:23:27 +0100 Subject: [PATCH] Enable/disable node pins Change-Id: Ibd0b41b534cd59ab99692c27e1e9588e5d72616e Reviewed-by: Karol Herda --- .../qmldesigner/nodegrapheditor/Main.qml | 9 +++++ .../imports/Editor/ContextMenu.qml | 37 ++++++++++++++++++ .../nodegrapheditor/imports/Nodes/Base.qml | 38 +++++++++++++++++++ .../imports/Nodes/Metalness.qml | 4 ++ 4 files changed, 88 insertions(+) diff --git a/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml b/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml index fb5c69ff71b..89236f6d1a3 100644 --- a/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml +++ b/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml @@ -293,6 +293,15 @@ Item { } onRightClicked: function (pos) { if (NodeGraphEditorBackend.nodeGraphEditorModel.currentFileName !== "") { + var selectedNodes = graphView.graph.selectedNodes; + if (selectedNodes) { + if (selectedNodes.length > 0) + contextMenu.node = selectedNodes.at(0); + else + contextMenu.node = null; + } else + contextMenu.node = null; + contextMenu.popup(); } } diff --git a/share/qtcreator/qmldesigner/nodegrapheditor/imports/Editor/ContextMenu.qml b/share/qtcreator/qmldesigner/nodegrapheditor/imports/Editor/ContextMenu.qml index 934232fe2f2..22c242207c8 100644 --- a/share/qtcreator/qmldesigner/nodegrapheditor/imports/Editor/ContextMenu.qml +++ b/share/qtcreator/qmldesigner/nodegrapheditor/imports/Editor/ContextMenu.qml @@ -14,9 +14,18 @@ StudioControls.Menu { id: contextMenu required property var graph + property var inputsModel: [] + property var node closePolicy: Popup.CloseOnPressOutside | Popup.CloseOnEscape + onAboutToShow: { + if (node && node.item) + contextMenu.inputsModel = node.item.portsMetaData; + else + contextMenu.inputsModel = null; + } + StudioControls.MenuItem { text: qsTr("BaseColor") @@ -88,4 +97,32 @@ StudioControls.Menu { contextMenu.graph.insertNode(Nodes.Components.texture); } } + + StudioControls.MenuSeparator { + height: implicitHeight + style: StudioTheme.Values.controlStyle + } + + StudioControls.Menu { + enabled: node !== null + title: "Pins" + + Repeater { + id: pinRepeater + + model: contextMenu.inputsModel ? contextMenu.inputsModel.pin : null + + delegate: StudioControls.CheckBox { + actionIndicator.visible: false + checkState: (modelData.enabled === undefined || modelData.enabled === true) ? Qt.Checked : Qt.UnChecked + text: "pin: " + modelData.name + width: implicitWidth + StudioTheme.Values.toolbarHorizontalMargin + + onToggled: { + contextMenu.node.item.switchPin(modelData.id); + contextMenu.node.item.updatePinVisibility(modelData.id); + } + } + } + } } diff --git a/share/qtcreator/qmldesigner/nodegrapheditor/imports/Nodes/Base.qml b/share/qtcreator/qmldesigner/nodegrapheditor/imports/Nodes/Base.qml index c27147c3e41..a291e2a8d38 100644 --- a/share/qtcreator/qmldesigner/nodegrapheditor/imports/Nodes/Base.qml +++ b/share/qtcreator/qmldesigner/nodegrapheditor/imports/Nodes/Base.qml @@ -18,6 +18,7 @@ Qan.NodeItem { // alias: "", // name: "", // type: "", + // enabled: true, // binding: (values) => {} // } property var pin: [] @@ -26,6 +27,29 @@ Qan.NodeItem { property string type property string uuid: NodeGraphEditorBackend.widget.generateUUID() + function switchPin(pin_id) { + root.portsMetaData.pin.forEach(data => { + if (data.id == pin_id) { + if (data.enabled === false) + data.enabled = true; + else + data.enabled = false; + } + }); + } + + function updatePinVisibility(pin_id) { + internal.createdPorts.forEach(data => { + if (data.dataId === pin_id) { + root.portsMetaData.pin.forEach(data2 => { + if (data2.id === pin_id) { + data.visible = data2.enabled; + } + }); + } + }); + } + Layout.preferredHeight: 60 Layout.preferredWidth: 100 connectable: Qan.NodeItem.UnConnectable @@ -56,6 +80,8 @@ Qan.NodeItem { QtObject { id: internal + property var createdPorts: [] + function configurePorts(graph) { const initPort = (portItem, data) => { if (data.binding) { @@ -65,15 +91,27 @@ Qan.NodeItem { portItem.dataType = data.type; portItem.dataId = data.id; }; + for (var i = 0; i < createdPorts.length; i++) { + graph.removePort(root.node, createdPorts[i]); + } + createdPorts = []; + + root.node.item.ports.clear(); root.portsMetaData.pin.forEach(data => { const portItem = graph.insertPort(root.node, Qan.NodeItem.Left, Qan.PortItem.In, `${data.name} (${data.type})`, data.id); initPort(portItem, data); + + if (data.enabled != undefined && data.enabled === false) { + portItem.visible = false; + } + createdPorts.push(portItem); }); root.portsMetaData.pout.forEach(data => { const portItem = graph.insertPort(root.node, Qan.NodeItem.Right, Qan.PortItem.Out, `${data.name}`, data.id); initPort(portItem, data); + createdPorts.push(portItem); }); } } diff --git a/share/qtcreator/qmldesigner/nodegrapheditor/imports/Nodes/Metalness.qml b/share/qtcreator/qmldesigner/nodegrapheditor/imports/Nodes/Metalness.qml index 7f84d0e3ed1..0dbf73570b0 100644 --- a/share/qtcreator/qmldesigner/nodegrapheditor/imports/Nodes/Metalness.qml +++ b/share/qtcreator/qmldesigner/nodegrapheditor/imports/Nodes/Metalness.qml @@ -30,18 +30,21 @@ Base { id: "metalness_in_metalness", alias: "metalness", name: "Metalness", + enabled: true, type: "real" }, { id: "metalness_in_metalnessChannel", alias: "channel", name: "Channel", + enabled: true, type: "QQuick3DMaterial::TextureChannelMapping" }, { id: "metalness_in_metalnessMap ", alias: "map", name: "Map", + enabled: false, type: "Texture" }, ] @@ -50,6 +53,7 @@ Base { id: "metalness_out", alias: "", name: "OUT", + enabled: true, type: "nge::Metalness" }, ]