BaseKey.qml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 BaseKey
  8. \inqmlmodule QtQuick.VirtualKeyboard.Components
  9. \ingroup qmlclass
  10. \ingroup qtvirtualkeyboard-components-qml
  11. \inherits Item
  12. \brief Common parent for all key types.
  13. BaseKey is a common type for all keys in keyboard layout.
  14. This type should not be used directly in the layouts. The specialized
  15. key types, such as Key or EnterKey should be used instead.
  16. */
  17. Item {
  18. id: keyItem
  19. /*! \since QtQuick.VirtualKeyboard 6.1
  20. \l Key type for the specialized key. Possible values are defined by the
  21. {QtVirtualKeyboard::KeyType}{key type enumeration}.
  22. For example, \l SpaceKey sets this value to \e QtVirtualKeyboard.KeyType.SpaceKey.
  23. */
  24. property int keyType: QtVirtualKeyboard.KeyType.BaseKey
  25. /*! Sets the key weight value which determines the relative size of the key.
  26. Use this property to change the key size in the layout.
  27. The default value is inherited from the parent element
  28. of the key in the layout hierarchy.
  29. */
  30. property real weight: parent.keyWeight
  31. /*! Sets the key text for input method processing.
  32. In most cases, this is the Unicode representation of the key code.
  33. The default value is an empty string.
  34. */
  35. property string text: ""
  36. /*! Sets the display text.
  37. This string is rendered in the keyboard layout.
  38. The default value is the key text.
  39. */
  40. property string displayText: text
  41. /*! \since QtQuick.VirtualKeyboard 2.0
  42. Sets the small text rendered in the corner of the key.
  43. The default value based on the default item in the effective alternative keys.
  44. */
  45. property string smallText: effectiveAlternativeKeys && effectiveAlternativeKeysHighlightIndex !== -1 ? effectiveAlternativeKeys[effectiveAlternativeKeysHighlightIndex] : ""
  46. /*! \since QtQuick.VirtualKeyboard 2.0
  47. Sets the visibility of small text.
  48. The default value is inherited from the parent.
  49. */
  50. property bool smallTextVisible: parent.smallTextVisible
  51. /*! Sets the list of alternative keys.
  52. This property can be set to a string, or a list of strings. If the value is
  53. a string, the alternative keys are presented as individual characters of
  54. that string. If the value is a list of strings, the list is used instead.
  55. The alternative keys are presented to the user by pressing and holding a key
  56. with this property set.
  57. \note If the alternative keys contains the key \c text, it will be filtered from
  58. the \c effectiveAlternativeKeys and its position will be used as an indicator
  59. for the highlighted item instead.
  60. The default is empty list.
  61. */
  62. property var alternativeKeys: []
  63. /*! \since QtQuick.VirtualKeyboard 2.0
  64. This property contains the effective alternative keys presented to user.
  65. The list is contains the items in the \c alternativeKeys excluding the \c text
  66. item.
  67. */
  68. readonly property var effectiveAlternativeKeys: {
  69. var textIndex = alternativeKeys.indexOf(text)
  70. if (textIndex == -1)
  71. return alternativeKeys
  72. return alternativeKeys.slice(0, textIndex).concat(alternativeKeys.slice(textIndex + 1))
  73. }
  74. /*! \since QtQuick.VirtualKeyboard 2.0
  75. This property contains the index of highlighted item in the \c effectiveAlternativeKeys.
  76. The index is calculated from the index of the key \c text in the \c alternativeKeys.
  77. For example, if the alternative keys contains "çcċčć" and the key \c text is "c",
  78. this index will become 1 and the effective alternative keys presented to user will
  79. be "ç[ċ]čć".
  80. */
  81. readonly property int effectiveAlternativeKeysHighlightIndex: {
  82. var index = alternativeKeys.indexOf(text)
  83. return index > 0 && (index + 1) == alternativeKeys.length ? index - 1 : index
  84. }
  85. /*! \since QtQuick.VirtualKeyboard 6.2
  86. This property allows overriding the list of key strings presented to the user in the
  87. alternative keys view.
  88. */
  89. property var displayAlternativeKeys: effectiveAlternativeKeys
  90. /*! Sets the key code for input method processing.
  91. The default is Qt.Key_unknown.
  92. */
  93. property int key: Qt.Key_unknown
  94. /*! \since QtQuick.VirtualKeyboard 1.3
  95. This property controls whether the key emits key events for input
  96. method processing. When true, the key events are disabled.
  97. By default, the key event is emitted if the \e key is not unknown
  98. or the \e text is not empty.
  99. */
  100. property bool noKeyEvent: key === Qt.Key_unknown && text.length === 0
  101. /*! This property holds the active status of the key.
  102. This property is automatically set to true when the key is pressed.
  103. */
  104. property bool active: false
  105. /*! \since QtQuick.VirtualKeyboard 1.3
  106. Disables key modifiers on the emitted key.
  107. The default is false.
  108. */
  109. property bool noModifier: false
  110. /*! Sets the key repeat attribute.
  111. If the repeat is enabled, the key will repeat the input events while held down.
  112. The repeat should not be used if alternativeKeys is also set.
  113. The default is false.
  114. */
  115. property bool repeat: false
  116. /*! Sets the highlighted status of the key.
  117. The default is false.
  118. */
  119. property bool highlighted: false
  120. /*! Sets the function key attribute.
  121. The default is false.
  122. */
  123. property bool functionKey: false
  124. /*! Sets the show preview attribute.
  125. By default, the character preview popup is not shown for function keys.
  126. */
  127. property bool showPreview: enabled && !functionKey && !keyboard.navigationModeActive
  128. /*! This property holds the pressed status of the key.
  129. The pressed status can only be true if the key is both enabled and active.
  130. When the key state becomes pressed, it triggers a key down event for the
  131. input engine. A key up event is triggered when the key is released.
  132. */
  133. property bool pressed: enabled && active
  134. /*! This property holds the uppercase status of the key.
  135. By default, this property reflects the uppercase status of the keyboard.
  136. */
  137. property bool uppercased: InputContext.uppercase && !noModifier
  138. /*! Sets the key panel delegate for the key.
  139. This property is essential for key decoration. Without a key panel delegate,
  140. the key is invisible. This property should be assigned in the inherited key type.
  141. */
  142. property alias keyPanelDelegate: keyPanel.sourceComponent
  143. /*!
  144. \since QtQuick.VirtualKeyboard 1.1
  145. This property holds the sound effect to be played on key press.
  146. This property is read-only since the sound effects are defined in the keyboard style.
  147. */
  148. readonly property url soundEffect: keyPanel.item ? keyPanel.item.soundEffect : ""
  149. onSoundEffectChanged: keyboard.soundEffect.register(soundEffect)
  150. Layout.minimumWidth: keyPanel.implicitWidth
  151. Layout.minimumHeight: keyPanel.implicitHeight
  152. Layout.preferredWidth: weight
  153. Layout.fillWidth: true
  154. Layout.fillHeight: true
  155. Loader {
  156. id: keyPanel
  157. anchors.fill: parent
  158. onLoaded: keyPanel.item.control = keyItem
  159. }
  160. /*! This signal is triggered when the key is pressed, allowing custom processing
  161. of key.
  162. */
  163. signal clicked
  164. }