Set focus on text field when slider handle is active - CURA-4432

This commit is contained in:
ChrisTerBeke 2017-10-11 11:13:04 +02:00
parent a7368e1751
commit ea01d6ad01
2 changed files with 11 additions and 7 deletions

View File

@ -226,7 +226,7 @@ Item {
maximumValue: sliderRoot.maximumValue maximumValue: sliderRoot.maximumValue
value: sliderRoot.upperValue value: sliderRoot.upperValue
busy: UM.LayerView.busy busy: UM.LayerView.busy
setValue: sliderRoot.setUpperValue // connect callback functions setValue: upperHandle.setValue // connect callback functions
} }
} }
@ -306,7 +306,7 @@ Item {
maximumValue: sliderRoot.maximumValue maximumValue: sliderRoot.maximumValue
value: sliderRoot.lowerValue value: sliderRoot.lowerValue
busy: UM.LayerView.busy busy: UM.LayerView.busy
setValue: sliderRoot.setLowerValue // connect callback functions setValue: lowerHandle.setValue // connect callback functions
} }
} }
} }

View File

@ -22,13 +22,16 @@ UM.PointingRectangle {
arrowSize: UM.Theme.getSize("default_arrow").width arrowSize: UM.Theme.getSize("default_arrow").width
height: parent.height height: parent.height
width: valueLabel.width + UM.Theme.getSize("default_margin").width width: valueLabel.width + UM.Theme.getSize("default_margin").width
visible: false
// make sure the text field is focussed when pressing the parent handle
// needed to connect the key bindings when switching active handle
onVisibleChanged: if (visible) valueLabel.forceActiveFocus()
color: UM.Theme.getColor("tool_panel_background") color: UM.Theme.getColor("tool_panel_background")
borderColor: UM.Theme.getColor("lining") borderColor: UM.Theme.getColor("lining")
borderWidth: UM.Theme.getSize("default_lining").width borderWidth: UM.Theme.getSize("default_lining").width
visible: true
Behavior on height { Behavior on height {
NumberAnimation { NumberAnimation {
duration: 50 duration: 50
@ -53,6 +56,10 @@ UM.PointingRectangle {
text: sliderLabelRoot.value + 1 // the current handle value, add 1 because layers is an array text: sliderLabelRoot.value + 1 // the current handle value, add 1 because layers is an array
horizontalAlignment: TextInput.AlignRight horizontalAlignment: TextInput.AlignRight
// key bindings, work when label is currenctly focused (active handle in LayerSlider)
Keys.onUpPressed: sliderLabelRoot.setValue(sliderLabelRoot.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
Keys.onDownPressed: sliderLabelRoot.setValue(sliderLabelRoot.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
style: TextFieldStyle { style: TextFieldStyle {
textColor: UM.Theme.getColor("setting_control_text") textColor: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default") font: UM.Theme.getFont("default")
@ -76,9 +83,6 @@ UM.PointingRectangle {
bottom: 1 bottom: 1
top: sliderLabelRoot.maximumValue + 1 // +1 because actual layers is an array top: sliderLabelRoot.maximumValue + 1 // +1 because actual layers is an array
} }
Keys.onUpPressed: sliderLabelRoot.setValue(sliderLabelRoot.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
Keys.onDownPressed: sliderLabelRoot.setValue(sliderLabelRoot.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
} }
BusyIndicator { BusyIndicator {