TextField.qml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.3 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. UM.I18nCatalog { id: catalog; name: "cura" }
  15. hoverEnabled: true
  16. selectByMouse: true
  17. font: UM.Theme.getFont("default")
  18. color: UM.Theme.getColor("text")
  19. renderType: Text.NativeRendering
  20. leftPadding: iconLeft.visible ? iconLeft.width + UM.Theme.getSize("default_margin").width * 2 : UM.Theme.getSize("thin_margin").width
  21. states: [
  22. State
  23. {
  24. name: "disabled"
  25. when: !textField.enabled
  26. PropertyChanges { target: backgroundRectangle.border; color: UM.Theme.getColor("setting_control_disabled_border")}
  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.border; color: UM.Theme.getColor("setting_validation_error")}
  34. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_validation_error_background")}
  35. },
  36. State
  37. {
  38. name: "hovered"
  39. when: textField.hovered || textField.activeFocus
  40. PropertyChanges { target: backgroundRectangle.border; color: UM.Theme.getColor("setting_control_border_highlight") }
  41. }
  42. ]
  43. background: Rectangle
  44. {
  45. id: backgroundRectangle
  46. color: UM.Theme.getColor("main_background")
  47. radius: UM.Theme.getSize("setting_control_radius").width
  48. border.color:
  49. {
  50. if (!textField.enabled)
  51. {
  52. return UM.Theme.getColor("setting_control_disabled_border")
  53. }
  54. if (textField.hovered || textField.activeFocus)
  55. {
  56. return UM.Theme.getColor("setting_control_border_highlight")
  57. }
  58. return UM.Theme.getColor("setting_control_border")
  59. }
  60. //Optional icon added on the left hand side.
  61. UM.RecolorImage
  62. {
  63. id: iconLeft
  64. anchors
  65. {
  66. verticalCenter: parent.verticalCenter
  67. left: parent.left
  68. leftMargin: UM.Theme.getSize("default_margin").width
  69. }
  70. visible: source != ""
  71. height: UM.Theme.getSize("small_button_icon").height
  72. width: visible ? height : 0
  73. color: textField.color
  74. }
  75. }
  76. }