1
0

InputPanel.qml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. text: "\uf062"
  126. functionKey: true
  127. onClicked: {
  128. if (pimpl.symbolModifier) {
  129. pimpl.symbolModifier = false
  130. }
  131. pimpl.shiftModifier = !pimpl.shiftModifier
  132. }
  133. inputPanel: root
  134. }
  135. Row {
  136. height: pimpl.rowHeight
  137. spacing: pimpl.horizontalSpacing
  138. anchors.horizontalCenter:parent.horizontalCenter
  139. Repeater {
  140. anchors.horizontalCenter: parent.horizontalCenter
  141. model: keyModel.thirdRowModel
  142. delegate: keyButtonDelegate
  143. }
  144. }
  145. KeyButton {
  146. id: backspaceKey
  147. font.family: "FontAwesome"
  148. color: "#1e1b18"
  149. anchors.right: parent.right
  150. width: 1.25*pimpl.buttonWidth
  151. height: pimpl.rowHeight
  152. text: "\x7F"
  153. displayText: "\uf177"
  154. inputPanel: root
  155. repeat: true
  156. }
  157. }
  158. Row {
  159. height: pimpl.rowHeight
  160. spacing: pimpl.horizontalSpacing
  161. anchors.horizontalCenter:parent.horizontalCenter
  162. KeyButton {
  163. id: hideKey
  164. color: "#1e1b18"
  165. width: 1.25*pimpl.buttonWidth
  166. height: pimpl.rowHeight
  167. font.family: "FontAwesome"
  168. text: "\uf078"
  169. functionKey: true
  170. onClicked: {
  171. Qt.inputMethod.hide()
  172. }
  173. inputPanel: root
  174. showPreview: false
  175. }
  176. KeyButton {
  177. color: "#1e1b18"
  178. width: 1.25*pimpl.buttonWidth
  179. height: pimpl.rowHeight
  180. text: ""
  181. inputPanel: root
  182. functionKey: true
  183. }
  184. KeyButton {
  185. color: "#1e1b18"
  186. width: pimpl.buttonWidth
  187. height: pimpl.rowHeight
  188. font.family: "FontAwesome"
  189. text: "\uf060" // arrow left
  190. //onClicked: InputEngine.sendKeyToFocusItem(text)
  191. inputPanel: root
  192. }
  193. KeyButton {
  194. id: spaceKey
  195. width: 3*pimpl.buttonWidth
  196. height: pimpl.rowHeight
  197. text: " "
  198. inputPanel: root
  199. showPreview: false
  200. }
  201. KeyButton {
  202. color: "#1e1b18"
  203. width: pimpl.buttonWidth
  204. height: pimpl.rowHeight
  205. font.family: "FontAwesome"
  206. text: "\uf061" //pimpl.symbolModifier ? ":" :"."
  207. inputPanel: root
  208. }
  209. KeyButton {
  210. id: symbolKey
  211. color: "#1e1b18"
  212. width: 1.25*pimpl.buttonWidth
  213. height: pimpl.rowHeight
  214. text: (!pimpl.symbolModifier)? "12#" : "ABC"
  215. functionKey: true
  216. onClicked: {
  217. if (pimpl.shiftModifier) {
  218. pimpl.shiftModifier = false
  219. }
  220. pimpl.symbolModifier = !pimpl.symbolModifier
  221. }
  222. inputPanel: root
  223. }
  224. KeyButton {
  225. id: enterKey
  226. color: "#1e1b18"
  227. width: 1.25*pimpl.buttonWidth
  228. height: pimpl.rowHeight
  229. displayText: "Enter"
  230. text: "\n"
  231. inputPanel: root
  232. }
  233. }
  234. }
  235. }
  236. }