TextField.qml 2.3 KB

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