TextField.qml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.5 as UM
  6. import Cura 1.1 as Cura
  7. //
  8. // Cura-style TextField
  9. //
  10. TextField
  11. {
  12. id: control
  13. property alias leftIcon: iconLeft.source
  14. height: UM.Theme.getSize("setting_control").height
  15. hoverEnabled: true
  16. selectByMouse: true
  17. font: UM.Theme.getFont("default")
  18. color: UM.Theme.getColor("text_field_text")
  19. selectedTextColor: UM.Theme.getColor("text_field_text")
  20. placeholderTextColor: UM.Theme.getColor("text_field_text_disabled")
  21. renderType: Text.NativeRendering
  22. selectionColor: UM.Theme.getColor("text_selection")
  23. leftPadding: iconLeft.visible ? iconLeft.width + UM.Theme.getSize("default_margin").width * 2 : UM.Theme.getSize("thin_margin").width
  24. states: [
  25. State
  26. {
  27. name: "disabled"
  28. when: !control.enabled
  29. PropertyChanges { target: control; color: UM.Theme.getColor("text_field_text_disabled")}
  30. PropertyChanges { target: backgroundRectangle; liningColor: UM.Theme.getColor("text_field_border_disabled")}
  31. },
  32. State
  33. {
  34. name: "invalid"
  35. when: !control.acceptableInput
  36. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_validation_error_background")}
  37. },
  38. State
  39. {
  40. name: "active"
  41. when: control.activeFocus
  42. PropertyChanges
  43. {
  44. target: backgroundRectangle
  45. liningColor: UM.Theme.getColor("text_field_border_active")
  46. borderColor: UM.Theme.getColor("text_field_border_active")
  47. }
  48. },
  49. State
  50. {
  51. name: "hovered"
  52. when: control.hovered && !control.activeFocus
  53. PropertyChanges
  54. {
  55. target: backgroundRectangle
  56. liningColor: UM.Theme.getColor("text_field_border_hovered")
  57. }
  58. }
  59. ]
  60. background: UM.UnderlineBackground
  61. {
  62. id: backgroundRectangle
  63. //Optional icon added on the left hand side.
  64. UM.ColorImage
  65. {
  66. id: iconLeft
  67. anchors
  68. {
  69. verticalCenter: parent.verticalCenter
  70. left: parent.left
  71. leftMargin: UM.Theme.getSize("default_margin").width
  72. }
  73. visible: source != ""
  74. height: UM.Theme.getSize("small_button_icon").height
  75. width: visible ? height : 0
  76. color: control.color
  77. }
  78. }
  79. }