1// Copyright (c) 2020 Ultimaker B.V.
2// Cura is released under the terms of the LGPLv3 or higher.
3
4import QtQuick 2.10
5import QtQuick.Controls 2.3
6import QtQuick.Layouts 1.3
7
8import UM 1.3 as UM
9import Cura 1.1 as Cura
10
11
12//
13// TextArea widget for editing Gcode in the Machine Settings dialog.
14//
15UM.TooltipArea
16{
17    id: control
18
19    UM.I18nCatalog { id: catalog; name: "cura"; }
20
21    text: tooltip
22
23    property alias containerStackId: propertyProvider.containerStackId
24    property alias settingKey: propertyProvider.key
25    property alias settingStoreIndex: propertyProvider.storeIndex
26
27    property string tooltip: propertyProvider.properties.description ? propertyProvider.properties.description : ""
28
29    property alias labelText: titleLabel.text
30    property alias labelFont: titleLabel.font
31
32    UM.SettingPropertyProvider
33    {
34        id: propertyProvider
35        watchedProperties: [ "value", "description" ]
36    }
37
38    Label   // Title Label
39    {
40        id: titleLabel
41        anchors.top: parent.top
42        anchors.left: parent.left
43        font: UM.Theme.getFont("medium_bold")
44        color: UM.Theme.getColor("text")
45        renderType: Text.NativeRendering
46    }
47
48    ScrollView
49    {
50        anchors.top: titleLabel.bottom
51        anchors.topMargin: UM.Theme.getSize("default_margin").height
52        anchors.bottom: parent.bottom
53        anchors.left: parent.left
54        anchors.right: parent.right
55
56        background: Rectangle
57        {
58            color: UM.Theme.getColor("main_background")
59            anchors.fill: parent
60
61            border.color:
62            {
63                if (!gcodeTextArea.enabled)
64                {
65                    return UM.Theme.getColor("setting_control_disabled_border")
66                }
67                if (gcodeTextArea.hovered || gcodeTextArea.activeFocus)
68                {
69                    return UM.Theme.getColor("setting_control_border_highlight")
70                }
71                return UM.Theme.getColor("setting_control_border")
72            }
73        }
74
75        TextArea
76        {
77            id: gcodeTextArea
78
79            hoverEnabled: true
80            selectByMouse: true
81
82            text: (propertyProvider.properties.value) ? propertyProvider.properties.value : ""
83            font: UM.Theme.getFont("fixed")
84            renderType: Text.NativeRendering
85            color: UM.Theme.getColor("text")
86            wrapMode: TextEdit.NoWrap
87
88            onActiveFocusChanged:
89            {
90                if (!activeFocus)
91                {
92                    propertyProvider.setPropertyValue("value", text)
93                }
94            }
95        }
96    }
97}
98