TextField.qml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2019 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. UM.I18nCatalog { id: catalog; name: "cura" }
  14. hoverEnabled: true
  15. selectByMouse: true
  16. font: UM.Theme.getFont("default")
  17. color: UM.Theme.getColor("text")
  18. renderType: Text.NativeRendering
  19. states: [
  20. State
  21. {
  22. name: "disabled"
  23. when: !textField.enabled
  24. PropertyChanges { target: backgroundRectangle.border; color: UM.Theme.getColor("setting_control_disabled_border")}
  25. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_control_disabled")}
  26. },
  27. State
  28. {
  29. name: "invalid"
  30. when: !textField.acceptableInput
  31. PropertyChanges { target: backgroundRectangle.border; color: UM.Theme.getColor("setting_validation_error")}
  32. PropertyChanges { target: backgroundRectangle; color: UM.Theme.getColor("setting_validation_error_background")}
  33. },
  34. State
  35. {
  36. name: "hovered"
  37. when: textField.hovered || textField.activeFocus
  38. PropertyChanges { target: backgroundRectangle.border; color: UM.Theme.getColor("setting_control_border_highlight") }
  39. }
  40. ]
  41. background: Rectangle
  42. {
  43. id: backgroundRectangle
  44. color: UM.Theme.getColor("main_background")
  45. anchors.margins: Math.round(UM.Theme.getSize("default_lining").width)
  46. radius: UM.Theme.getSize("setting_control_radius").width
  47. border.color:
  48. {
  49. if (!textField.enabled)
  50. {
  51. return UM.Theme.getColor("setting_control_disabled_border")
  52. }
  53. if (textField.hovered || textField.activeFocus)
  54. {
  55. return UM.Theme.getColor("setting_control_border_highlight")
  56. }
  57. return UM.Theme.getColor("setting_control_border")
  58. }
  59. }
  60. }