diff options
author | Henning Gruendl <henning.gruendl@qt.io> | 2022-09-21 17:45:59 +0200 |
---|---|---|
committer | Henning Gründl <henning.gruendl@qt.io> | 2022-09-23 09:20:21 +0000 |
commit | 66ec244cf9dacb3692c7c29d947afac777cdbf11 (patch) | |
tree | 02a0f79b899dde3a1e03718e6d30af25b6f37ce1 | |
parent | a8f46ac852d70a6ddbf3a28fd240edda24e846f2 (diff) | |
download | qt-creator-66ec244cf9dacb3692c7c29d947afac777cdbf11.tar.gz |
QmlDesigner: Fix TextField context menu
Fix TextField keeping its selection after context menu is opened. Due to
this bug QTBUG-71723 being closed the behavior changed. Also the states
when condition TextField needed to be context menu aware to not set a
new expression when the context menu is opened, otherwise it will
immediately reset the model and the context menu wont show up if the
content was edited.
Task-number: QDS-7730
Change-Id: Ic0e63cd3d244bd7f83bcb0edd3b31c0ca1f0a5df
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r-- | share/qtcreator/qmldesigner/newstateseditor/StateThumbnail.qml | 7 | ||||
-rw-r--r-- | share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TextField.qml | 30 |
2 files changed, 21 insertions, 16 deletions
diff --git a/share/qtcreator/qmldesigner/newstateseditor/StateThumbnail.qml b/share/qtcreator/qmldesigner/newstateseditor/StateThumbnail.qml index 642ebd972d..4b004708c2 100644 --- a/share/qtcreator/qmldesigner/newstateseditor/StateThumbnail.qml +++ b/share/qtcreator/qmldesigner/newstateseditor/StateThumbnail.qml @@ -650,7 +650,12 @@ Item { } onEditingFinished: { - if (whenCondition.previousCondition === whenCondition.text) + // The check for contenxtMenuAboutToShow is necessary in order to make a the + // popup stay open if the when condition was changed. Otherwise editingFinished + // will be called and the model will be reset. The popup will trigger a focus + // change and editingFinished is triggered. + if (whenCondition.previousCondition === whenCondition.text + || whenCondition.contextMenuAboutToShow) return whenCondition.previousCondition = whenCondition.text diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TextField.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TextField.qml index 702d80ab8a..531a5b0ff3 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TextField.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/TextField.qml @@ -50,6 +50,8 @@ T.TextField { property string preFocusText: "" + property bool contextMenuAboutToShow: false + horizontalAlignment: Qt.AlignLeft verticalAlignment: Qt.AlignVCenter @@ -62,7 +64,7 @@ T.TextField { readOnly: false selectByMouse: true - persistentSelection: focus // QTBUG-73807 + persistentSelection: contextMenu.visible || root.focus clip: true width: StudioTheme.Values.defaultControlWidth @@ -78,24 +80,22 @@ T.TextField { enabled: true hoverEnabled: true propagateComposedEvents: true - acceptedButtons: Qt.LeftButton | Qt.RightButton + acceptedButtons: Qt.NoButton cursorShape: Qt.PointingHandCursor - onPressed: function(mouse) { - if (mouse.button === Qt.RightButton) - contextMenu.popup(root) - - mouse.accepted = false - } } - onPersistentSelectionChanged: { - if (!persistentSelection) - root.deselect() + onPressed: function(event) { + if (event.button === Qt.RightButton) + contextMenu.popup(root) } ContextMenu { id: contextMenu myTextEdit: root + + onClosed: root.forceActiveFocus() + onAboutToShow: root.contextMenuAboutToShow = true + onAboutToHide: root.contextMenuAboutToShow = false } onActiveFocusChanged: { @@ -165,7 +165,7 @@ T.TextField { states: [ State { name: "default" - when: root.enabled && !root.hover && !root.edit + when: root.enabled && !root.hover && !root.edit && !contextMenu.visible PropertyChanges { target: textFieldBackground color: StudioTheme.Values.themeControlBackground @@ -184,7 +184,7 @@ T.TextField { State { name: "globalHover" when: (actionIndicator.hover || translationIndicator.hover || indicator.hover) - && !root.edit && root.enabled + && !root.edit && root.enabled && !contextMenu.visible PropertyChanges { target: textFieldBackground color: StudioTheme.Values.themeControlBackgroundGlobalHover @@ -199,7 +199,7 @@ T.TextField { State { name: "hover" when: mouseArea.containsMouse && !actionIndicator.hover && !translationIndicator.hover - && !indicator.hover && !root.edit && root.enabled + && !indicator.hover && !root.edit && root.enabled && !contextMenu.visible PropertyChanges { target: textFieldBackground color: StudioTheme.Values.themeControlBackgroundHover @@ -213,7 +213,7 @@ T.TextField { }, State { name: "edit" - when: root.edit + when: root.edit || contextMenu.visible PropertyChanges { target: textFieldBackground color: StudioTheme.Values.themeControlBackgroundInteraction |