GcodeTextArea.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. wrapMode: TextEdit.NoWrap
  55. onActiveFocusChanged:
  56. {
  57. if (!activeFocus)
  58. {
  59. propertyProvider.setPropertyValue("value", text)
  60. }
  61. }
  62. background: Rectangle
  63. {
  64. anchors.fill: parent
  65. anchors.margins: -border.width //Wrap the border around the parent.
  66. color: UM.Theme.getColor("detail_background")
  67. border.color:
  68. {
  69. if (!gcodeTextArea.enabled)
  70. {
  71. return UM.Theme.getColor("setting_control_disabled_border")
  72. }
  73. if (gcodeTextArea.hovered || gcodeTextArea.activeFocus)
  74. {
  75. return UM.Theme.getColor("border_main")
  76. }
  77. return UM.Theme.getColor("border_field_light")
  78. }
  79. border.width: UM.Theme.getSize("default_lining").width
  80. }
  81. }
  82. }
  83. }