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) width: Math.min(300, root.width)
onApplied: { function apply() {
let renamed = statesEditorModel.renameActiveStateGroup(editTextField.text) let renamed = statesEditorModel.renameActiveStateGroup(editTextField.text)
if (renamed) if (renamed)
editDialog.close() editDialog.close()
} }
onApplied: editDialog.accept()
StudioControls.TextField { StudioControls.TextField {
id: editTextField id: editTextField
text: statesEditorModel.activeStateGroup
actionIndicatorVisible: false actionIndicatorVisible: false
translationIndicatorVisible: false translationIndicatorVisible: false
anchors.fill: parent 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 { StudioControls.TextField {
id: textField id: textField
signal rejected
translationIndicator.visible: false translationIndicator.visible: false
actionIndicator.visible: false actionIndicator.visible: false
@@ -158,6 +156,11 @@ StudioControls.TextField {
onPressed: listView.model = null onPressed: listView.model = null
onRejected: {
if (textField.completionActive)
listView.model = null
}
Keys.priority: Keys.BeforeItem Keys.priority: Keys.BeforeItem
Keys.onPressed: function(event) { Keys.onPressed: function(event) {
var text = textField.text 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) { Keys.onUpPressed: function(event) {
listView.decrementCurrentIndex() listView.decrementCurrentIndex()
event.accepted = false event.accepted = false

View File

@@ -60,7 +60,7 @@ T.Button {
states: [ states: [
State { State {
name: "default" name: "default"
when: !root.down && !root.hovered && !root.checked when: root.enabled && !root.down && !root.hovered && !root.checked
PropertyChanges { PropertyChanges {
target: background target: background
@@ -75,7 +75,7 @@ T.Button {
}, },
State { State {
name: "hover" name: "hover"
when: root.hovered && !root.checked && !root.down when: root.enabled && root.hovered && !root.checked && !root.down
PropertyChanges { PropertyChanges {
target: background target: background
@@ -88,8 +88,8 @@ T.Button {
} }
}, },
State { State {
name: "pressed" name: "press"
when: root.checked || root.down when: root.enabled && (root.checked || root.down)
PropertyChanges { PropertyChanges {
target: background target: background
@@ -100,6 +100,19 @@ T.Button {
target: textItem target: textItem
color: StudioTheme.Values.themeTextColor 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 property bool contextMenuAboutToShow: false
signal rejected
horizontalAlignment: Qt.AlignLeft horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter verticalAlignment: Qt.AlignVCenter
@@ -247,10 +249,10 @@ T.TextField {
} }
] ]
Keys.onPressed: function(event) { Keys.onEscapePressed: function(event) {
if (event.key === Qt.Key_Escape) { event.accepted = true
root.text = root.preFocusText root.text = root.preFocusText
root.rejected()
root.focus = false root.focus = false
} }
} }
}