TextField.qml 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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: "hovered"
  41. when: control.hovered || control.activeFocus
  42. PropertyChanges { target: backgroundRectangle; liningColor: UM.Theme.getColor("text_field_border_hovered")}
  43. }
  44. ]
  45. background: UM.UnderlineBackground
  46. {
  47. id: backgroundRectangle
  48. //Optional icon added on the left hand side.
  49. UM.ColorImage
  50. {
  51. id: iconLeft
  52. anchors
  53. {
  54. verticalCenter: parent.verticalCenter
  55. left: parent.left
  56. leftMargin: UM.Theme.getSize("default_margin").width
  57. }
  58. visible: source != ""
  59. height: UM.Theme.getSize("small_button_icon").height
  60. width: visible ? height : 0
  61. color: control.color
  62. }
  63. }
  64. }