GcodeTextArea.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. TextArea.flickable: TextArea
  46. {
  47. id: gcodeTextArea
  48. hoverEnabled: true
  49. selectByMouse: true
  50. text: (propertyProvider.properties.value) ? propertyProvider.properties.value : ""
  51. font: UM.Theme.getFont("fixed")
  52. renderType: Text.NativeRendering
  53. color: UM.Theme.getColor("text")
  54. selectionColor: UM.Theme.getColor("text_selection")
  55. selectedTextColor: UM.Theme.getColor("text")
  56. wrapMode: TextEdit.NoWrap
  57. onActiveFocusChanged:
  58. {
  59. if (!activeFocus)
  60. {
  61. propertyProvider.setPropertyValue("value", text)
  62. }
  63. }
  64. background: Rectangle
  65. {
  66. anchors.fill: parent
  67. anchors.margins: -border.width //Wrap the border around the 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. }