diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2016-06-21 15:49:05 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2016-06-22 06:41:09 +0000 |
commit | 531d8fe22a52b5d0e98096d71dd7d7a81368121c (patch) | |
tree | 3797505fc8ce0fe4cfd4fdadf8a3cb6aace6e843 | |
parent | eac979b8a16d4128653a22cdfb47f6c35e56da30 (diff) |
Fix the behavior of TextInput field inside treeview
Now the TextInput field properly hides when it should.
It also no longer hogs the focus when hidden.
Change-Id: I634befb62af4ba7f8d5822d3128df36b54141f4e
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Reviewed-by: Titta Heikkala <titta.heikkala@qt.io>
-rw-r--r-- | editorlib/qml/ComponentMenu.qml | 1 | ||||
-rw-r--r-- | editorlib/qml/DragHandle.qml | 1 | ||||
-rw-r--r-- | editorlib/qml/EntityLibrary.qml | 1 | ||||
-rw-r--r-- | editorlib/qml/EntityTree.qml | 47 | ||||
-rw-r--r-- | editorlib/qml/main.qml | 2 |
5 files changed, 28 insertions, 24 deletions
diff --git a/editorlib/qml/ComponentMenu.qml b/editorlib/qml/ComponentMenu.qml index 8a00107..fef7169 100644 --- a/editorlib/qml/ComponentMenu.qml +++ b/editorlib/qml/ComponentMenu.qml @@ -84,7 +84,6 @@ Menu { enabled: !entityTreeView.sceneRootSelected iconSource: "images/minus.png" onTriggered: { - entityTreeView.editing = false if (editorScene.multiSelection) { // Handle multiselection removal editorScene.undoHandler.beginMacro(text) diff --git a/editorlib/qml/DragHandle.qml b/editorlib/qml/DragHandle.qml index 510d5a4..6dde71d 100644 --- a/editorlib/qml/DragHandle.qml +++ b/editorlib/qml/DragHandle.qml @@ -64,6 +64,7 @@ Item { mouse.modifiers & Qt.AltModifier) } onPressed: { + entityTree.focusTree() var scenePos = editorViewport.mapFromItem(parent, mouseX, mouseY) editorScene.dragHandlePress(handleType, scenePos, handleIndex) dragHandle.dragging = true diff --git a/editorlib/qml/EntityLibrary.qml b/editorlib/qml/EntityLibrary.qml index eb56a30..538c032 100644 --- a/editorlib/qml/EntityLibrary.qml +++ b/editorlib/qml/EntityLibrary.qml @@ -112,6 +112,7 @@ Item { drag.target: dragEntityItem onPressed: { + entityTree.focusTree() var globalPos = mapToItem(applicationArea, mouseX, mouseY) dragPositionX = globalPos.x dragPositionY = globalPos.y diff --git a/editorlib/qml/EntityTree.qml b/editorlib/qml/EntityTree.qml index 9e8abc6..81c7363 100644 --- a/editorlib/qml/EntityTree.qml +++ b/editorlib/qml/EntityTree.qml @@ -35,11 +35,10 @@ import QtQuick.Controls.Styles 1.4 Item { id: treeViewSplit - property bool entityTreeViewEditing: entityTreeView.editing - property alias view: entityTreeView property alias menu: addComponentMenu property bool treeviewPasting: false + signal closeNameEditor() Keys.onDeletePressed: { if (editorScene.multiSelection) { @@ -58,6 +57,7 @@ Item { } function focusTree() { + closeNameEditor() entityTreeView.forceActiveFocus(Qt.MouseFocusReason) } @@ -72,7 +72,6 @@ Item { function addNewEntity(entityType, xPos, yPos) { var x = xPos ? xPos : -1 var y = yPos ? yPos : -1 - entityTreeView.editing = false editorScene.clearMultiSelection() @@ -86,8 +85,6 @@ Item { entityTreeView.expand(entityTreeView.selection.currentIndex) entityTreeView.selection.setCurrentIndex(newItemIndex, ItemSelectionModel.SelectCurrent) - // Remove focus so activating editing will always force it on - entityTreeView.focus = true } Component.onCompleted: selectSceneRoot() @@ -123,6 +120,7 @@ Item { selection: ItemSelectionModel { model: editorScene.sceneModel } + focus: true headerVisible: false alternatingRowColors: false backgroundVisible: false @@ -178,7 +176,6 @@ Item { } } - property bool editing: false property bool sceneRootSelected: true property bool cameraSelected: true property bool groupSelected: true @@ -289,7 +286,9 @@ Item { } onDoubleClicked: { - entityTreeView.editing = true + valueField.visible = false + renameTextiInput.forceActiveFocus(Qt.MouseFocusReason) + } } DropArea { @@ -369,7 +368,7 @@ Item { color: mainwindow.textColor elide: styleData.elideMode text: styleData.value - visible: !entityTreeView.editing || !styleData.selected + visible: true anchors.fill: parent clip: true } @@ -385,7 +384,7 @@ Item { clip: true visible: !valueField.visible selectByMouse: true - focus: true + focus: visible color: mainwindow.textColor selectionColor: mainwindow.selectionColor selectedTextColor: mainwindow.textColor @@ -396,21 +395,17 @@ Item { regExp: /^[A-Za-z_][A-Za-z0-9_ ]*$/ } - onVisibleChanged: { - if (visible) { + onActiveFocusChanged: { + if (activeFocus) { text = styleData.value selectAll() - forceActiveFocus(Qt.MouseFocusReason) + } else { + valueField.visible = true } } - onCursorVisibleChanged: { - if (!cursorVisible) - entityTreeView.editing = false - } - Keys.onReturnPressed: { - entityTreeView.editing = false + valueField.visible = true if (text !== model.name) { editorScene.undoHandler.createRenameEntityCommand(selectedEntityName, text) @@ -418,12 +413,21 @@ Item { selectedEntityName = editorScene.sceneModel.entityName( entityTreeView.selection.currentIndex) } + Connections { + target: entityTreeView.selection + onCurrentIndexChanged: { + valueField.visible = true + } + } + Connections { + target: treeViewSplit + onCloseNameEditor: { + valueField.visible = true + } + } } } } - onDoubleClicked: { - entityTreeView.editing = true - } TableViewColumn { title: qsTr("Entities") + editorScene.emptyString @@ -461,7 +465,6 @@ Item { Connections { target: entityTreeView.selection onCurrentIndexChanged: { - entityTreeView.editing = false // If there is no current item selected for some reason, fall back to scene root, // except when dealing with multiselection, during which currentIndex can become -1 temporarily. if (entityTreeView.selection.currentIndex.row === -1) { diff --git a/editorlib/qml/main.qml b/editorlib/qml/main.qml index 1ca98d6..bc7c23f 100644 --- a/editorlib/qml/main.qml +++ b/editorlib/qml/main.qml @@ -368,7 +368,7 @@ QQC2.ApplicationWindow { function selectIndex(index) { expandTo(index) - entityTree.view.forceActiveFocus() + entityTree.focusTree() entityTree.view.selection.setCurrentIndex(index, ItemSelectionModel.ClearAndSelect) } |