Lomiri
InputMethod.qml
1 /*
2  * Copyright (C) 2014 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.0
18 import QtMir.Application 0.1
19 import Lomiri.Components 0.1
20 
21 // TODO: try to share this code with that from the lomiri shell
22 
23 Item {
24  id: inputMethodRoot
25 
26  Connections {
27  target: SurfaceManager
28  onSurfaceCreated: {
29  if (surface.type == MirSurfaceItem.InputMethod) {
30  inputMethodRoot.surface = surface;
31  }
32  }
33 
34  onSurfaceDestroyed: {
35  if (inputMethodRoot.surface == surface) {
36  inputMethodRoot.surface = null;
37  surface.parent = null;
38  }
39  if (!surface.parent) {
40  // there's no one displaying it. delete it right away
41  surface.release();
42  }
43  }
44  }
45 
46  property var surface: null
47 
48  property int transitionDuration: LomiriAnimation.FastDuration
49 
50  state: {
51  if (surface && surface.state != MirSurfaceItem.Minimized) {
52  return "shown";
53  } else {
54  return "hidden";
55  }
56  }
57 
58  states: [
59  State {
60  name: "shown"
61  PropertyChanges {
62  target: root
63  visible: true
64  y: 0
65  }
66  },
67  State {
68  name: "hidden"
69  PropertyChanges {
70  target: root
71  visible: false
72  // half-way down because the vkb occupies only the lower half of the surface
73  // TODO: consider keyboard rotation
74  y: inputMethodRoot.parent.height / 2.0
75  }
76  }
77  ]
78 
79  transitions: [
80  Transition {
81  from: "*"; to: "*"
82  PropertyAction { property: "visible"; value: true }
83  LomiriNumberAnimation { property: "y"; duration: transitionDuration }
84  }
85  ]
86 
87  Connections {
88  target: surface
89  ignoreUnknownSignals: true // don't wanna spam the log when surface is null
90  onStateChanged: {
91  if (state == MirSurfaceItem.Minimized) {
92  inputMethodRoot.hide();
93  } else if (state == MirSurfaceItem.Maximized) {
94  inputMethodRoot.show();
95  }
96  }
97  }
98 
99  onSurfaceChanged: {
100  if (surface) {
101  surface.parent = inputMethodRoot;
102  surface.anchors.fill = inputMethodRoot;
103  }
104  }
105 
106  Component.onDestruction: {
107  if (surface) {
108  surface.parent = null;
109  surface.release();
110  surface = null;
111  }
112  }
113 }