KeyboardLayout.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright (C) 2016 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
  3. import QtQuick
  4. import QtQuick.Layouts
  5. import QtQuick.VirtualKeyboard
  6. /*!
  7. \qmltype KeyboardLayout
  8. \inqmlmodule QtQuick.VirtualKeyboard.Components
  9. \ingroup qmlclass
  10. \ingroup qtvirtualkeyboard-components-qml
  11. \inherits ColumnLayout
  12. \brief Keyboard layout.
  13. This type is the root element of the keyboard layout.
  14. Use this element to build a new keyboard layout.
  15. Example:
  16. \code
  17. import QtQuick
  18. import QtQuick.Layouts
  19. import QtQuick.VirtualKeyboard
  20. // file: layouts/en_GB/main.qml
  21. KeyboardLayout {
  22. KeyboardRow {
  23. Key {
  24. key: Qt.Key_Q
  25. text: "q"
  26. }
  27. Key {
  28. key: Qt.Key_W
  29. text: "w"
  30. }
  31. Key {
  32. key: Qt.Key_E
  33. text: "e"
  34. }
  35. Key {
  36. key: Qt.Key_R
  37. text: "r"
  38. }
  39. Key {
  40. key: Qt.Key_T
  41. text: "t"
  42. }
  43. Key {
  44. key: Qt.Key_Y
  45. text: "y"
  46. }
  47. }
  48. }
  49. \endcode
  50. */
  51. ColumnLayout {
  52. id: root
  53. /*! Sets the input method to be used in this layout.
  54. This property allows a custom input method to be
  55. used in this layout.
  56. */
  57. property var inputMethod
  58. /*! This function may be overridden by the keyboard layout
  59. to create the input method object dynamically. The default
  60. implementation returns \c null.
  61. The input method object created by this function can outlive
  62. keyboard layout transitions in certain cases. In particular,
  63. this applies to the transitions between the layouts listed in
  64. the sharedLayouts property.
  65. */
  66. function createInputMethod() {
  67. return null
  68. }
  69. /*! List of layout names which share the input method created
  70. by the createInputMethod() function.
  71. If the list is empty (the default) the input method is not
  72. shared with any other layout and will be destroyed when the
  73. layout changes.
  74. The list should contain only the name of the layout type,
  75. e.g., ['symbols']. The current layout does not have to be
  76. included in the list.
  77. */
  78. property var sharedLayouts
  79. /*! Sets the input mode to be used in this layout.
  80. By default, the virtual keyboard attempts to preserve
  81. the current input mode when switching to a different
  82. keyboard layout.
  83. If the current input mode is not valid in the current
  84. context, the default input mode is specified by the
  85. input method.
  86. */
  87. property int inputMode: -1
  88. /*! Sets the key weight for all children keys.
  89. The default value is inherited from the parent element
  90. in the layout hierarchy.
  91. */
  92. property real keyWeight
  93. /*! \since QtQuick.VirtualKeyboard 2.0
  94. Sets the \c smallTextVisible for all children keys.
  95. The default value is inherited from the parent element
  96. in the layout hierarchy.
  97. */
  98. property bool smallTextVisible
  99. spacing: 0
  100. function scanLayout() {
  101. var layout = {
  102. width: root.width,
  103. height: root.height,
  104. keys: []
  105. }
  106. __scanLayoutRecursive(this, layout)
  107. return layout
  108. }
  109. function __scanLayoutRecursive(parent, layout) {
  110. for (var i in parent.children) {
  111. var child = parent.children[i]
  112. if (child.keyType !== undefined) {
  113. var pos = mapFromItem(child, 0, 0)
  114. var key = {
  115. left: pos.x,
  116. top: pos.y,
  117. width: child.width,
  118. height: child.height,
  119. keyType: child.keyType,
  120. key: child.key,
  121. text: child.text,
  122. altKeys: child.effectiveAlternativeKeys,
  123. isFunctionKey: child.functionKey,
  124. noKeyEvent: child.noKeyEvent
  125. }
  126. if (key.left + key.width > layout.width)
  127. layout.width = key.left + key.width
  128. if (key.top + key.height > layout.height)
  129. layout.height = key.top + key.height
  130. layout.keys.push(key)
  131. } else {
  132. __scanLayoutRecursive(child, layout)
  133. }
  134. }
  135. }
  136. }