TextField.qml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. PlaceholderText {
  30. id: placeholder
  31. x: control.leftPadding
  32. y: control.topPadding
  33. width: control.width - (control.leftPadding + control.rightPadding)
  34. height: control.height - (control.topPadding + control.bottomPadding)
  35. text: control.placeholderText
  36. font: control.font
  37. color: control.placeholderTextColor
  38. verticalAlignment: control.verticalAlignment
  39. visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
  40. elide: Text.ElideRight
  41. renderType: control.renderType
  42. }
  43. background: NinePatchImage {
  44. source: Imagine.url + "textfield-background"
  45. NinePatchImageSelector on source {
  46. states: [
  47. {"disabled": !control.enabled},
  48. {"focused": control.activeFocus},
  49. {"mirrored": control.mirrored},
  50. {"hovered": control.enabled && control.hovered}
  51. ]
  52. }
  53. }
  54. }