KeyboardLayoutLoader.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.VirtualKeyboard
  5. /*!
  6. \qmltype KeyboardLayoutLoader
  7. \inqmlmodule QtQuick.VirtualKeyboard.Components
  8. \ingroup qmlclass
  9. \ingroup qtvirtualkeyboard-components-qml
  10. \inherits Loader
  11. \since QtQuick.VirtualKeyboard 1.1
  12. \brief Allows dynamic loading of keyboard layout.
  13. This type is useful for keyboard layouts consisting of multiple pages of keys.
  14. A single keyboard layout (a page) is defined by using the Component
  15. as a container. The active keyboard layout can then be changed by
  16. setting the sourceComponent property to a different value.
  17. Example:
  18. \code
  19. import QtQuick
  20. import QtQuick.Layouts
  21. import QtQuick.VirtualKeyboard
  22. // file: layouts/en_GB/symbols.qml
  23. KeyboardLayoutLoader {
  24. property bool secondPage
  25. onVisibleChanged: if (!visible) secondPage = false
  26. sourceComponent: secondPage ? page2 : page1
  27. Component {
  28. id: page1
  29. KeyboardLayout {
  30. // Keyboard layout definition for page 1
  31. }
  32. }
  33. Component {
  34. id: page2
  35. KeyboardLayout {
  36. // Keyboard layout definition for page 2
  37. }
  38. }
  39. }
  40. \endcode
  41. */
  42. Loader {
  43. /*! Sets the input method for all the keyboard layouts loaded
  44. in this context.
  45. The input method can either be set separately for each keyboard
  46. layout, or commonly at this context. If set separately, then this
  47. property should not be modified.
  48. */
  49. property var inputMethod: item ? item.inputMethod : null
  50. /*! This function may be overridden by the keyboard layout
  51. to create the input method object dynamically. The default
  52. implementation forwards the call to the child keyboard
  53. layout.
  54. The input method object created by this function can outlive
  55. keyboard layout transitions in certain cases. In particular,
  56. this applies to the transitions between the layouts listed in
  57. the sharedLayouts property.
  58. */
  59. function createInputMethod() {
  60. return item ? item.createInputMethod() : null
  61. }
  62. /*! List of layout names which share the input method created
  63. by the createInputMethod() function.
  64. If the list is empty (the default) the input method is not
  65. shared with any other layout and will be destroyed when the
  66. layout changes.
  67. The list should contain only the name of the layout type,
  68. e.g., ['symbols']. The current layout does not have to be
  69. included in the list.
  70. */
  71. property var sharedLayouts: item ? item.sharedLayouts : null
  72. /*! Sets the input mode for all the keyboard layouts loaded
  73. in this context.
  74. The input mode can either be set separately for each keyboard
  75. layout, or commonly at this context. If set separately, then this
  76. property should not be modified.
  77. */
  78. property int inputMode: item ? item.inputMode : -1
  79. property int __updateCount
  80. active: parent !== null
  81. onItemChanged: {
  82. if (parent && item && __updateCount++ > 0) {
  83. if (!keyboard.inputMethodNeedsReset)
  84. keyboard.updateInputMethod()
  85. keyboard.notifyLayoutChanged()
  86. }
  87. }
  88. function scanLayout() {
  89. if (item === null)
  90. return null
  91. return item.scanLayout()
  92. }
  93. }