TextField.qml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. renderType: Text.NativeRendering
  20. selectionColor: UM.Theme.getColor("text_selection")
  21. leftPadding: iconLeft.visible ? iconLeft.width + UM.Theme.getSize("default_margin").width * 2 : UM.Theme.getSize("thin_margin").width
  22. states: [
  23. State
  24. {
  25. name: "disabled"
  26. when: !control.enabled
  27. PropertyChanges { target: control; color: UM.Theme.getColor("text_field_text_disabled")}
  28. PropertyChanges { target: backgroundRectangle; liningColor: UM.Theme.getColor("text_field_border_disabled")}
  29. },
  30. State
  31. {
  32. name: "invalid"
  33. when: !control.acceptableInput
  34. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_validation_error_background")}
  35. },
  36. State
  37. {
  38. name: "hovered"
  39. when: control.hovered || control.activeFocus
  40. PropertyChanges { target: backgroundRectangle; liningColor: UM.Theme.getColor("text_field_border_hovered")}
  41. }
  42. ]
  43. background: UM.UnderlineBackground
  44. {
  45. id: backgroundRectangle
  46. //Optional icon added on the left hand side.
  47. UM.ColorImage
  48. {
  49. id: iconLeft
  50. anchors
  51. {
  52. verticalCenter: parent.verticalCenter
  53. left: parent.left
  54. leftMargin: UM.Theme.getSize("default_margin").width
  55. }
  56. visible: source != ""
  57. height: UM.Theme.getSize("small_button_icon").height
  58. width: visible ? height : 0
  59. color: control.color
  60. }
  61. }
  62. }