HandwritingInputPanel.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright (C) 2016 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
  3. import QtQuick
  4. // Deliberately imported after QtQuick to avoid missing restoreMode property in Binding. Fix in Qt 6.
  5. import QtQml
  6. import QtQuick.Window
  7. import QtQuick.VirtualKeyboard
  8. import QtQuick.VirtualKeyboard.Components
  9. /*!
  10. \qmltype HandwritingInputPanel
  11. \inqmlmodule QtQuick.VirtualKeyboard
  12. \since QtQuick.VirtualKeyboard 2.0
  13. \brief Provides a handwriting panel add-on for the virtual keyboard UI.
  14. \ingroup qmlclass
  15. \ingroup qtvirtualkeyboard-qml
  16. The HandwritingInputPanel is an add-on component for the InputPanel, which
  17. enables full-screen handwriting input for the application.
  18. HandwritingInputPanel is designed to be anchored full screen alongside
  19. the InputPanel. The operating principle is that when the handwriting panel
  20. is "available", the InputPanel is invisible. This functionality is built-in,
  21. and requires no more than a reference to the InputPanel instance.
  22. The panel is set into operation by setting the \l {HandwritingInputPanel::}{available}
  23. property to \c true. When the panel is in operation, the keyboard remains hidden
  24. when the input focus is set. When \c available is \c true, handwriting input is
  25. activated by setting the \l {HandwritingInputPanel::}{active} property to \c true.
  26. The user interface, which provides controls for handwriting mode and the
  27. visibility of the keyboard, is application-specific. One suggested implementation
  28. is to use a floating button on the handwriting panel, where single click toggles
  29. the handwriting mode (changes the \l {HandwritingInputPanel::}{active} property), and double-click toggles
  30. the visibility of the keyboard (changes the \l {HandwritingInputPanel::}{available} property).
  31. HandwritingInputPanel also provides a word candidate popup which allows the user
  32. to select an alternative word candidate from the list of suggestions generated
  33. by the handwriting input method.
  34. */
  35. Item {
  36. id: handwritingInputPanel
  37. /*! A reference to the input panel instance.
  38. This property must be set to the existing input panel instance.
  39. */
  40. property var inputPanel
  41. /*! This property controls the availability status of the handwriting input method.
  42. Setting the property to \c true prepares the handwriting input method and inhibits
  43. the display of keyboard.
  44. */
  45. property bool available
  46. /*! This property controls the active status of the handwriting input method.
  47. Setting the property to \c true activates the handwriting input method. When the
  48. handwriting input method is active, all touch input is captured by the
  49. handwriting input panel and redirected to input engine for processing.
  50. */
  51. property bool active
  52. state: enabled && available ? (active ? "active" : "available") : "unavailable"
  53. enabled: inputPanel.keyboard.isHandwritingAvailable()
  54. visible: enabled && available && active && Qt.inputMethod.visible
  55. LayoutMirroring.enabled: false
  56. LayoutMirroring.childrenInherit: true
  57. Item {
  58. id: keyboard
  59. property var style: inputPanel && inputPanel.hasOwnProperty ? inputPanel.keyboard.style : null
  60. property var soundEffect: inputPanel && inputPanel.hasOwnProperty ? inputPanel.keyboard.soundEffect : null
  61. }
  62. onEnabledChanged: inputPanel.keyboard.fullScreenHandwritingMode = enabled && available
  63. onAvailableChanged: inputPanel.keyboard.fullScreenHandwritingMode = enabled && available
  64. TraceInputArea {
  65. id: hwrInputArea
  66. enabled: handwritingInputPanel.enabled && handwritingInputPanel.available && handwritingInputPanel.active
  67. objectName: "hwrInputArea"
  68. anchors.fill: parent
  69. patternRecognitionMode: InputEngine.PatternRecognitionMode.Handwriting
  70. canvasType: "fullscreen"
  71. }
  72. Binding {
  73. target: InputContext.priv
  74. property: "keyboardRectangle"
  75. value: Qt.rect(hwrInputArea.x, hwrInputArea.y, hwrInputArea.width, hwrInputArea.height)
  76. when: handwritingInputPanel.enabled && handwritingInputPanel.available && handwritingInputPanel.active
  77. }
  78. Binding {
  79. target: inputPanel ? inputPanel.keyboard : null
  80. property: "active"
  81. value: false
  82. when: handwritingInputPanel.enabled && handwritingInputPanel.available
  83. restoreMode: Binding.RestoreBinding
  84. }
  85. WordCandidatePopupList {
  86. id: wordCandidatePopupList
  87. z: 1
  88. objectName: "wordCandidatePopupList"
  89. enabled: handwritingInputPanel.enabled && handwritingInputPanel.available && handwritingInputPanel.active
  90. }
  91. Loader {
  92. sourceComponent: keyboard.style.popupListBackground
  93. anchors.fill: wordCandidatePopupList
  94. z: -1
  95. visible: wordCandidatePopupList.visible
  96. }
  97. }