GcodeTextArea.qml 3.0 KB

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