mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Simplify rounding
Use sliders stepSize and snapMode properties CURA-9793
This commit is contained in:
parent
aaab633912
commit
e03b4e07f9
@ -38,7 +38,6 @@ RecommendedSettingSection
|
||||
height: UM.Theme.getSize("combobox").height
|
||||
width: parent.width
|
||||
settingName: "infill_sparse_density"
|
||||
roundToNearestTen: true
|
||||
updateAllExtruders: true
|
||||
// disable slider when gradual support is enabled
|
||||
enabled: parseInt(infillSteps.properties.value) == 0
|
||||
|
@ -11,24 +11,25 @@ import Cura 1.7 as Cura
|
||||
// All of the setting updating logic is handled by this component.
|
||||
// This component allows you to choose values between minValue -> maxValue and rounds them to the nearest 10.
|
||||
// If the setting is limited to a single extruder or is settable with different values per extruder use "updateAllExtruders: true"
|
||||
Item
|
||||
UM.Slider
|
||||
{
|
||||
height: childrenRect.height
|
||||
id: settingSlider
|
||||
|
||||
property alias settingName: propertyProvider.key
|
||||
property alias enabled: settingSlider.enabled
|
||||
|
||||
// If true, all extruders will have "settingName" property updated.
|
||||
// The displayed value will be read from the extruder with index "defaultExtruderIndex" instead of the machine.
|
||||
property bool updateAllExtruders: false
|
||||
// This is only used if updateAllExtruders == true
|
||||
property int defaultExtruderIndex: 0
|
||||
|
||||
property bool roundToNearestTen: false
|
||||
property int maxValue: 100
|
||||
property int minValue: 0
|
||||
property int previousValue: -1
|
||||
|
||||
// set range from 0 to 100
|
||||
from: 0; to: 100
|
||||
// set stepSize to 10 and set snapMode to snap on release snapMode is needed
|
||||
// otherwise the used percentage and slider handle show different values
|
||||
stepSize: 10; snapMode: Slider.SnapOnRelease
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
{
|
||||
id: propertyProvider
|
||||
@ -37,24 +38,15 @@ Item
|
||||
storeIndex: 0
|
||||
}
|
||||
|
||||
UM.Slider
|
||||
// set initial value from stack
|
||||
value: parseInt(propertyProvider.properties.value)
|
||||
|
||||
// When the slider is released trigger an update immediately. This forces the slider to snap to the rounded value.
|
||||
onPressedChanged: function(pressed)
|
||||
{
|
||||
id: settingSlider
|
||||
|
||||
width: parent.width
|
||||
|
||||
from: minValue; to: maxValue; stepSize: 1
|
||||
|
||||
// set initial value from stack
|
||||
value: parseInt(propertyProvider.properties.value)
|
||||
|
||||
// When the slider is released trigger an update immediately. This forces the slider to snap to the rounded value.
|
||||
onPressedChanged: function(pressed)
|
||||
if(!pressed)
|
||||
{
|
||||
if(!pressed)
|
||||
{
|
||||
roundSliderValueUpdateSetting();
|
||||
}
|
||||
updateSetting(settingSlider.value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,14 +77,6 @@ Item
|
||||
settingSlider.value = value
|
||||
}
|
||||
|
||||
function roundSliderValueUpdateSetting()
|
||||
{
|
||||
// If the user interacts with the slider we round the value and update the setting.
|
||||
const roundedSliderValue = roundToNearestTen ? Math.round(settingSlider.value / 10) * 10 : Math.round(settingSlider.value)
|
||||
updateSetting(roundedSliderValue)
|
||||
}
|
||||
|
||||
|
||||
function parseValueUpdateSetting(triggerUpdate)
|
||||
{
|
||||
// Only run when the setting value is updated by something other than the slider.
|
||||
|
Loading…
x
Reference in New Issue
Block a user