mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-13 20:05:56 +08:00
Allow SpinBox
components to contain fractional values
This commit is contained in:
parent
a0e5d66299
commit
9c2d370e72
@ -243,7 +243,7 @@ Item
|
|||||||
value: properties.density
|
value: properties.density
|
||||||
decimals: 2
|
decimals: 2
|
||||||
suffix: " g/cm³"
|
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)
|
onEditingFinished: base.setMetaDataEntry("properties/density", properties.density, value)
|
||||||
onValueChanged: updateCostPerMeter()
|
onValueChanged: updateCostPerMeter()
|
||||||
@ -258,7 +258,7 @@ Item
|
|||||||
value: properties.diameter
|
value: properties.diameter
|
||||||
decimals: 2
|
decimals: 2
|
||||||
suffix: " mm"
|
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:
|
onEditingFinished:
|
||||||
{
|
{
|
||||||
@ -389,12 +389,6 @@ Item
|
|||||||
|
|
||||||
Item { width: parent.width; height: UM.Theme.getSize("default_margin").height }
|
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
|
ListView
|
||||||
@ -606,4 +600,10 @@ Item
|
|||||||
base.setMetaDataEntry("brand", old_brand, new_brand)
|
base.setMetaDataEntry("brand", old_brand, new_brand)
|
||||||
properties.brand = new_brand
|
properties.brand = new_brand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateCostPerMeter()
|
||||||
|
{
|
||||||
|
base.spoolLength = calculateSpoolLength(diameterSpinBox.value, densitySpinBox.value, spoolWeightSpinBox.value);
|
||||||
|
base.costPerMeter = calculateCostPerMeter(spoolCostSpinBox.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,43 +4,73 @@
|
|||||||
import QtQuick 2.2
|
import QtQuick 2.2
|
||||||
import QtQuick.Controls 2.15
|
import QtQuick.Controls 2.15
|
||||||
|
|
||||||
SpinBox
|
Item
|
||||||
{
|
{
|
||||||
id: base
|
id: base
|
||||||
|
|
||||||
|
height: spinBox.height
|
||||||
|
|
||||||
property string prefix: ""
|
property string prefix: ""
|
||||||
property string suffix: ""
|
property string suffix: ""
|
||||||
property int decimals: 0
|
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)
|
property bool editable: true
|
||||||
{
|
|
||||||
return parseFloat(text.substring(prefix.length, text.length - suffix.length), decimals);
|
|
||||||
}
|
|
||||||
|
|
||||||
textFromValue: function(value)
|
property var validator: RegExpValidator
|
||||||
{
|
|
||||||
return prefix + value.toFixed(decimals) + suffix
|
|
||||||
}
|
|
||||||
|
|
||||||
validator: RegExpValidator
|
|
||||||
{
|
{
|
||||||
regExp: new RegExp("^" + prefix + "([0-9]+[.|,]?[0-9]*)?" + suffix + "$")
|
regExp: new RegExp("^" + prefix + "([0-9]+[.|,]?[0-9]*)?" + suffix + "$")
|
||||||
}
|
}
|
||||||
|
|
||||||
contentItem: TextField
|
signal editingFinished()
|
||||||
|
|
||||||
|
SpinBox
|
||||||
{
|
{
|
||||||
text: base.textFromValue(base.value, base.locale)
|
id: spinBox
|
||||||
selectByMouse: true
|
anchors.fill: base
|
||||||
background: Item {}
|
|
||||||
|
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
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user