DefaultTextField.qml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2020 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.Controls
  6. import QtQuick.Controls.impl
  7. import QtQuick.Templates as T
  8. import QtQuick.NativeStyle as NativeStyle
  9. T.TextField {
  10. id: control
  11. readonly property bool __nativeBackground: background instanceof NativeStyle.StyleItem
  12. readonly property bool __notCustomizable: true
  13. implicitWidth: implicitBackgroundWidth + leftInset + rightInset
  14. || Math.max(contentWidth, placeholder.implicitWidth) + leftPadding + rightPadding
  15. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  16. contentHeight + topPadding + bottomPadding,
  17. placeholder.implicitHeight + topPadding + bottomPadding)
  18. leftPadding: __nativeBackground ? background.contentPadding.left: 7
  19. rightPadding: __nativeBackground ? background.contentPadding.right: 7
  20. topPadding: __nativeBackground ? background.contentPadding.top: 3
  21. bottomPadding: __nativeBackground ? background.contentPadding.bottom: 3
  22. color: control.palette.text
  23. selectionColor: control.palette.highlight
  24. selectedTextColor: control.palette.highlightedText
  25. placeholderTextColor: control.palette.placeholderText
  26. verticalAlignment: TextInput.AlignTop
  27. PlaceholderText {
  28. id: placeholder
  29. x: control.leftPadding
  30. y: control.topPadding
  31. width: control.width - (control.leftPadding + control.rightPadding)
  32. height: control.height - (control.topPadding + control.bottomPadding)
  33. text: control.placeholderText
  34. font: control.font
  35. color: control.placeholderTextColor
  36. verticalAlignment: control.verticalAlignment
  37. visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
  38. elide: Text.ElideRight
  39. renderType: control.renderType
  40. }
  41. background: NativeStyle.TextField {
  42. control: control
  43. contentWidth: Math.max(control.contentWidth, placeholder.implicitWidth)
  44. contentHeight: control.contentHeight
  45. readonly property bool __ignoreNotCustomizable: true
  46. }
  47. }