1
0

InputPanel.qml 8.5 KB

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