Dekko
KeyboardRectangle.qml
1 /*
2  * Copyright (C) 2012-2015 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.4
18 
19 Item {
20  id: keyboardRect
21 
22  property bool active: true
23 
24  anchors.left: parent.left
25  anchors.right: parent.right
26  anchors.bottom: parent.bottom
27  height: active && Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
28 
29  states: [
30  State {
31  name: "hidden"
32  when: keyboardRect.height === 0
33  },
34  State {
35  name: "shown"
36  when: keyboardRect.height === Qt.inputMethod.keyboardRectangle.height
37  }
38  ]
39 
40  function recursiveFindFocusedItem(parent) {
41  if (parent.activeFocus) {
42  return parent;
43  }
44 
45  for (var i in parent.children) {
46  var child = parent.children[i];
47  if (child.activeFocus) {
48  return child;
49  }
50 
51  var item = recursiveFindFocusedItem(child);
52 
53  if (item != null) {
54  return item;
55  }
56  }
57 
58  return null;
59  }
60 
61  Connections {
62  target: Qt.inputMethod
63 
64  onVisibleChanged: {
65  if (!Qt.inputMethod.visible) {
66  var focusedItem = recursiveFindFocusedItem(keyboardRect.parent);
67  if (focusedItem != null) {
68  focusedItem.focus = false;
69  }
70  }
71  }
72  }
73 }