forked from qt-creator/qt-creator
QmlDesigner: Handle keyboard accept and reject operations in RealSpinBox
Fixes: QDS-11748 Change-Id: Id8770ffc1ab2057f4003d8734bf21b2f6c5a11ad Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Shrief Gabr <shrief.gabr@qt.io>
This commit is contained in:
@@ -188,6 +188,18 @@ T.SpinBox {
|
||||
}
|
||||
|
||||
onTextEdited: control.dirty = true
|
||||
|
||||
Keys.onPressed: (event) => {
|
||||
if (event.key === Qt.Key_Enter) {
|
||||
let inputValue = control.valueFromAnyText(spinBoxInput.text, control.locale)
|
||||
control.setRealValue(inputValue)
|
||||
spinBoxInput.focus = false
|
||||
} else if (event.key === Qt.Key_Escape) {
|
||||
let controlText = control.textFromAnyValue(control.realValue, control.locale)
|
||||
spinBoxInput.text = controlText
|
||||
spinBoxInput.focus = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
@@ -226,14 +238,11 @@ T.SpinBox {
|
||||
}
|
||||
|
||||
textFromValue: function (value, locale) {
|
||||
locale.numberOptions = Locale.OmitGroupSeparator
|
||||
var decimals = trailingZeroes ? control.decimals : decimalCounter(value)
|
||||
|
||||
return Number(control.realValue).toLocaleString(locale, 'f', decimals)
|
||||
return control.textFromAnyValue(control.realValue, locale)
|
||||
}
|
||||
|
||||
valueFromText: function (text, locale) {
|
||||
control.setRealValue(Number.fromLocaleString(locale, spinBoxInput.text))
|
||||
control.setRealValue(control.valueFromAnyText(spinBoxInput.text, locale))
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -436,4 +445,14 @@ T.SpinBox {
|
||||
|
||||
return Math.min(index, control.decimals);
|
||||
}
|
||||
|
||||
function textFromAnyValue(value: real, locale: var) : string {
|
||||
locale.numberOptions = Locale.OmitGroupSeparator
|
||||
var decimals = control.trailingZeroes ? control.decimals : control.decimalCounter(value)
|
||||
return Number(value).toLocaleString(locale, 'f', decimals)
|
||||
}
|
||||
|
||||
function valueFromAnyText(text: string, locale: var) : var {
|
||||
return Number.fromLocaleString(locale, text)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user