TextField.qml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2017 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.Imagine
  8. import QtQuick.Controls.Imagine.impl
  9. T.TextField {
  10. id: control
  11. implicitWidth: implicitBackgroundWidth + leftInset + rightInset
  12. || Math.max(contentWidth, placeholder.implicitWidth) + leftPadding + rightPadding
  13. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  14. contentHeight + topPadding + bottomPadding,
  15. placeholder.implicitHeight + topPadding + bottomPadding)
  16. topPadding: background ? background.topPadding : 0
  17. leftPadding: background ? background.leftPadding : 0
  18. rightPadding: background ? background.rightPadding : 0
  19. bottomPadding: background ? background.bottomPadding : 0
  20. topInset: background ? -background.topInset || 0 : 0
  21. leftInset: background ? -background.leftInset || 0 : 0
  22. rightInset: background ? -background.rightInset || 0 : 0
  23. bottomInset: background ? -background.bottomInset || 0 : 0
  24. color: control.palette.text
  25. selectionColor: control.palette.highlight
  26. selectedTextColor: control.palette.highlightedText
  27. placeholderTextColor: control.palette.placeholderText
  28. verticalAlignment: Qt.AlignVCenter
  29. ContextMenu.menu: TextEditingContextMenu {
  30. editor: control
  31. }
  32. PlaceholderText {
  33. id: placeholder
  34. x: control.leftPadding
  35. y: control.topPadding
  36. width: control.width - (control.leftPadding + control.rightPadding)
  37. height: control.height - (control.topPadding + control.bottomPadding)
  38. text: control.placeholderText
  39. font: control.font
  40. color: control.placeholderTextColor
  41. verticalAlignment: control.verticalAlignment
  42. visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
  43. elide: Text.ElideRight
  44. renderType: control.renderType
  45. }
  46. background: NinePatchImage {
  47. source: Imagine.url + "textfield-background"
  48. NinePatchImageSelector on source {
  49. states: [
  50. {"disabled": !control.enabled},
  51. {"focused": control.activeFocus},
  52. {"mirrored": control.mirrored},
  53. {"hovered": control.enabled && control.hovered}
  54. ]
  55. }
  56. }
  57. }