Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions meshroom/ui/qml/Utils/ExpressionTextField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ TextField {

// evaluated numeric value (NaN if invalid)
// It helps keeping the connection that text has so that we don't loose ability to undo/reset
property bool textChanged: false
property bool exprTextChanged: false
property real evaluatedValue: 0

property bool hasExprError: false
property bool isInt: false
property int decimals: 2

// Overlay for error state (red border on top of default background)
Rectangle {
Expand All @@ -36,8 +35,6 @@ TextField {
if (_err == false) {
if (isInt)
_res = Math.round(_res)
else
_res = _res.toFixed(decimals)
return _res
} else {
console.error("Error: Expression", _text, "is invalid")
Expand All @@ -63,7 +60,7 @@ TextField {
evaluatedValue = previousEvaluatedValue
raiseError()
}
textChanged = false
exprTextChanged = false
}

// onAccepted and onEditingFinished will break the bindings to text
Expand All @@ -72,42 +69,42 @@ TextField {
// No need to restore the binding if the expression has an error because we don't break it

onAccepted: {
if (textChanged)
if (exprTextChanged)
{
updateExpression()
if (!hasExprError && !isNaN(evaluatedValue)) {
// Commit the result value to the text field
if (isInt)
root.text = Number(evaluatedValue).toFixed(0)
else
root.text = Number(evaluatedValue).toFixed(decimals)
root.text = Number(evaluatedValue)
}
}
}

onEditingFinished: {
if (textChanged)
if (exprTextChanged)
{
updateExpression()
if (!hasExprError && !isNaN(evaluatedValue)) {
if (isInt)
root.text = Number(evaluatedValue).toFixed(0)
else
root.text = Number(evaluatedValue).toFixed(decimals)
root.text = Number(evaluatedValue)
}
}
}

onTextChanged: {
if (!activeFocus) {
if (!activeFocus && exprTextChanged) {
refreshStatus()
} else {
textChanged = true
exprTextChanged = true
}
}

Component.onDestruction: {
if (textChanged) {
if (exprTextChanged) {
root.accepted()
}
}
Expand Down
4 changes: 1 addition & 3 deletions meshroom/ui/qml/Viewer/HdrImageToolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ FloatingPane {
ToolTip.text: "Color Gain (in linear colorspace)"

text: gainValue
decimals: 2
Layout.preferredWidth: textMetrics_gainValue.width
selectByMouse: true
onAccepted: {
Expand Down Expand Up @@ -164,7 +163,7 @@ FloatingPane {

onClicked: {
gammaLabel.text = gammaDefaultValue
gammaCtrl.value = gammaLabel.text;
gammaCtrl.value = gammaLabel.text
}
}
ExpressionTextField {
Expand All @@ -175,7 +174,6 @@ FloatingPane {
ToolTip.text: "Apply Gamma (after Gain and in linear colorspace)"

text: gammaValue
decimals: 2
Layout.preferredWidth: textMetrics_gainValue.width
selectByMouse: true
onAccepted: {
Expand Down