From 502e94cbe9d964e624557ebd720918eb806159c8 Mon Sep 17 00:00:00 2001 From: Henning Gruendl Date: Tue, 27 Sep 2022 17:52:52 +0200 Subject: [PATCH] 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: Reviewed-by: Thomas Hartmann --- .../qmldesigner/newstateseditor/Main.qml | 36 +++++++++++++++++-- .../HelperWidgets/ExpressionTextField.qml | 16 +++------ .../imports/StudioControls/DialogButton.qml | 21 ++++++++--- .../imports/StudioControls/TextField.qml | 12 ++++--- 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/share/qtcreator/qmldesigner/newstateseditor/Main.qml b/share/qtcreator/qmldesigner/newstateseditor/Main.qml index 5f4cfa1ab0e..540f70b4857 100644 --- a/share/qtcreator/qmldesigner/newstateseditor/Main.qml +++ b/share/qtcreator/qmldesigner/newstateseditor/Main.qml @@ -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 } } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ExpressionTextField.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ExpressionTextField.qml index 7828e9b4272..889f94f4ac3 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ExpressionTextField.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ExpressionTextField.qml @@ -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 diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/DialogButton.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/DialogButton.qml index 6f0c33264fc..173b4ffdf3d 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/DialogButton.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/DialogButton.qml @@ -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 + } } ] } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TextField.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TextField.qml index 0a683fa6d12..7d0dc041f19 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TextField.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TextField.qml @@ -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 } }