diff --git a/meshroom/core/desc.py b/meshroom/core/desc.py index 092471d6..a3986ce8 100644 --- a/meshroom/core/desc.py +++ b/meshroom/core/desc.py @@ -343,6 +343,19 @@ class StringParam(Param): return "" +class ColorParam(Param): + """ + """ + def __init__(self, name, label, description, value, uid, group='allParams', advanced=False, semantic='', enabled=True): + super(ColorParam, self).__init__(name=name, label=label, description=description, value=value, uid=uid, group=group, advanced=advanced, semantic=semantic, enabled=enabled) + + def validateValue(self, value): + if not isinstance(value, pyCompatibility.basestring) or len(value.split(" ")) > 1: + raise ValueError('ColorParam value should be a string containing either an SVG name or an hexadecimal ' + 'color code (param: {}, value: {}, type: {})'.format(self.name, value, type(value))) + return value + + class Level(Enum): NONE = 0 NORMAL = 1 @@ -508,6 +521,13 @@ class Node(object): description="Custom label to replace the node's default label.", value="", uid=[], + ), + ColorParam( + name="color", + label="Color", + description="Custom color for the node (SVG name or hexadecimal code).", + value="", + uid=[], ) ] inputs = [] diff --git a/meshroom/core/node.py b/meshroom/core/node.py index d2ed68e8..210ab33a 100644 --- a/meshroom/core/node.py +++ b/meshroom/core/node.py @@ -532,6 +532,15 @@ class BaseNode(BaseObject): return label return self.nameToLabel(self._name) + def getColor(self): + """ + Returns: + str: the user-provided custom color of the node if it exists, empty string otherwise + """ + if self.hasInternalAttribute("color"): + return self.internalAttribute("color").value.strip() + return "" + @Slot(str, result=str) def nameToLabel(self, name): """ @@ -1088,6 +1097,7 @@ class BaseNode(BaseObject): name = Property(str, getName, constant=True) label = Property(str, getLabel, constant=True) + color = Property(str, getColor, constant=True) nodeType = Property(str, nodeType.fget, constant=True) documentation = Property(str, getDocumentation, constant=True) positionChanged = Signal() diff --git a/meshroom/ui/qml/GraphEditor/AttributeItemDelegate.qml b/meshroom/ui/qml/GraphEditor/AttributeItemDelegate.qml index dcb6f6d6..2d3ad5f9 100644 --- a/meshroom/ui/qml/GraphEditor/AttributeItemDelegate.qml +++ b/meshroom/ui/qml/GraphEditor/AttributeItemDelegate.qml @@ -157,6 +157,8 @@ RowLayout { if (attribute.desc.semantic === 'multiline') return textArea_component return textField_component + case "ColorParam": + return color_component default: return textField_component } } @@ -240,6 +242,70 @@ RowLayout { } } + Component { + id: color_component + RowLayout { + CheckBox { + id: color_checkbox + Layout.alignment: Qt.AlignLeft + checked: node.color === "" ? false : true + text: "Custom Color" + onClicked: { + if(checked) { + _reconstruction.setAttribute(attribute, "#0000FF") + } else { + _reconstruction.setAttribute(attribute, "") + } + } + } + TextField { + id: colorText + Layout.alignment: Qt.AlignLeft + implicitWidth: 100 + enabled: color_checkbox.checked + visible: enabled + text: enabled ? attribute.value : "" + selectByMouse: true + onEditingFinished: setTextFieldAttribute(text) + onAccepted: setTextFieldAttribute(text) + Component.onDestruction: { + if(activeFocus) + setTextFieldAttribute(text) + } + } + + Rectangle { + height: colorText.height + width: colorText.width / 2 + Layout.alignment: Qt.AlignLeft + visible: color_checkbox.checked + color: color_checkbox.checked ? attribute.value : "" + + MouseArea { + anchors.fill: parent + onClicked: colorDialog.open() + } + } + + ColorDialog { + id: colorDialog + title: "Please choose a color" + color: attribute.value + onAccepted: { + colorText.text = color + // Artificially trigger change of attribute value + colorText.editingFinished() + close() + } + onRejected: close() + } + Item { + // Dummy item to fill out the space if needed + Layout.fillWidth: true + } + } + } + Component { id: comboBox_component ComboBox { diff --git a/meshroom/ui/qml/GraphEditor/Node.qml b/meshroom/ui/qml/GraphEditor/Node.qml index 5ddff3f4..6ddd30d1 100755 --- a/meshroom/ui/qml/GraphEditor/Node.qml +++ b/meshroom/ui/qml/GraphEditor/Node.qml @@ -74,6 +74,7 @@ Item { onInternalAttributesChanged: { nodeLabel.text = node ? node.label : "" + background.color = (node.color === "" ? Qt.lighter(activePalette.base, 1.4) : node.color) } } @@ -142,7 +143,7 @@ Item { Rectangle { id: background anchors.fill: nodeContent - color: Qt.lighter(activePalette.base, 1.4) + color: node.color === "" ? Qt.lighter(activePalette.base, 1.4) : node.color layer.enabled: true layer.effect: DropShadow { radius: 3; color: shadowColor } radius: 3