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>
This commit is contained in:
Henning Gruendl
2022-09-21 17:45:59 +02:00
committed by Henning Gründl
parent a8f46ac852
commit 66ec244cf9
2 changed files with 21 additions and 16 deletions

View File

@@ -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

View File

@@ -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