Skip to content

Commit

Permalink
Add "color" as an internal attribute
Browse files Browse the repository at this point in the history
Setting this attribute allows the user to change the color
of a node, either by directly providing an SVG color name or an
hexadecimal color code, or by picking a color with the selector.
  • Loading branch information
cbentejac committed Aug 1, 2022
1 parent 5fa9626 commit 457c826
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
8 changes: 8 additions & 0 deletions meshroom/core/desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ class Node(object):
description="Custom label to replace the node's default label.",
value="",
uid=[0],
),
StringParam(
name="color",
label="Color",
description="Custom color for the node (SVG name or hexadecimal code).",
semantic="color/bool",
value="",
uid=[0],
)
]
inputs = []
Expand Down
4 changes: 4 additions & 0 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ def getLabel(self):
return self._internalAttributes.get("label").value.strip()
return self.nameToLabel(self._name)

def getColor(self):
return self._internalAttributes.get("color").value.strip()

@Slot(str, result=str)
def nameToLabel(self, name):
"""
Expand Down Expand Up @@ -1049,6 +1052,7 @@ def canBeCanceled(self):

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()
Expand Down
66 changes: 66 additions & 0 deletions meshroom/ui/qml/GraphEditor/AttributeItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ RowLayout {
case "StringParam":
if(attribute.desc.semantic === 'multiline')
return textArea_component
if(attribute.desc.semantic === 'color/bool')
return color_textField_component
return textField_component
default: return textField_component
}
Expand Down Expand Up @@ -240,6 +242,70 @@ RowLayout {
}
}

Component {
id: color_textField_component
RowLayout {
CheckBox {
id: color_textField_checkbox
Layout.alignment: Qt.AlignLeft
checked: node.color === "" ? false : true
text: checked ? "Disable custom color" : "Enable custom color"
onClicked: {
if(checked) {
_reconstruction.setAttribute(attribute, "#0000FF")
} else {
_reconstruction.setAttribute(attribute, "")
}
}
}
TextField {
id: colorText
Layout.alignment: Qt.AlignLeft
implicitWidth: 100
enabled: color_textField_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
color: color_textField_checkbox.checked ? attribute.value : "white"
visible: color_textField_checkbox.checked

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 {
Expand Down
3 changes: 2 additions & 1 deletion meshroom/ui/qml/GraphEditor/Node.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Item {

onInternalAttributesChanged: {
nodeLabel.text = node ? node.label : ""
background.color = (node.color === "" ? Qt.lighter(activePalette.base, 1.4) : node.color)
}
}

Expand Down Expand Up @@ -140,7 +141,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
Expand Down

0 comments on commit 457c826

Please sign in to comment.