TextArea.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2024 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. import QtQuick
  5. import QtQuick.Templates as T
  6. import QtQuick.Controls.impl
  7. import QtQuick.Controls.FluentWinUI3.impl as Impl
  8. T.TextArea {
  9. id: control
  10. implicitWidth: implicitBackgroundWidth + leftInset + rightInset
  11. || Math.max(contentWidth, placeholder.implicitWidth) + leftPadding + rightPadding
  12. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  13. contentHeight + topPadding + bottomPadding,
  14. placeholder.implicitHeight + topPadding + bottomPadding)
  15. topPadding: __config.topPadding || 0
  16. bottomPadding: __config.bottomPadding || 0
  17. leftPadding: __config.leftPadding || 0
  18. rightPadding: __config.rightPadding || 0
  19. topInset: -__config.topInset || 0
  20. bottomInset: -__config.bottomInset || 0
  21. leftInset: -__config.leftInset || 0
  22. rightInset: -__config.rightInset || 0
  23. color: control.palette.text
  24. selectionColor: control.palette.highlight
  25. selectedTextColor: control.palette.highlightedText
  26. placeholderTextColor: control.palette.placeholderText
  27. verticalAlignment: Text.AlignVCenter
  28. readonly property string __currentState: [
  29. !enabled && "disabled",
  30. activeFocus && "focused",
  31. enabled && !activeFocus && hovered && "hovered",
  32. ].filter(Boolean).join("_") || "normal"
  33. readonly property var __config: Config.controls.textarea[__currentState] || {}
  34. ContextMenu.menu: Impl.TextEditingContextMenu {
  35. editor: control
  36. }
  37. PlaceholderText {
  38. id: placeholder
  39. x: control.leftPadding
  40. y: control.topPadding
  41. width: control.width - (control.leftPadding + control.rightPadding)
  42. height: control.height - (control.topPadding + control.bottomPadding)
  43. text: control.placeholderText
  44. font: control.font
  45. color: control.placeholderTextColor
  46. verticalAlignment: control.verticalAlignment
  47. horizontalAlignment: control.horizontalAlignment
  48. visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
  49. elide: Text.ElideRight
  50. renderType: control.renderType
  51. }
  52. background: Impl.StyleImage {
  53. imageConfig: control.__config.background
  54. Item{
  55. visible: control.activeFocus
  56. width: parent.width
  57. height: 2
  58. y: parent.height - height
  59. Impl.FocusStroke {
  60. width: parent.width
  61. height: parent.height
  62. radius: control.__config.background.bottomOffset
  63. color: control.palette.accent
  64. }
  65. }
  66. }
  67. }