TextField.qml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) 2021 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: textField
  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")
  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: !textField.enabled
  27. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_control_disabled")}
  28. },
  29. State
  30. {
  31. name: "invalid"
  32. when: !textField.acceptableInput
  33. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_validation_error_background")}
  34. },
  35. State
  36. {
  37. name: "hovered"
  38. when: textField.hovered || textField.activeFocus
  39. PropertyChanges { target: backgroundRectangle; liningColor: UM.Theme.getColor("border_main")}
  40. }
  41. ]
  42. background: UM.UnderlineBackground
  43. {
  44. id: backgroundRectangle
  45. //Optional icon added on the left hand side.
  46. UM.RecolorImage
  47. {
  48. id: iconLeft
  49. anchors
  50. {
  51. verticalCenter: parent.verticalCenter
  52. left: parent.left
  53. leftMargin: UM.Theme.getSize("default_margin").width
  54. }
  55. visible: source != ""
  56. height: UM.Theme.getSize("small_button_icon").height
  57. width: visible ? height : 0
  58. color: textField.color
  59. }
  60. }
  61. }