diff --git a/resources/qml/Preferences/Materials/MaterialsView.qml b/resources/qml/Preferences/Materials/MaterialsView.qml index a3aa451963..6511812057 100644 --- a/resources/qml/Preferences/Materials/MaterialsView.qml +++ b/resources/qml/Preferences/Materials/MaterialsView.qml @@ -243,7 +243,7 @@ Item value: properties.density decimals: 2 suffix: " g/cm³" -// stepSize: 0.01 // spinboxes can only cointain reals, a non-integer value can not be entered as the step size + stepSize: 0.01 onEditingFinished: base.setMetaDataEntry("properties/density", properties.density, value) onValueChanged: updateCostPerMeter() @@ -258,7 +258,7 @@ Item value: properties.diameter decimals: 2 suffix: " mm" -// stepSize: 0.01 // spinboxes can only cointain reals, a non-integer value can not be entered as the step size + stepSize: 0.01 onEditingFinished: { @@ -389,12 +389,6 @@ Item Item { width: parent.width; height: UM.Theme.getSize("default_margin").height } } - - function updateCostPerMeter() - { - base.spoolLength = calculateSpoolLength(diameterSpinBox.value, densitySpinBox.value, spoolWeightSpinBox.value); - base.costPerMeter = calculateCostPerMeter(spoolCostSpinBox.value); - } } ListView @@ -606,4 +600,10 @@ Item base.setMetaDataEntry("brand", old_brand, new_brand) properties.brand = new_brand } + + function updateCostPerMeter() + { + base.spoolLength = calculateSpoolLength(diameterSpinBox.value, densitySpinBox.value, spoolWeightSpinBox.value); + base.costPerMeter = calculateCostPerMeter(spoolCostSpinBox.value); + } } diff --git a/resources/qml/SpinBox.qml b/resources/qml/SpinBox.qml index e71435d8c9..956ffdaa10 100644 --- a/resources/qml/SpinBox.qml +++ b/resources/qml/SpinBox.qml @@ -4,44 +4,74 @@ import QtQuick 2.2 import QtQuick.Controls 2.15 -SpinBox +Item { id: base + height: spinBox.height + property string prefix: "" property string suffix: "" property int decimals: 0 + property real stepSize: 1 + property real value: 0 + property real from: 0 + property real to: 99 - signal editingFinished() + property alias wrap: spinBox.wrap - valueFromText: function(text) - { - return parseFloat(text.substring(prefix.length, text.length - suffix.length), decimals); - } + property bool editable: true - textFromValue: function(value) - { - return prefix + value.toFixed(decimals) + suffix - } - - validator: RegExpValidator + property var validator: RegExpValidator { regExp: new RegExp("^" + prefix + "([0-9]+[.|,]?[0-9]*)?" + suffix + "$") } - contentItem: TextField + signal editingFinished() + + SpinBox { - text: base.textFromValue(base.value, base.locale) - selectByMouse: true - background: Item {} + id: spinBox + anchors.fill: base + + stepSize: 1 + + value: Math.floor(base.value / base.stepSize) + from: Math.floor(base.from / base.stepSize) + to: Math.floor(base.to / base.stepSize) + editable: base.editable + + valueFromText: function(text) + { + return parseFloat(text.substring(prefix.length, text.length - suffix.length)) / base.stepSize; + } + + textFromValue: function(value) + { + return prefix + (value * base.stepSize).toFixed(decimals) + suffix; + } + validator: base.validator - onActiveFocusChanged: + onValueModified: { - if(!activeFocus) + base.value = value * base.stepSize; + } + + contentItem: TextField + { + text: spinBox.textFromValue(spinBox.value, spinBox.locale) + selectByMouse: base.editable + background: Item {} + validator: base.validator + + onActiveFocusChanged: { - base.editingFinished() + if(!activeFocus) + { + base.editingFinished(); + } } } } -} \ No newline at end of file +}