forked from qt-creator/qt-creator
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:
committed by
Henning Gründl
parent
a8f46ac852
commit
66ec244cf9
@@ -650,7 +650,12 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onEditingFinished: {
|
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
|
return
|
||||||
|
|
||||||
whenCondition.previousCondition = whenCondition.text
|
whenCondition.previousCondition = whenCondition.text
|
||||||
|
@@ -50,6 +50,8 @@ T.TextField {
|
|||||||
|
|
||||||
property string preFocusText: ""
|
property string preFocusText: ""
|
||||||
|
|
||||||
|
property bool contextMenuAboutToShow: false
|
||||||
|
|
||||||
horizontalAlignment: Qt.AlignLeft
|
horizontalAlignment: Qt.AlignLeft
|
||||||
verticalAlignment: Qt.AlignVCenter
|
verticalAlignment: Qt.AlignVCenter
|
||||||
|
|
||||||
@@ -62,7 +64,7 @@ T.TextField {
|
|||||||
|
|
||||||
readOnly: false
|
readOnly: false
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
persistentSelection: focus // QTBUG-73807
|
persistentSelection: contextMenu.visible || root.focus
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
width: StudioTheme.Values.defaultControlWidth
|
width: StudioTheme.Values.defaultControlWidth
|
||||||
@@ -78,24 +80,22 @@ T.TextField {
|
|||||||
enabled: true
|
enabled: true
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
propagateComposedEvents: true
|
propagateComposedEvents: true
|
||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
acceptedButtons: Qt.NoButton
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onPressed: function(mouse) {
|
|
||||||
if (mouse.button === Qt.RightButton)
|
|
||||||
contextMenu.popup(root)
|
|
||||||
|
|
||||||
mouse.accepted = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onPersistentSelectionChanged: {
|
onPressed: function(event) {
|
||||||
if (!persistentSelection)
|
if (event.button === Qt.RightButton)
|
||||||
root.deselect()
|
contextMenu.popup(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextMenu {
|
ContextMenu {
|
||||||
id: contextMenu
|
id: contextMenu
|
||||||
myTextEdit: root
|
myTextEdit: root
|
||||||
|
|
||||||
|
onClosed: root.forceActiveFocus()
|
||||||
|
onAboutToShow: root.contextMenuAboutToShow = true
|
||||||
|
onAboutToHide: root.contextMenuAboutToShow = false
|
||||||
}
|
}
|
||||||
|
|
||||||
onActiveFocusChanged: {
|
onActiveFocusChanged: {
|
||||||
@@ -165,7 +165,7 @@ T.TextField {
|
|||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "default"
|
name: "default"
|
||||||
when: root.enabled && !root.hover && !root.edit
|
when: root.enabled && !root.hover && !root.edit && !contextMenu.visible
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackground
|
color: StudioTheme.Values.themeControlBackground
|
||||||
@@ -184,7 +184,7 @@ T.TextField {
|
|||||||
State {
|
State {
|
||||||
name: "globalHover"
|
name: "globalHover"
|
||||||
when: (actionIndicator.hover || translationIndicator.hover || indicator.hover)
|
when: (actionIndicator.hover || translationIndicator.hover || indicator.hover)
|
||||||
&& !root.edit && root.enabled
|
&& !root.edit && root.enabled && !contextMenu.visible
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackgroundGlobalHover
|
color: StudioTheme.Values.themeControlBackgroundGlobalHover
|
||||||
@@ -199,7 +199,7 @@ T.TextField {
|
|||||||
State {
|
State {
|
||||||
name: "hover"
|
name: "hover"
|
||||||
when: mouseArea.containsMouse && !actionIndicator.hover && !translationIndicator.hover
|
when: mouseArea.containsMouse && !actionIndicator.hover && !translationIndicator.hover
|
||||||
&& !indicator.hover && !root.edit && root.enabled
|
&& !indicator.hover && !root.edit && root.enabled && !contextMenu.visible
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackgroundHover
|
color: StudioTheme.Values.themeControlBackgroundHover
|
||||||
@@ -213,7 +213,7 @@ T.TextField {
|
|||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "edit"
|
name: "edit"
|
||||||
when: root.edit
|
when: root.edit || contextMenu.visible
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: textFieldBackground
|
target: textFieldBackground
|
||||||
color: StudioTheme.Values.themeControlBackgroundInteraction
|
color: StudioTheme.Values.themeControlBackgroundInteraction
|
||||||
|
Reference in New Issue
Block a user