QmlDesigner: Improve state group rename dialog

If the user presses enter when having focus on the TextField inside the
StateGroup rename dialog it will submit the change and close the dialog.
If the user presses escape it will reject the change and close the
dialog.

Task-number: QDS-7764
Change-Id: I8626c7b9ca9bf6d087c226343b3e6833641da54c
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Henning Gruendl
2022-09-27 17:52:52 +02:00
committed by Henning Gründl
parent 3f6d8e8cd6
commit 502e94cbe9
4 changed files with 63 additions and 22 deletions

View File

@@ -303,18 +303,50 @@ Rectangle {
width: Math.min(300, root.width)
onApplied: {
function apply() {
let renamed = statesEditorModel.renameActiveStateGroup(editTextField.text)
if (renamed)
editDialog.close()
}
onApplied: editDialog.accept()
StudioControls.TextField {
id: editTextField
text: statesEditorModel.activeStateGroup
actionIndicatorVisible: false
translationIndicatorVisible: false
anchors.fill: parent
onTextChanged: {
let btn = editDialog.standardButton(Dialog.Apply)
if (!btn)
return
if (editDialog.previousString !== editTextField.text) {
btn.enabled = true
} else {
btn.enabled = false
}
}
onAccepted: editDialog.accept()
onRejected: editDialog.reject()
}
onAccepted: {
let renamed = statesEditorModel.renameActiveStateGroup(editTextField.text)
if (renamed)
editDialog.close()
}
property string previousString
onAboutToShow: {
editTextField.text = statesEditorModel.activeStateGroup
editDialog.previousString = statesEditorModel.activeStateGroup
let btn = editDialog.standardButton(Dialog.Apply)
btn.enabled = false
}
}

View File

@@ -33,8 +33,6 @@ import StudioTheme 1.0 as StudioTheme
StudioControls.TextField {
id: textField
signal rejected
translationIndicator.visible: false
actionIndicator.visible: false
@@ -158,6 +156,11 @@ StudioControls.TextField {
onPressed: listView.model = null
onRejected: {
if (textField.completionActive)
listView.model = null
}
Keys.priority: Keys.BeforeItem
Keys.onPressed: function(event) {
var text = textField.text
@@ -244,15 +247,6 @@ StudioControls.TextField {
}
}
Keys.onEscapePressed: function(event) {
event.accepted = true
if (textField.completionActive) {
listView.model = null
} else {
textField.rejected()
}
}
Keys.onUpPressed: function(event) {
listView.decrementCurrentIndex()
event.accepted = false

View File

@@ -60,7 +60,7 @@ T.Button {
states: [
State {
name: "default"
when: !root.down && !root.hovered && !root.checked
when: root.enabled && !root.down && !root.hovered && !root.checked
PropertyChanges {
target: background
@@ -75,7 +75,7 @@ T.Button {
},
State {
name: "hover"
when: root.hovered && !root.checked && !root.down
when: root.enabled && root.hovered && !root.checked && !root.down
PropertyChanges {
target: background
@@ -88,8 +88,8 @@ T.Button {
}
},
State {
name: "pressed"
when: root.checked || root.down
name: "press"
when: root.enabled && (root.checked || root.down)
PropertyChanges {
target: background
@@ -100,6 +100,19 @@ T.Button {
target: textItem
color: StudioTheme.Values.themeTextColor
}
},
State {
name: "disable"
when: !root.enabled
PropertyChanges {
target: background
color: StudioTheme.Values.themeControlBackgroundDisabled
border.color: StudioTheme.Values.themeControlOutlineDisabled
}
PropertyChanges {
target: textItem
color: StudioTheme.Values.themeTextColorDisabled
}
}
]
}

View File

@@ -52,6 +52,8 @@ T.TextField {
property bool contextMenuAboutToShow: false
signal rejected
horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter
@@ -247,10 +249,10 @@ T.TextField {
}
]
Keys.onPressed: function(event) {
if (event.key === Qt.Key_Escape) {
root.text = root.preFocusText
root.focus = false
}
Keys.onEscapePressed: function(event) {
event.accepted = true
root.text = root.preFocusText
root.rejected()
root.focus = false
}
}