From 50587a313187b7d9872a4875c16f8fcf379b4746 Mon Sep 17 00:00:00 2001
From: Christiaan Janssen <christiaan.janssen@nokia.com>
Date: Fri, 8 Jan 2010 14:21:30 +0100
Subject: [PATCH] QmlDesigner.StatesEditor:  Improving focus management of
 TextInputs for state renaming

---
 .../components/stateseditor/stateslist.qml    | 36 +++++++++++--------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/plugins/qmldesigner/components/stateseditor/stateslist.qml b/src/plugins/qmldesigner/components/stateseditor/stateslist.qml
index 112dce5b143..492948b59ef 100644
--- a/src/plugins/qmldesigner/components/stateseditor/stateslist.qml
+++ b/src/plugins/qmldesigner/components/stateseditor/stateslist.qml
@@ -27,8 +27,10 @@ Rectangle {
         signal: "changedToState(n)"
         script: {root.currentStateIndex = n}
     }
-	
-	Item { id:focusStealer } 
+
+    // TextInputs don't loose focus automatically when user clicks away, have to be done explicitly
+    signal unFocus
+    Item { id:focusStealer }
 
     Flickable {
         id: listView
@@ -94,34 +96,38 @@ Rectangle {
                 anchors.fill: container
                 onClicked: {
                     root.currentStateIndex = index
-                    focusStealer.focus=true; // steal focus from textinput
+                    root.unFocus();
                 }
             }
 
+            Connection {
+                sender: root
+                signal: "unFocus()"
+                script: txt.unFocus()
+            }
+
             TextInput {
                 anchors.top: img.bottom
                 anchors.horizontalCenter: img.horizontalCenter
                 id: txt
                 text: stateName
                 color: "#E1E1E1";
-                onAccepted: {
-                    // force focus to move to another item, otherwise this one will be reactivated at mode change
+                function unFocus() {
                     focus=false;
-                    itemRegion.focus=true;
-                }
-                onFocusChanged: if (!focus) {
-                    txtRegion.enabled=true
-                    statesEditorModel.renameState(index, text)
+                    focusStealer.focus=true;
+                    txtRegion.enabled=true;
+                    if (index!=0)
+                        statesEditorModel.renameState(index,text);
                 }
+                onAccepted: unFocus();
                 MouseRegion {
                     id: txtRegion
                     anchors.fill:parent
-                    property bool wasDoubleClicked:false
                     onClicked: {
                         root.currentStateIndex = index;
-                        itemRegion.focus=true;
+                        root.unFocus();
                     }
-                    onDoubleClicked: if (index!=0) { // base state not editable
+                    onDoubleClicked: if (index!=0) {
                         parent.focus=true;
                         enabled=false;
                     }
@@ -185,6 +191,7 @@ Rectangle {
         MouseRegion {
             anchors.fill:parent
             onClicked: {
+                root.unFocus();
                 if (root.currentStateIndex == 0)
                 root.createNewState(); //create new state
                 else
@@ -249,6 +256,7 @@ Rectangle {
         MouseRegion {
             anchors.fill:parent
             onClicked: {
+                root.unFocus();
                 root.deleteCurrentState();
                 if (root.currentStateIndex >= statesEditorModel.count)
                     root.currentStateIndex = root.currentStateIndex-1;
@@ -312,7 +320,7 @@ Rectangle {
                 anchors.fill:parent
                 property int dragging:0;
                 property int originalX:0;
-                onPressed: { dragging = 1; originalX = mouse.x; }
+                onPressed: { dragging = 1; originalX = mouse.x;root.unFocus(); }
                 onReleased: { dragging = 0; }
                 onPositionChanged: if (dragging)
                 {
-- 
GitLab