GcodeTextArea.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 QtQuick.Layouts 1.3
  6. import UM 1.5 as UM
  7. import Cura 1.1 as Cura
  8. //
  9. // TextArea widget for editing Gcode in the Machine Settings dialog.
  10. //
  11. Item
  12. {
  13. id: control
  14. UM.I18nCatalog { id: catalog; name: "cura"; }
  15. property alias containerStackId: propertyProvider.containerStackId
  16. property alias settingKey: propertyProvider.key
  17. property alias settingStoreIndex: propertyProvider.storeIndex
  18. property alias labelText: titleLabel.text
  19. property alias labelFont: titleLabel.font
  20. UM.SettingPropertyProvider
  21. {
  22. id: propertyProvider
  23. watchedProperties: [ "value", "description" ]
  24. }
  25. UM.Label
  26. {
  27. id: titleLabel
  28. anchors.top: parent.top
  29. anchors.left: parent.left
  30. font: UM.Theme.getFont("medium_bold")
  31. }
  32. Flickable
  33. {
  34. anchors
  35. {
  36. top: titleLabel.bottom
  37. topMargin: UM.Theme.getSize("default_margin").height
  38. bottom: parent.bottom
  39. left: parent.left
  40. right: parent.right
  41. }
  42. ScrollBar.vertical: UM.ScrollBar {}
  43. clip: true
  44. TextArea.flickable: TextArea
  45. {
  46. id: gcodeTextArea
  47. hoverEnabled: true
  48. selectByMouse: true
  49. text: (propertyProvider.properties.value) ? propertyProvider.properties.value : ""
  50. font: UM.Theme.getFont("fixed")
  51. renderType: Text.NativeRendering
  52. color: UM.Theme.getColor("text")
  53. selectionColor: UM.Theme.getColor("text_selection")
  54. selectedTextColor: UM.Theme.getColor("text")
  55. wrapMode: TextEdit.NoWrap
  56. padding: UM.Theme.getSize("narrow_margin").height + backgroundRectangle.border.width
  57. onActiveFocusChanged:
  58. {
  59. if (!activeFocus)
  60. {
  61. propertyProvider.setPropertyValue("value", text)
  62. }
  63. }
  64. background: Rectangle
  65. {
  66. id: backgroundRectangle
  67. anchors.fill: parent
  68. color: UM.Theme.getColor("detail_background")
  69. border.color:
  70. {
  71. if (!gcodeTextArea.enabled)
  72. {
  73. return UM.Theme.getColor("setting_control_disabled_border")
  74. }
  75. if (gcodeTextArea.hovered || gcodeTextArea.activeFocus)
  76. {
  77. return UM.Theme.getColor("text_field_border_active")
  78. }
  79. return UM.Theme.getColor("border_field_light")
  80. }
  81. border.width: UM.Theme.getSize("default_lining").width
  82. }
  83. }
  84. }
  85. }