InputPanel.qml 8.7 KB

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