TextField.qml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.TextField {
  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. readonly property string __currentState: [
  16. !enabled && "disabled",
  17. activeFocus && "focused",
  18. enabled && !activeFocus && hovered && "hovered",
  19. ].filter(Boolean).join("_") || "normal"
  20. readonly property var __config: Config.controls.textfield[__currentState] || {}
  21. topPadding: __config.topPadding || 0
  22. bottomPadding: __config.bottomPadding || 0
  23. leftPadding: __config.leftPadding || 0
  24. rightPadding: __config.rightPadding || 0
  25. topInset: -__config.topInset || 0
  26. bottomInset: -__config.bottomInset || 0
  27. leftInset: -__config.leftInset || 0
  28. rightInset: -__config.rightInset || 0
  29. color: control.palette.text
  30. selectionColor: control.palette.highlight
  31. selectedTextColor: control.palette.highlightedText
  32. placeholderTextColor: control.palette.placeholderText
  33. verticalAlignment: Text.AlignVCenter
  34. PlaceholderText {
  35. id: placeholder
  36. x: control.leftPadding
  37. y: control.topPadding
  38. width: control.width - (control.leftPadding + control.rightPadding)
  39. height: control.height - (control.topPadding + control.bottomPadding)
  40. text: control.placeholderText
  41. font: control.font
  42. color: control.placeholderTextColor
  43. verticalAlignment: control.verticalAlignment
  44. horizontalAlignment: control.horizontalAlignment
  45. visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
  46. elide: Text.ElideRight
  47. renderType: control.renderType
  48. }
  49. background: Impl.StyleImage {
  50. imageConfig: control.__config.background
  51. Item{
  52. visible: control.activeFocus
  53. width: parent.width
  54. height: 2
  55. y: parent.height - height
  56. Impl.FocusStroke {
  57. width: parent.width
  58. height: parent.height
  59. radius: control.__config.background.bottomOffset
  60. color: control.palette.accent
  61. }
  62. }
  63. }
  64. }