forked from qt-creator/qt-creator
QmlDesigner: Input lose focus after pressing enter
* Add losing focus after pressing Return/Enter for all TextInputs * Add losing focus and reverting values after pressing Escape for all TextInputs * FontComboBox fix initial value selection * Code cleanup Task-number: QDS-5972 Task-number: QDS-6028 Change-Id: Ice7449e89088f6e7da76eb7c2edefab647b109de Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Henning Gründl
parent
e865b03448
commit
414fb08bc6
@@ -92,7 +92,6 @@ StudioControls.ComboBox {
|
|||||||
onValueFromBackendChanged: colorLogic.invalidate()
|
onValueFromBackendChanged: colorLogic.invalidate()
|
||||||
|
|
||||||
function invalidate() {
|
function invalidate() {
|
||||||
|
|
||||||
if (comboBox.block)
|
if (comboBox.block)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -140,6 +139,21 @@ StudioControls.ComboBox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onAccepted: {
|
||||||
|
if (!comboBox.__isCompleted)
|
||||||
|
return
|
||||||
|
|
||||||
|
let inputValue = comboBox.editText
|
||||||
|
|
||||||
|
let index = comboBox.find(inputValue)
|
||||||
|
if (index !== -1)
|
||||||
|
inputValue = comboBox.textAt(index)
|
||||||
|
|
||||||
|
comboBox.backendValue.value = inputValue
|
||||||
|
|
||||||
|
comboBox.dirty = false
|
||||||
|
}
|
||||||
|
|
||||||
onCompressedActivated: {
|
onCompressedActivated: {
|
||||||
if (!comboBox.__isCompleted)
|
if (!comboBox.__isCompleted)
|
||||||
return
|
return
|
||||||
|
@@ -29,7 +29,7 @@ import HelperWidgets 2.0
|
|||||||
import StudioControls 1.0 as StudioControls
|
import StudioControls 1.0 as StudioControls
|
||||||
|
|
||||||
StudioControls.ComboBox {
|
StudioControls.ComboBox {
|
||||||
id: comboBox
|
id: root
|
||||||
|
|
||||||
property variant backendValue
|
property variant backendValue
|
||||||
property color textColor: colorLogic.textColor
|
property color textColor: colorLogic.textColor
|
||||||
@@ -39,17 +39,17 @@ StudioControls.ComboBox {
|
|||||||
labelColor: colorLogic.textColor
|
labelColor: colorLogic.textColor
|
||||||
editable: true
|
editable: true
|
||||||
|
|
||||||
onTextColorChanged: setColor()
|
onTextColorChanged: root.setColor()
|
||||||
|
|
||||||
FileResourcesModel {
|
FileResourcesModel {
|
||||||
id: fileModel
|
id: fileModel
|
||||||
modelNodeBackendProperty: modelNodeBackend
|
modelNodeBackendProperty: modelNodeBackend
|
||||||
filter: comboBox.fontFilter
|
filter: root.fontFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFontLoader(fontUrl) {
|
function createFontLoader(fontUrl) {
|
||||||
return Qt.createQmlObject('import QtQuick 2.0; FontLoader { source: "' + fontUrl + '"; }',
|
return Qt.createQmlObject('import QtQuick 2.0; FontLoader { source: "' + fontUrl + '"; }',
|
||||||
comboBox, "dynamicFontLoader")
|
root, "dynamicFontLoader")
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupModel() {
|
function setupModel() {
|
||||||
@@ -63,80 +63,83 @@ StudioControls.ComboBox {
|
|||||||
// Remove duplicate family names
|
// Remove duplicate family names
|
||||||
familyNames = [...new Set(familyNames)]
|
familyNames = [...new Set(familyNames)]
|
||||||
familyNames.sort()
|
familyNames.sort()
|
||||||
comboBox.model = familyNames
|
root.model = familyNames
|
||||||
|
root.currentIndex = root.find(root.backendValue.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
onModelChanged: editText = comboBox.backendValue.valueToString
|
function setColor() {
|
||||||
|
// Hack to style the text input
|
||||||
|
for (var i = 0; i < root.children.length; i++) {
|
||||||
|
if (root.children[i].text !== undefined) {
|
||||||
|
root.children[i].color = root.textColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onModelChanged: root.editText = root.backendValue.valueToString
|
||||||
|
|
||||||
ExtendedFunctionLogic {
|
ExtendedFunctionLogic {
|
||||||
id: extFuncLogic
|
id: extFuncLogic
|
||||||
backendValue: comboBox.backendValue
|
backendValue: root.backendValue
|
||||||
}
|
}
|
||||||
|
|
||||||
actionIndicator.icon.color: extFuncLogic.color
|
actionIndicator.icon.color: extFuncLogic.color
|
||||||
actionIndicator.icon.text: extFuncLogic.glyph
|
actionIndicator.icon.text: extFuncLogic.glyph
|
||||||
actionIndicator.onClicked: extFuncLogic.show()
|
actionIndicator.onClicked: extFuncLogic.show()
|
||||||
actionIndicator.forceVisible: extFuncLogic.menuVisible
|
actionIndicator.forceVisible: extFuncLogic.menuVisible
|
||||||
actionIndicator.visible: comboBox.showExtendedFunctionButton
|
actionIndicator.visible: root.showExtendedFunctionButton
|
||||||
|
|
||||||
ColorLogic {
|
ColorLogic {
|
||||||
id: colorLogic
|
id: colorLogic
|
||||||
property string textValue: comboBox.backendValue.valueToString
|
property string textValue: root.backendValue.valueToString
|
||||||
backendValue: comboBox.backendValue
|
backendValue: root.backendValue
|
||||||
onTextValueChanged: comboBox.editText = colorLogic.textValue
|
onTextValueChanged: root.editText = colorLogic.textValue
|
||||||
}
|
}
|
||||||
|
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
if (backendValue === undefined)
|
if (root.backendValue === undefined)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (editText === "")
|
if (root.editText === "")
|
||||||
return
|
return
|
||||||
|
|
||||||
if (backendValue.value !== editText)
|
if (root.backendValue.value !== root.editText)
|
||||||
backendValue.value = editText;
|
root.backendValue.value = root.editText
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivated: {
|
onCompressedActivated: function(index, reason) { root.handleActivate(index) }
|
||||||
if (backendValue === undefined)
|
|
||||||
|
function handleActivate(index)
|
||||||
|
{
|
||||||
|
if (root.backendValue === undefined)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (editText === "")
|
if (root.editText === "")
|
||||||
return
|
return
|
||||||
|
|
||||||
var indexText = comboBox.textAt(index)
|
var indexText = root.textAt(index)
|
||||||
|
|
||||||
if (backendValue.value !== indexText)
|
if (root.backendValue.value !== indexText)
|
||||||
backendValue.value = indexText
|
root.backendValue.value = indexText
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: modelNodeBackend
|
target: modelNodeBackend
|
||||||
function onSelectionChanged() {
|
function onSelectionChanged() {
|
||||||
comboBox.editText = backendValue.value
|
root.editText = root.backendValue.value
|
||||||
setupModel()
|
root.setupModel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
setupModel()
|
root.setupModel()
|
||||||
// Hack to style the text input
|
// Hack to style the text input
|
||||||
for (var i = 0; i < comboBox.children.length; i++) {
|
for (var i = 0; i < root.children.length; i++) {
|
||||||
if (comboBox.children[i].text !== undefined) {
|
if (root.children[i].text !== undefined) {
|
||||||
comboBox.children[i].color = comboBox.textColor
|
root.children[i].color = root.textColor
|
||||||
comboBox.children[i].anchors.rightMargin = 34
|
root.children[i].anchors.rightMargin = 34
|
||||||
comboBox.children[i].anchors.leftMargin = 18
|
root.children[i].anchors.leftMargin = 18
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setColor() {
|
|
||||||
// Hack to style the text input
|
|
||||||
for (var i = 0; i < comboBox.children.length; i++) {
|
|
||||||
if (comboBox.children[i].text !== undefined) {
|
|
||||||
comboBox.children[i].color = comboBox.textColor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -32,36 +32,43 @@ StudioControls.TextField {
|
|||||||
id: lineEdit
|
id: lineEdit
|
||||||
|
|
||||||
property variant backendValue
|
property variant backendValue
|
||||||
property color borderColor: "#222"
|
|
||||||
property color highlightColor: "orange"
|
|
||||||
color: lineEdit.edit ? StudioTheme.Values.themeTextColor : colorLogic.textColor
|
|
||||||
|
|
||||||
property bool showTranslateCheckBox: true
|
|
||||||
translationIndicatorVisible: showTranslateCheckBox
|
|
||||||
|
|
||||||
property bool writeValueManually: false
|
property bool writeValueManually: false
|
||||||
property bool writeAsExpression: false
|
property bool writeAsExpression: false
|
||||||
|
|
||||||
property bool __dirty: false
|
property bool showTranslateCheckBox: true
|
||||||
|
|
||||||
property bool showExtendedFunctionButton: true
|
property bool showExtendedFunctionButton: true
|
||||||
|
property string context
|
||||||
|
|
||||||
actionIndicator.visible: showExtendedFunctionButton
|
property bool __dirty: false
|
||||||
|
|
||||||
signal commitData
|
signal commitData
|
||||||
|
|
||||||
property string context
|
color: lineEdit.edit ? StudioTheme.Values.themeTextColor : colorLogic.textColor
|
||||||
|
actionIndicator.visible: lineEdit.showExtendedFunctionButton
|
||||||
|
translationIndicatorVisible: lineEdit.showTranslateCheckBox
|
||||||
|
|
||||||
function setTranslateExpression() {
|
function setTranslateExpression() {
|
||||||
if (translateFunction() === "qsTranslate") {
|
if (translateFunction() === "qsTranslate") {
|
||||||
backendValue.expression = translateFunction()
|
lineEdit.backendValue.expression = translateFunction()
|
||||||
+ "(\"" + backendValue.getTranslationContext()
|
+ "(\"" + lineEdit.backendValue.getTranslationContext()
|
||||||
+ "\", " + "\"" + escapeString(text) + "\")"
|
+ "\", " + "\"" + lineEdit.escapeString(lineEdit.text) + "\")"
|
||||||
} else {
|
} else {
|
||||||
backendValue.expression = translateFunction() + "(\"" + escapeString(text) + "\")"
|
lineEdit.backendValue.expression = translateFunction()
|
||||||
|
+ "(\"" + lineEdit.escapeString(lineEdit.text) + "\")"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeString(string) {
|
||||||
|
var str = string
|
||||||
|
str = str.replace(/\\/g, "\\\\")
|
||||||
|
str.replace(/\"/g, "\\\"")
|
||||||
|
str = str.replace(/\t/g, "\\t")
|
||||||
|
str = str.replace(/\r/g, "\\r")
|
||||||
|
str = str.replace(/\n/g, '\\n')
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
ExtendedFunctionLogic {
|
ExtendedFunctionLogic {
|
||||||
id: extFuncLogic
|
id: extFuncLogic
|
||||||
backendValue: lineEdit.backendValue
|
backendValue: lineEdit.backendValue
|
||||||
@@ -79,60 +86,58 @@ StudioControls.TextField {
|
|||||||
if (colorLogic.valueFromBackend === undefined) {
|
if (colorLogic.valueFromBackend === undefined) {
|
||||||
lineEdit.text = ""
|
lineEdit.text = ""
|
||||||
} else {
|
} else {
|
||||||
if (writeValueManually)
|
if (lineEdit.writeValueManually)
|
||||||
lineEdit.text = convertColorToString(colorLogic.valueFromBackend)
|
lineEdit.text = convertColorToString(colorLogic.valueFromBackend)
|
||||||
else
|
else
|
||||||
lineEdit.text = colorLogic.valueFromBackend
|
lineEdit.text = colorLogic.valueFromBackend
|
||||||
}
|
}
|
||||||
__dirty = false
|
lineEdit.__dirty = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: lineEdit.__dirty = true
|
||||||
__dirty = true
|
|
||||||
}
|
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: modelNodeBackend
|
target: modelNodeBackend
|
||||||
function onSelectionToBeChanged() {
|
function onSelectionToBeChanged() {
|
||||||
if (__dirty && !writeValueManually) {
|
if (lineEdit.__dirty && !lineEdit.writeValueManually) {
|
||||||
if (writeAsExpression)
|
if (lineEdit.writeAsExpression)
|
||||||
lineEdit.backendValue.expression = text
|
lineEdit.backendValue.expression = lineEdit.text
|
||||||
else
|
else
|
||||||
lineEdit.backendValue.value = text
|
lineEdit.backendValue.value = lineEdit.text
|
||||||
} else if (__dirty) {
|
} else if (lineEdit.__dirty) {
|
||||||
commitData()
|
commitData()
|
||||||
}
|
}
|
||||||
|
|
||||||
__dirty = false
|
lineEdit.__dirty = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onEditingFinished: {
|
onEditingFinished: {
|
||||||
if (writeValueManually)
|
if (lineEdit.writeValueManually)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (!__dirty)
|
if (!lineEdit.__dirty)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (backendValue.isTranslated) {
|
if (lineEdit.backendValue.isTranslated) {
|
||||||
setTranslateExpression()
|
lineEdit.setTranslateExpression()
|
||||||
} else {
|
} else {
|
||||||
if (writeAsExpression) {
|
if (lineEdit.writeAsExpression) {
|
||||||
if (lineEdit.backendValue.expression !== text)
|
if (lineEdit.backendValue.expression !== lineEdit.text)
|
||||||
lineEdit.backendValue.expression = text
|
lineEdit.backendValue.expression = lineEdit.text
|
||||||
} else if (lineEdit.backendValue.value !== text) {
|
} else if (lineEdit.backendValue.value !== lineEdit.text) {
|
||||||
lineEdit.backendValue.value = text
|
lineEdit.backendValue.value = lineEdit.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
__dirty = false
|
lineEdit.__dirty = false
|
||||||
}
|
}
|
||||||
|
|
||||||
property bool isTranslated: colorLogic.backendValue === undefined ? false
|
property bool isTranslated: colorLogic.backendValue === undefined ? false
|
||||||
: colorLogic.backendValue.isTranslated
|
: colorLogic.backendValue.isTranslated
|
||||||
|
|
||||||
translationIndicator.onClicked: {
|
translationIndicator.onClicked: {
|
||||||
if (translationIndicator.checked) {
|
if (lineEdit.translationIndicator.checked) {
|
||||||
setTranslateExpression()
|
setTranslateExpression()
|
||||||
} else {
|
} else {
|
||||||
var textValue = lineEdit.text
|
var textValue = lineEdit.text
|
||||||
@@ -141,7 +146,8 @@ StudioControls.TextField {
|
|||||||
colorLogic.evaluate()
|
colorLogic.evaluate()
|
||||||
}
|
}
|
||||||
|
|
||||||
property variant backendValueValueInternal: backendValue === undefined ? 0 : backendValue.value
|
property variant backendValueValueInternal: lineEdit.backendValue === undefined ? 0
|
||||||
|
: lineEdit.backendValue.value
|
||||||
onBackendValueValueInternalChanged: {
|
onBackendValueValueInternalChanged: {
|
||||||
if (lineEdit.backendValue === undefined)
|
if (lineEdit.backendValue === undefined)
|
||||||
lineEdit.translationIndicator.checked = false
|
lineEdit.translationIndicator.checked = false
|
||||||
@@ -155,15 +161,4 @@ StudioControls.TextField {
|
|||||||
else
|
else
|
||||||
lineEdit.translationIndicator.checked = lineEdit.backendValue.isTranslated
|
lineEdit.translationIndicator.checked = lineEdit.backendValue.isTranslated
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeString(string) {
|
|
||||||
var str = string
|
|
||||||
str = str.replace(/\\/g, "\\\\")
|
|
||||||
str.replace(/\"/g, "\\\"")
|
|
||||||
str = str.replace(/\t/g, "\\t")
|
|
||||||
str = str.replace(/\r/g, "\\r")
|
|
||||||
str = str.replace(/\n/g, '\\n')
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -51,15 +51,15 @@ Rectangle {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
if (myControl.activeFocus)
|
||||||
|
myControl.focus = false
|
||||||
|
|
||||||
if (myPopup.opened) {
|
if (myPopup.opened) {
|
||||||
myPopup.close()
|
myPopup.close()
|
||||||
} else {
|
} else {
|
||||||
myPopup.open()
|
myPopup.open()
|
||||||
myPopup.forceActiveFocus()
|
myPopup.forceActiveFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myControl.activeFocus)
|
|
||||||
myControl.focus = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -65,6 +65,11 @@ T.ComboBox {
|
|||||||
comboBoxPopup.close()
|
comboBoxPopup.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onActiveFocusChanged: {
|
||||||
|
if (myComboBox.activeFocus)
|
||||||
|
comboBoxInput.preFocusText = myComboBox.editText
|
||||||
|
}
|
||||||
|
|
||||||
ActionIndicator {
|
ActionIndicator {
|
||||||
id: actionIndicator
|
id: actionIndicator
|
||||||
myControl: myComboBox
|
myControl: myComboBox
|
||||||
@@ -76,19 +81,22 @@ T.ComboBox {
|
|||||||
|
|
||||||
contentItem: ComboBoxInput {
|
contentItem: ComboBoxInput {
|
||||||
id: comboBoxInput
|
id: comboBoxInput
|
||||||
|
|
||||||
|
property string preFocusText: ""
|
||||||
|
|
||||||
myControl: myComboBox
|
myControl: myComboBox
|
||||||
text: myComboBox.editText
|
text: myComboBox.editText
|
||||||
|
|
||||||
onEditingFinished: {
|
onEditingFinished: {
|
||||||
comboBoxInput.deselect()
|
comboBoxInput.deselect()
|
||||||
comboBoxInput.focus = false
|
comboBoxInput.focus = false
|
||||||
|
myComboBox.focus = false
|
||||||
|
|
||||||
// Only trigger the signal, if the value was modified
|
// Only trigger the signal, if the value was modified
|
||||||
if (myComboBox.dirty) {
|
if (myComboBox.dirty) {
|
||||||
myTimer.stop()
|
myTimer.stop()
|
||||||
myComboBox.dirty = false
|
myComboBox.dirty = false
|
||||||
myComboBox.compressedActivated(myComboBox.find(myComboBox.editText),
|
myComboBox.accepted()
|
||||||
ComboBox.ActivatedReason.EditingFinished)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onTextEdited: myComboBox.dirty = true
|
onTextEdited: myComboBox.dirty = true
|
||||||
@@ -312,7 +320,10 @@ T.ComboBox {
|
|||||||
]
|
]
|
||||||
|
|
||||||
Keys.onPressed: function(event) {
|
Keys.onPressed: function(event) {
|
||||||
if (event.key === Qt.Key_Escape)
|
if (event.key === Qt.Key_Escape) {
|
||||||
|
myComboBox.editText = comboBoxInput.preFocusText
|
||||||
|
myComboBox.dirty = true
|
||||||
myComboBox.focus = false
|
myComboBox.focus = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -73,13 +73,13 @@ TextInput {
|
|||||||
acceptedButtons: Qt.LeftButton
|
acceptedButtons: Qt.LeftButton
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onPressed: function(mouse) {
|
onPressed: function(mouse) {
|
||||||
if (textInput.readOnly) {
|
if (!textInput.myControl.editable) {
|
||||||
if (myControl.popup.opened) {
|
if (myControl.popup.opened) {
|
||||||
myControl.popup.close()
|
myControl.popup.close()
|
||||||
myControl.focus = false
|
myControl.focus = false
|
||||||
} else {
|
} else {
|
||||||
myControl.forceActiveFocus()
|
|
||||||
myControl.popup.open()
|
myControl.popup.open()
|
||||||
|
myControl.forceActiveFocus()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
textInput.forceActiveFocus()
|
textInput.forceActiveFocus()
|
||||||
|
@@ -113,8 +113,6 @@ Item {
|
|||||||
myTimer.stop()
|
myTimer.stop()
|
||||||
root.dirty = false
|
root.dirty = false
|
||||||
root.editText = root.editText.trim()
|
root.editText = root.editText.trim()
|
||||||
//root.compressedActivated(root.find(root.editText),
|
|
||||||
// ComboBox.ActivatedReason.EditingFinished)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
root.finishEditing()
|
root.finishEditing()
|
||||||
|
@@ -79,6 +79,8 @@ T.SpinBox {
|
|||||||
|
|
||||||
property alias compressedValueTimer: myTimer
|
property alias compressedValueTimer: myTimer
|
||||||
|
|
||||||
|
property string preFocusText: ""
|
||||||
|
|
||||||
signal realValueModified
|
signal realValueModified
|
||||||
signal compressedRealValueModified
|
signal compressedRealValueModified
|
||||||
signal dragStarted
|
signal dragStarted
|
||||||
@@ -162,6 +164,8 @@ T.SpinBox {
|
|||||||
validator: doubleValidator
|
validator: doubleValidator
|
||||||
|
|
||||||
function handleEditingFinished() {
|
function handleEditingFinished() {
|
||||||
|
mySpinBox.focus = false
|
||||||
|
|
||||||
// Keep the dirty state before calling setValueFromInput(),
|
// Keep the dirty state before calling setValueFromInput(),
|
||||||
// it will be set to false (cleared) internally
|
// it will be set to false (cleared) internally
|
||||||
var valueModified = mySpinBox.dirty
|
var valueModified = mySpinBox.dirty
|
||||||
@@ -174,7 +178,7 @@ T.SpinBox {
|
|||||||
mySpinBox.compressedRealValueModified()
|
mySpinBox.compressedRealValueModified()
|
||||||
}
|
}
|
||||||
|
|
||||||
onEditingFinished: handleEditingFinished()
|
onEditingFinished: spinBoxInput.handleEditingFinished()
|
||||||
onTextEdited: mySpinBox.dirty = true
|
onTextEdited: mySpinBox.dirty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +285,7 @@ T.SpinBox {
|
|||||||
id: myTimer
|
id: myTimer
|
||||||
repeat: false
|
repeat: false
|
||||||
running: false
|
running: false
|
||||||
interval: 200
|
interval: 400
|
||||||
onTriggered: mySpinBox.compressedRealValueModified()
|
onTriggered: mySpinBox.compressedRealValueModified()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,9 +310,11 @@ T.SpinBox {
|
|||||||
}
|
}
|
||||||
onDisplayTextChanged: spinBoxInput.text = mySpinBox.displayText
|
onDisplayTextChanged: spinBoxInput.text = mySpinBox.displayText
|
||||||
onActiveFocusChanged: {
|
onActiveFocusChanged: {
|
||||||
if (mySpinBox.activeFocus) // QTBUG-75862 && mySpinBox.focusReason === Qt.TabFocusReason)
|
if (mySpinBox.activeFocus) { // QTBUG-75862 && mySpinBox.focusReason === Qt.TabFocusReason)
|
||||||
|
mySpinBox.preFocusText = spinBoxInput.text
|
||||||
spinBoxInput.selectAll()
|
spinBoxInput.selectAll()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Keys.onPressed: function(event) {
|
Keys.onPressed: function(event) {
|
||||||
if (event.key === Qt.Key_Up || event.key === Qt.Key_Down) {
|
if (event.key === Qt.Key_Up || event.key === Qt.Key_Down) {
|
||||||
@@ -333,8 +339,11 @@ T.SpinBox {
|
|||||||
mySpinBox.realStepSize = currStepSize
|
mySpinBox.realStepSize = currStepSize
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === Qt.Key_Escape)
|
if (event.key === Qt.Key_Escape) {
|
||||||
mySpinBox.focus = false
|
spinBoxInput.text = mySpinBox.preFocusText
|
||||||
|
mySpinBox.dirty = true
|
||||||
|
spinBoxInput.handleEditingFinished()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clamp(v, lo, hi) {
|
function clamp(v, lo, hi) {
|
||||||
|
@@ -28,15 +28,15 @@ import QtQuick.Templates 2.15 as T
|
|||||||
import StudioTheme 1.0 as StudioTheme
|
import StudioTheme 1.0 as StudioTheme
|
||||||
|
|
||||||
T.TextField {
|
T.TextField {
|
||||||
id: myTextField
|
id: root
|
||||||
|
|
||||||
property alias actionIndicator: actionIndicator
|
property alias actionIndicator: actionIndicator
|
||||||
property alias translationIndicator: translationIndicator
|
property alias translationIndicator: translationIndicator
|
||||||
|
|
||||||
// This property is used to indicate the global hover state
|
// This property is used to indicate the global hover state
|
||||||
property bool hover: (actionIndicator.hover || mouseArea.containsMouse
|
property bool hover: (actionIndicator.hover || mouseArea.containsMouse
|
||||||
|| translationIndicator.hover) && myTextField.enabled
|
|| translationIndicator.hover) && root.enabled
|
||||||
property bool edit: myTextField.activeFocus
|
property bool edit: root.activeFocus
|
||||||
|
|
||||||
property alias actionIndicatorVisible: actionIndicator.visible
|
property alias actionIndicatorVisible: actionIndicator.visible
|
||||||
property real __actionIndicatorWidth: StudioTheme.Values.actionIndicatorWidth
|
property real __actionIndicatorWidth: StudioTheme.Values.actionIndicatorWidth
|
||||||
@@ -46,6 +46,8 @@ T.TextField {
|
|||||||
property real __translationIndicatorWidth: StudioTheme.Values.translationIndicatorWidth
|
property real __translationIndicatorWidth: StudioTheme.Values.translationIndicatorWidth
|
||||||
property real __translationIndicatorHeight: StudioTheme.Values.translationIndicatorHeight
|
property real __translationIndicatorHeight: StudioTheme.Values.translationIndicatorHeight
|
||||||
|
|
||||||
|
property string preFocusText: ""
|
||||||
|
|
||||||
horizontalAlignment: Qt.AlignLeft
|
horizontalAlignment: Qt.AlignLeft
|
||||||
verticalAlignment: Qt.AlignVCenter
|
verticalAlignment: Qt.AlignVCenter
|
||||||
|
|
||||||
@@ -78,7 +80,7 @@ T.TextField {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onPressed: function(mouse) {
|
onPressed: function(mouse) {
|
||||||
if (mouse.button === Qt.RightButton)
|
if (mouse.button === Qt.RightButton)
|
||||||
contextMenu.popup(myTextField)
|
contextMenu.popup(root)
|
||||||
|
|
||||||
mouse.accepted = false
|
mouse.accepted = false
|
||||||
}
|
}
|
||||||
@@ -86,43 +88,50 @@ T.TextField {
|
|||||||
|
|
||||||
onPersistentSelectionChanged: {
|
onPersistentSelectionChanged: {
|
||||||
if (!persistentSelection)
|
if (!persistentSelection)
|
||||||
myTextField.deselect()
|
root.deselect()
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextMenu {
|
ContextMenu {
|
||||||
id: contextMenu
|
id: contextMenu
|
||||||
myTextEdit: myTextField
|
myTextEdit: root
|
||||||
|
}
|
||||||
|
|
||||||
|
onActiveFocusChanged: {
|
||||||
|
if (root.activeFocus)
|
||||||
|
root.preFocusText = root.text
|
||||||
}
|
}
|
||||||
|
|
||||||
onEditChanged: {
|
onEditChanged: {
|
||||||
if (myTextField.edit)
|
if (root.edit)
|
||||||
contextMenu.close()
|
contextMenu.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onEditingFinished: root.focus = false
|
||||||
|
|
||||||
ActionIndicator {
|
ActionIndicator {
|
||||||
id: actionIndicator
|
id: actionIndicator
|
||||||
myControl: myTextField
|
myControl: root
|
||||||
x: 0
|
x: 0
|
||||||
y: 0
|
y: 0
|
||||||
width: actionIndicator.visible ? myTextField.__actionIndicatorWidth : 0
|
width: actionIndicator.visible ? root.__actionIndicatorWidth : 0
|
||||||
height: actionIndicator.visible ? myTextField.__actionIndicatorHeight : 0
|
height: actionIndicator.visible ? root.__actionIndicatorHeight : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: placeholder
|
id: placeholder
|
||||||
x: myTextField.leftPadding
|
x: root.leftPadding
|
||||||
y: myTextField.topPadding
|
y: root.topPadding
|
||||||
width: myTextField.width - (myTextField.leftPadding + myTextField.rightPadding)
|
width: root.width - (root.leftPadding + root.rightPadding)
|
||||||
height: myTextField.height - (myTextField.topPadding + myTextField.bottomPadding)
|
height: root.height - (root.topPadding + root.bottomPadding)
|
||||||
|
|
||||||
text: myTextField.placeholderText
|
text: root.placeholderText
|
||||||
font: myTextField.font
|
font: root.font
|
||||||
color: myTextField.placeholderTextColor
|
color: root.placeholderTextColor
|
||||||
verticalAlignment: myTextField.verticalAlignment
|
verticalAlignment: root.verticalAlignment
|
||||||
visible: !myTextField.length && !myTextField.preeditText
|
visible: !root.length && !root.preeditText
|
||||||
&& (!myTextField.activeFocus || myTextField.horizontalAlignment !== Qt.AlignHCenter)
|
&& (!root.activeFocus || root.horizontalAlignment !== Qt.AlignHCenter)
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
renderType: myTextField.renderType
|
renderType: root.renderType
|
||||||
}
|
}
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
@@ -131,14 +140,14 @@ T.TextField {
|
|||||||
border.color: StudioTheme.Values.themeControlOutline
|
border.color: StudioTheme.Values.themeControlOutline
|
||||||
border.width: StudioTheme.Values.border
|
border.width: StudioTheme.Values.border
|
||||||
x: actionIndicator.width
|
x: actionIndicator.width
|
||||||
width: myTextField.width - actionIndicator.width
|
width: root.width - actionIndicator.width
|
||||||
height: myTextField.height
|
height: root.height
|
||||||
}
|
}
|
||||||
|
|
||||||
TranslationIndicator {
|
TranslationIndicator {
|
||||||
id: translationIndicator
|
id: translationIndicator
|
||||||
myControl: myTextField
|
myControl: root
|
||||||
x: myTextField.width - translationIndicator.width
|
x: root.width - translationIndicator.width
|
||||||
width: translationIndicator.visible ? __translationIndicatorWidth : 0
|
width: translationIndicator.visible ? __translationIndicatorWidth : 0
|
||||||
height: translationIndicator.visible ? __translationIndicatorHeight : 0
|
height: translationIndicator.visible ? __translationIndicatorHeight : 0
|
||||||
}
|
}
|
||||||
@@ -146,15 +155,14 @@ T.TextField {
|
|||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "default"
|
name: "default"
|
||||||
when: myTextField.enabled && !myTextField.hover
|
when: root.enabled && !root.hover && !root.edit
|
||||||
&& !myTextField.edit
|
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackground
|
color: StudioTheme.Values.themeControlBackground
|
||||||
border.color: StudioTheme.Values.themeControlOutline
|
border.color: StudioTheme.Values.themeControlOutline
|
||||||
}
|
}
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: myTextField
|
target: root
|
||||||
color: StudioTheme.Values.themeTextColor
|
color: StudioTheme.Values.themeTextColor
|
||||||
placeholderTextColor: StudioTheme.Values.themePlaceholderTextColor
|
placeholderTextColor: StudioTheme.Values.themePlaceholderTextColor
|
||||||
}
|
}
|
||||||
@@ -165,15 +173,15 @@ T.TextField {
|
|||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "globalHover"
|
name: "globalHover"
|
||||||
when: (actionIndicator.hover || translationIndicator.hover) && !myTextField.edit
|
when: (actionIndicator.hover || translationIndicator.hover) && !root.edit
|
||||||
&& myTextField.enabled
|
&& root.enabled
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackgroundGlobalHover
|
color: StudioTheme.Values.themeControlBackgroundGlobalHover
|
||||||
border.color: StudioTheme.Values.themeControlOutline
|
border.color: StudioTheme.Values.themeControlOutline
|
||||||
}
|
}
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: myTextField
|
target: root
|
||||||
color: StudioTheme.Values.themeTextColor
|
color: StudioTheme.Values.themeTextColor
|
||||||
placeholderTextColor: StudioTheme.Values.themePlaceholderTextColor
|
placeholderTextColor: StudioTheme.Values.themePlaceholderTextColor
|
||||||
}
|
}
|
||||||
@@ -181,28 +189,28 @@ T.TextField {
|
|||||||
State {
|
State {
|
||||||
name: "hover"
|
name: "hover"
|
||||||
when: mouseArea.containsMouse && !actionIndicator.hover && !translationIndicator.hover
|
when: mouseArea.containsMouse && !actionIndicator.hover && !translationIndicator.hover
|
||||||
&& !myTextField.edit && myTextField.enabled
|
&& !root.edit && root.enabled
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackgroundHover
|
color: StudioTheme.Values.themeControlBackgroundHover
|
||||||
border.color: StudioTheme.Values.themeControlOutline
|
border.color: StudioTheme.Values.themeControlOutline
|
||||||
}
|
}
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: myTextField
|
target: root
|
||||||
color: StudioTheme.Values.themeTextColor
|
color: StudioTheme.Values.themeTextColor
|
||||||
placeholderTextColor: StudioTheme.Values.themePlaceholderTextColor
|
placeholderTextColor: StudioTheme.Values.themePlaceholderTextColor
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "edit"
|
name: "edit"
|
||||||
when: myTextField.edit
|
when: root.edit
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackgroundInteraction
|
color: StudioTheme.Values.themeControlBackgroundInteraction
|
||||||
border.color: StudioTheme.Values.themeControlOutlineInteraction
|
border.color: StudioTheme.Values.themeControlOutlineInteraction
|
||||||
}
|
}
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: myTextField
|
target: root
|
||||||
color: StudioTheme.Values.themeTextColor
|
color: StudioTheme.Values.themeTextColor
|
||||||
placeholderTextColor: StudioTheme.Values.themePlaceholderTextColorInteraction
|
placeholderTextColor: StudioTheme.Values.themePlaceholderTextColorInteraction
|
||||||
}
|
}
|
||||||
@@ -213,14 +221,14 @@ T.TextField {
|
|||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "disable"
|
name: "disable"
|
||||||
when: !myTextField.enabled
|
when: !root.enabled
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackgroundDisabled
|
color: StudioTheme.Values.themeControlBackgroundDisabled
|
||||||
border.color: StudioTheme.Values.themeControlOutlineDisabled
|
border.color: StudioTheme.Values.themeControlOutlineDisabled
|
||||||
}
|
}
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: myTextField
|
target: root
|
||||||
color: StudioTheme.Values.themeTextColorDisabled
|
color: StudioTheme.Values.themeTextColorDisabled
|
||||||
placeholderTextColor: StudioTheme.Values.themeTextColorDisabled
|
placeholderTextColor: StudioTheme.Values.themeTextColorDisabled
|
||||||
}
|
}
|
||||||
@@ -228,7 +236,9 @@ T.TextField {
|
|||||||
]
|
]
|
||||||
|
|
||||||
Keys.onPressed: function(event) {
|
Keys.onPressed: function(event) {
|
||||||
if (event.key === Qt.Key_Escape)
|
if (event.key === Qt.Key_Escape) {
|
||||||
myTextField.focus = false
|
root.text = root.preFocusText
|
||||||
|
root.focus = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user