|
| 1 | +// Copyright (c) 2025 Ultimaker B.V. |
| 2 | +// Cura is released under the terms of the LGPLv3 or higher. |
| 3 | + |
| 4 | +import QtQuick 2.15 |
| 5 | +import QtQuick.Controls 2.15 |
| 6 | + |
| 7 | +import UM 1.7 as UM |
| 8 | + |
| 9 | +// Custom multiline text area component for post-processing script settings |
| 10 | +// Triggered when setting has "comments": "multiline" property |
| 11 | +Item |
| 12 | +{ |
| 13 | + id: base |
| 14 | + |
| 15 | + // Properties passed from the Loader |
| 16 | + property var definition |
| 17 | + property var settingDefinitionsModel |
| 18 | + property var propertyProvider |
| 19 | + property var globalPropertyProvider |
| 20 | + |
| 21 | + // Standard setting item properties (required by loader but unused in this component) |
| 22 | + property bool showRevertButton: false |
| 23 | + property bool showInheritButton: false |
| 24 | + property bool showLinkedSettingIcon: false |
| 25 | + property bool doDepthIndentation: false |
| 26 | + property bool doQualityUserSettingEmphasis: false |
| 27 | + |
| 28 | + // Internal state tracking (unused but kept for potential future use) |
| 29 | + property string textBeforeEdit |
| 30 | + property bool textHasChanged |
| 31 | + |
| 32 | + // Signals for tooltip support (required by Connections in loader) |
| 33 | + // Note: These signals are declared but intentionally never emitted. |
| 34 | + // This prevents tooltips from appearing on mouse-over, which would obstruct the text area |
| 35 | + // while the user is typing or editing multiline content. |
| 36 | + signal showTooltip(string text) |
| 37 | + signal hideTooltip() |
| 38 | + |
| 39 | + width: parent.width |
| 40 | + // Height calculation: label height + spacing + text area (3x normal height for multiline editing) |
| 41 | + height: UM.Theme.getSize("standard_list_lineheight").height + UM.Theme.getSize("narrow_margin").height + (UM.Theme.getSize("setting_control").height * 3) |
| 42 | + |
| 43 | + UM.Label |
| 44 | + { |
| 45 | + id: labelText |
| 46 | + anchors.top: parent.top |
| 47 | + anchors.left: parent.left |
| 48 | + anchors.right: parent.right |
| 49 | + height: UM.Theme.getSize("standard_list_lineheight").height |
| 50 | + text: definition ? definition.label : "" |
| 51 | + elide: Text.ElideRight |
| 52 | + font: UM.Theme.getFont("default_bold") |
| 53 | + color: UM.Theme.getColor("text") |
| 54 | + } |
| 55 | + |
| 56 | + Flickable |
| 57 | + { |
| 58 | + id: flickable |
| 59 | + anchors.top: labelText.bottom |
| 60 | + anchors.topMargin: UM.Theme.getSize("narrow_margin").height |
| 61 | + anchors.left: parent.left |
| 62 | + anchors.right: parent.right |
| 63 | + // Right margin to prevent overlap with parent ListView scrollbar |
| 64 | + anchors.rightMargin: UM.Theme.getSize("default_margin").width + UM.Theme.getSize("narrow_margin").width |
| 65 | + height: UM.Theme.getSize("setting_control").height * 3 |
| 66 | + |
| 67 | + clip: true |
| 68 | + ScrollBar.vertical: UM.ScrollBar { } |
| 69 | + |
| 70 | + TextArea.flickable: TextArea |
| 71 | + { |
| 72 | + id: textArea |
| 73 | + |
| 74 | + enabled: propertyProvider && propertyProvider.properties ? propertyProvider.properties.enabled === "True" : true |
| 75 | + // Explicit undefined check to prevent QML warnings about undefined QString assignment |
| 76 | + text: (propertyProvider && propertyProvider.properties && propertyProvider.properties.value !== undefined) ? propertyProvider.properties.value : "" |
| 77 | + |
| 78 | + background: Rectangle |
| 79 | + { |
| 80 | + color: UM.Theme.getColor("setting_control") |
| 81 | + border.color: textArea.activeFocus ? UM.Theme.getColor("text_field_border_active") : UM.Theme.getColor("text_field_border") |
| 82 | + border.width: UM.Theme.getSize("default_lining").width |
| 83 | + } |
| 84 | + |
| 85 | + onTextChanged: |
| 86 | + { |
| 87 | + // Save value on each keystroke when focused (live update) |
| 88 | + if (activeFocus && propertyProvider) |
| 89 | + { |
| 90 | + propertyProvider.setPropertyValue("value", text); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + font: UM.Theme.getFont("default") |
| 95 | + color: UM.Theme.getColor("text") |
| 96 | + selectionColor: UM.Theme.getColor("text_selection") |
| 97 | + selectedTextColor: UM.Theme.getColor("text") |
| 98 | + wrapMode: TextEdit.NoWrap |
| 99 | + selectByMouse: true |
| 100 | + |
| 101 | + // Allow Enter/Return to insert newlines instead of closing dialog |
| 102 | + Keys.onReturnPressed: function(event) { event.accepted = false; } |
| 103 | + Keys.onEnterPressed: function(event) { event.accepted = false; } |
| 104 | + // Escape key removes focus from text area |
| 105 | + Keys.onEscapePressed: function(event) { focus = false; event.accepted = true; } |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments