TextField.qml 2.1 KB

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