1
0

InputPanel.qml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import QtQuick 2.0
  2. import "."
  3. import FreeVirtualKeyboard 1.0
  4. /**
  5. * This is the QML input panel that provides the virtual keyboard UI
  6. * The code has been copied from
  7. * http://tolszak-dev.blogspot.de/2013/04/qplatforminputcontext-and-virtual.html
  8. */
  9. Item {
  10. id:root
  11. objectName: "inputPanel"
  12. width: parent.width
  13. height: width / 4
  14. signal hideKeyPressed
  15. // Report actual keyboard rectangle to input engine
  16. onYChanged: InputEngine.setKeyboardRectangle(Qt.rect(x, y, width, height))
  17. KeyModel {
  18. id:keyModel
  19. kbdLayout: settings.value("COMMON/KbdLayout") //"de"
  20. }
  21. FontLoader {
  22. source: "FontAwesome.otf"
  23. }
  24. QtObject {
  25. id:pimpl
  26. property bool shiftModifier: false
  27. property bool symbolModifier: false
  28. property int verticalSpacing: keyboard.height / 40
  29. property int horizontalSpacing: verticalSpacing
  30. property int rowHeight: keyboard.height/24*5 - verticalSpacing
  31. property int buttonWidth: (keyboard.width-column.anchors.margins)/12 - horizontalSpacing
  32. }
  33. // The delegate that paints the key buttons
  34. Component {
  35. id: keyButtonDelegate
  36. KeyButton {
  37. id: button
  38. width: pimpl.buttonWidth
  39. height: pimpl.rowHeight
  40. text: (pimpl.shiftModifier) ? letter.toUpperCase() : (pimpl.symbolModifier)?firstSymbol : letter
  41. inputPanel: root
  42. }
  43. }
  44. Component {
  45. id: numberButtonDelegate
  46. KeyButton {
  47. id: button
  48. width: pimpl.buttonWidth
  49. height: pimpl.rowHeight * 4 / 5
  50. text: (pimpl.shiftModifier) ? letter.toUpperCase() : (pimpl.symbolModifier)?firstSymbol : letter
  51. inputPanel: root
  52. color: "grey"
  53. }
  54. }
  55. Connections {
  56. target: InputEngine
  57. // Switch the keyboard layout to Numeric if the input mode of the InputEngine changes
  58. onInputModeChanged: {
  59. pimpl.symbolModifier = ((InputEngine.inputMode == InputEngine.Numeric)
  60. || (InputEngine.inputMode == InputEngine.Dialable))
  61. if (pimpl.symbolModifier) {
  62. pimpl.shiftModifier = false
  63. }
  64. }
  65. }
  66. // This function shows the character preview popup for each key button
  67. function showKeyPopup(keyButton)
  68. {
  69. // console.log("showKeyPopup");
  70. keyPopup.popup(keyButton, root);
  71. }
  72. // The key popup for character preview
  73. KeyPopup {
  74. id: keyPopup
  75. visible: false
  76. z: 100
  77. }
  78. Rectangle {
  79. id: background
  80. color: "black"
  81. width: keyboard.width
  82. height: keyboard.height + 4 * pimpl.verticalSpacing
  83. }
  84. Rectangle {
  85. id:keyboard
  86. color: "black"
  87. anchors.fill: parent;
  88. MouseArea {
  89. anchors.fill: parent
  90. }
  91. Column {
  92. id:column
  93. anchors.margins: 5
  94. anchors.fill: parent
  95. spacing: pimpl.verticalSpacing
  96. Row {
  97. height: pimpl.rowHeight
  98. spacing: pimpl.horizontalSpacing
  99. anchors.horizontalCenter:parent.horizontalCenter
  100. Repeater {
  101. model: keyModel.numbersRowModel
  102. delegate: numberButtonDelegate
  103. }
  104. }
  105. Row {
  106. height: pimpl.rowHeight
  107. spacing: pimpl.horizontalSpacing
  108. anchors.horizontalCenter:parent.horizontalCenter
  109. Repeater {
  110. model: keyModel.firstRowModel
  111. delegate: keyButtonDelegate
  112. }
  113. }
  114. Row {
  115. height: pimpl.rowHeight
  116. spacing: pimpl.horizontalSpacing
  117. anchors.horizontalCenter:parent.horizontalCenter
  118. Repeater {
  119. model: keyModel.secondRowModel
  120. delegate: keyButtonDelegate
  121. }
  122. }
  123. Item {
  124. height: pimpl.rowHeight
  125. width:parent.width
  126. KeyButton {
  127. id: shiftKey
  128. color: (pimpl.shiftModifier)? "#1e6fa7": "#1e1b18"
  129. anchors.left: parent.left
  130. width: 1.25*pimpl.buttonWidth
  131. height: pimpl.rowHeight
  132. font.family: "FontAwesome"
  133. font.bold: true
  134. text: "\u21ea" //"\uf062"
  135. functionKey: true
  136. onClicked: {
  137. if (pimpl.symbolModifier) {
  138. pimpl.symbolModifier = false
  139. }
  140. pimpl.shiftModifier = !pimpl.shiftModifier
  141. }
  142. inputPanel: root
  143. }
  144. Row {
  145. height: pimpl.rowHeight
  146. spacing: pimpl.horizontalSpacing
  147. anchors.horizontalCenter:parent.horizontalCenter
  148. Repeater {
  149. anchors.horizontalCenter: parent.horizontalCenter
  150. model: keyModel.thirdRowModel
  151. delegate: keyButtonDelegate
  152. }
  153. }
  154. KeyButton {
  155. id: backspaceKey
  156. font.family: "FontAwesome"
  157. color: "#1e1b18"
  158. anchors.right: parent.right
  159. width: 1.25*pimpl.buttonWidth
  160. height: pimpl.rowHeight
  161. text: "\x7F"
  162. displayText: "\u27f5" //"\uf177"
  163. inputPanel: root
  164. repeat: true
  165. }
  166. }
  167. Row {
  168. height: pimpl.rowHeight
  169. spacing: pimpl.horizontalSpacing
  170. anchors.horizontalCenter:parent.horizontalCenter
  171. KeyButton {
  172. id: hideKey
  173. color: "#1e1b18"
  174. width: 1.25*pimpl.buttonWidth
  175. height: pimpl.rowHeight
  176. font.family: "FontAwesome"
  177. text: "\uf11c" //"\uf078"
  178. functionKey: true
  179. onClicked: {
  180. Qt.inputMethod.hide();
  181. hideKeyPressed();
  182. }
  183. inputPanel: root
  184. showPreview: false
  185. }
  186. KeyButton {
  187. color: "#1e1b18"
  188. width: 1.25*pimpl.buttonWidth
  189. height: pimpl.rowHeight
  190. font.family: "FontAwesome"
  191. font.bold: true
  192. text: (pimpl.shiftModifier) ? "\u21a4":"\u21a6"
  193. inputPanel: root
  194. //functionKey: true
  195. }
  196. KeyButton {
  197. color: "#1e1b18"
  198. width: pimpl.buttonWidth
  199. height: pimpl.rowHeight
  200. font.family: "FontAwesome"
  201. text: (pimpl.shiftModifier) ? "\u2191":"\u2190" //"\uf060" // arrow left
  202. //onClicked: InputEngine.sendKeyToFocusItem(text)
  203. inputPanel: root
  204. }
  205. KeyButton {
  206. id: spaceKey
  207. width: 3*pimpl.buttonWidth
  208. height: pimpl.rowHeight
  209. text: " "
  210. inputPanel: root
  211. showPreview: false
  212. }
  213. KeyButton {
  214. color: "#1e1b18"
  215. width: pimpl.buttonWidth
  216. height: pimpl.rowHeight
  217. font.family: "FontAwesome"
  218. text: (pimpl.shiftModifier) ?"\u2193":"\u2192" //"\uf061" //pimpl.symbolModifier ? ":" :"."
  219. inputPanel: root
  220. }
  221. KeyButton {
  222. id: symbolKey
  223. color: "#1e1b18"
  224. width: 1.25*pimpl.buttonWidth
  225. height: pimpl.rowHeight
  226. text: (!pimpl.symbolModifier)? "12#" : "ABC"
  227. functionKey: true
  228. onClicked: {
  229. if (pimpl.shiftModifier) {
  230. pimpl.shiftModifier = false
  231. }
  232. pimpl.symbolModifier = !pimpl.symbolModifier
  233. }
  234. inputPanel: root
  235. }
  236. KeyButton {
  237. id: enterKey
  238. color: "#1e1b18"
  239. width: 1.25*pimpl.buttonWidth
  240. height: pimpl.rowHeight
  241. font.bold: true
  242. displayText: "\u23ce" //"Enter"
  243. text: "\n"
  244. inputPanel: root
  245. }
  246. }
  247. }
  248. }
  249. }