Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SettingItem.qml « Settings « qml « resources - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 228de4a9d6bac85c174044d0169a08ab9b0326a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
// Copyright (c) 2018 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.

import QtQuick 2.7
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.0

import UM 1.5 as UM
import Cura 1.0 as Cura

import "."

Item
{
    id: base
    height: enabled ? UM.Theme.getSize("section").height + UM.Theme.getSize("narrow_margin").height : 0
    anchors.left: parent.left
    anchors.right: parent.right

    property alias contents: controlContainer.children
    property alias hovered: mouse.containsMouse

    property bool showRevertButton: true
    property bool showInheritButton: true
    property bool showLinkedSettingIcon: true
    property bool doDepthIndentation: true
    property bool doQualityUserSettingEmphasis: true
    property var settingKey: definition.key //Used to detect each individual setting more easily in Squish GUI tests.

    // Create properties to put property provider stuff in (bindings break in qt 5.5.1 otherwise)
    property var state: propertyProvider.properties.state
    property var resolve: propertyProvider.properties.resolve
    property var stackLevels: propertyProvider.stackLevels
    property var stackLevel: stackLevels[0]
    // A list of stack levels that will trigger to show the revert button
    property var showRevertStackLevels: [0]
    property bool resetButtonVisible: {
        var is_revert_stack_level = false;
        for (var i in base.showRevertStackLevels)
        {
            if (base.stackLevel == i)
            {
                is_revert_stack_level = true
                break
            }
        }
        return is_revert_stack_level && base.showRevertButton
    }

    signal focusReceived()
    signal setActiveFocusToNextSetting(bool forward)
    signal contextMenuRequested()
    signal showTooltip(string text)
    signal hideTooltip()
    signal showAllHiddenInheritedSettings(string category_id)

    function createTooltipText()
    {
        var affects = settingDefinitionsModel.getRequiredBy(definition.key, "value")
        var affected_by = settingDefinitionsModel.getRequires(definition.key, "value")

        var affected_by_list = ""
        for (var i in affected_by)
        {
            if(affected_by[i].label != "")
            {
                affected_by_list += "<li>%1</li>\n".arg(affected_by[i].label)
            }
        }

        var affects_list = ""
        for (var i in affects)
        {
            if(affects[i].label != "")
            {
                affects_list += "<li>%1</li>\n".arg(affects[i].label)
            }
        }

        var tooltip = "<b>%1</b>\n<p>%2</p>".arg(definition.label).arg(definition.description)

        if(!propertyProvider.isValueUsed)
        {
            tooltip += "<i>%1</i><br/><br/>".arg(catalog.i18nc("@label", "This setting is not used because all the settings that it influences are overridden."))
        }

        if (affects_list != "")
        {
            tooltip += "<b>%1</b><ul>%2</ul>".arg(catalog.i18nc("@label Header for list of settings.", "Affects")).arg(affects_list)
        }

        if (affected_by_list != "")
        {
            tooltip += "<b>%1</b><ul>%2</ul>".arg(catalog.i18nc("@label Header for list of settings.", "Affected By")).arg(affected_by_list)
        }

        return tooltip
    }

    MouseArea
    {
        id: mouse

        anchors.fill: parent

        acceptedButtons: Qt.RightButton
        hoverEnabled: true;

        onClicked: base.contextMenuRequested()

        onEntered:
        {
            hoverTimer.start()
        }

        onExited:
        {
            if (controlContainer.item && controlContainer.item.hovered)
            {
                return
            }
            hoverTimer.stop()
            base.hideTooltip()
        }

        Timer
        {
            id: hoverTimer
            interval: 500
            repeat: false

            onTriggered:
            {
                base.showTooltip(base.createTooltipText())
            }
        }

        UM.Label
        {
            id: label

            anchors.left: parent.left
            anchors.leftMargin: doDepthIndentation ? Math.round(UM.Theme.getSize("thin_margin").width + ((definition.depth - 1) * UM.Theme.getSize("default_margin").width)) : 0
            anchors.right: settingControls.left
            anchors.verticalCenter: parent.verticalCenter

            text: definition.label
            elide: Text.ElideMiddle
            textFormat: Text.PlainText

            color: UM.Theme.getColor("setting_control_text")
            opacity: (definition.visible) ? 1 : 0.5
            // emphasize the setting if it has a value in the user or quality profile
            font: base.doQualityUserSettingEmphasis && base.stackLevel !== undefined && base.stackLevel <= 1 ? UM.Theme.getFont("default_italic") : UM.Theme.getFont("default")
        }

        Row
        {
            id: settingControls

            height: UM.Theme.getSize("small_button_icon").height
            spacing: Math.round(UM.Theme.getSize("thick_margin").height / 2)

            anchors
            {
                right: controlContainer.left
                rightMargin: Math.round(UM.Theme.getSize("thick_margin").width / 2)
                verticalCenter: parent.verticalCenter
            }

            UM.SimpleButton
            {
                id: linkedSettingIcon;

                visible: (!definition.settable_per_extruder || String(globalPropertyProvider.properties.limit_to_extruder) != "-1") && base.showLinkedSettingIcon

                anchors.top: parent.top
                anchors.bottom: parent.bottom
                height: UM.Theme.getSize("small_button_icon").height
                width: height

                color: UM.Theme.getColor("setting_control_button")
                hoverColor: UM.Theme.getColor("setting_control_button")

                iconSource: UM.Theme.getIcon("Link")

                onEntered:
                {
                    hoverTimer.stop()
                    var tooltipText = catalog.i18nc("@label", "This setting is always shared between all extruders. Changing it here will change the value for all extruders.")
                    if ((resolve !== "None") && (stackLevel !== 0))
                    {
                        // We come here if a setting has a resolve and the setting is not manually edited.
                        tooltipText += " " + catalog.i18nc("@label", "This setting is resolved from conflicting extruder-specific values:") + " [" + Cura.ExtruderManager.getInstanceExtruderValues(definition.key) + "]."
                    }
                    base.showTooltip(tooltipText)
                }
                onExited: base.showTooltip(base.createTooltipText())
            }

            UM.SimpleButton
            {
                id: revertButton

                visible: base.resetButtonVisible

                anchors.top: parent.top
                anchors.bottom: parent.bottom
                height: UM.Theme.getSize("small_button_icon").height
                width: height

                color: UM.Theme.getColor("setting_control_button")
                hoverColor: UM.Theme.getColor("setting_control_button_hover")

                iconSource: UM.Theme.getIcon("ArrowReset")

                onClicked:
                {
                    revertButton.focus = true

                    if (externalResetHandler)
                    {
                        externalResetHandler(propertyProvider.key)
                    }
                    else
                    {
                        Cura.MachineManager.clearUserSettingAllCurrentStacks(propertyProvider.key)
                    }
                }

                onEntered:
                {
                    hoverTimer.stop()
                    base.showTooltip(catalog.i18nc("@label", "This setting has a value that is different from the profile.\n\nClick to restore the value of the profile."))
                }
                onExited: base.showTooltip(base.createTooltipText())
            }

            UM.SimpleButton
            {
                // This button shows when the setting has an inherited function, but is overridden by profile.
                id: inheritButton
                // Inherit button needs to be visible if;
                // - User made changes that override any loaded settings
                // - This setting item uses inherit button at all
                // - The type of the value of any deeper container is an "object" (eg; is a function)
                visible:
                {
                    if (!base.showInheritButton)
                    {
                        return false
                    }

                    if (!propertyProvider.properties.enabled)
                    {
                        // Note: This is not strictly necessary since a disabled setting is hidden anyway.
                        // But this will cause the binding to be re-evaluated when the enabled property changes.
                        return false
                    }

                    // There are no settings with any warning.
                    if (Cura.SettingInheritanceManager.settingsWithInheritanceWarning.length === 0)
                    {
                        return false
                    }

                    // This setting has a resolve value, so an inheritance warning doesn't do anything.
                    if (resolve !== "None")
                    {
                        return false
                    }

                    // If the setting does not have a limit_to_extruder property (or is -1), use the active stack.
                    if (globalPropertyProvider.properties.limit_to_extruder === null || globalPropertyProvider.properties.limit_to_extruder === "-1")
                    {
                        return Cura.SettingInheritanceManager.settingsWithInheritanceWarning.indexOf(definition.key) >= 0
                    }

                    // Setting does have a limit_to_extruder property, so use that one instead.
                    if (definition.key === undefined) {
                        // Observed when loading workspace, probably when SettingItems are removed.
                        return false
                    }
                    if(globalPropertyProvider.properties.limit_to_extruder === undefined)
                    {
                        return false
                    }
                    return Cura.SettingInheritanceManager.hasOverrides(definition.key, globalPropertyProvider.properties.limit_to_extruder)
                }

                anchors.top: parent.top
                anchors.bottom: parent.bottom
                height: UM.Theme.getSize("small_button_icon").height
                width: height

                onClicked:
                {
                    focus = true

                    // Get the most shallow function value (eg not a number) that we can find.
                    var last_entry = propertyProvider.stackLevels[propertyProvider.stackLevels.length - 1]
                    for (var i = 1; i < base.stackLevels.length; i++)
                    {
                        var has_setting_function = typeof(propertyProvider.getPropertyValue("value", base.stackLevels[i])) == "object"
                        if(has_setting_function)
                        {
                            last_entry = propertyProvider.stackLevels[i]
                            break
                        }
                    }
                    if ((last_entry === 4 || last_entry === 11) && base.stackLevel === 0 && base.stackLevels.length === 2)
                    {
                        // Special case of the inherit reset. If only the definition (4th or 11th) container) and the first
                        // entry (user container) are set, we can simply remove the container.
                        propertyProvider.removeFromContainer(0)
                    }
                    else
                    {
                        // Put that entry into the "top" instance container.
                        // This ensures that the value in any of the deeper containers need not be removed, which is
                        // needed for the reset button (which deletes the top value) to correctly go back to profile
                        // defaults.
                        propertyProvider.setPropertyValue("value", propertyProvider.getPropertyValue("value", last_entry))
                        propertyProvider.setPropertyValue("state", "InstanceState.Calculated")

                    }
                }

                color: UM.Theme.getColor("setting_control_button")
                hoverColor: UM.Theme.getColor("setting_control_button_hover")

                iconSource: UM.Theme.getIcon("Function")

                onEntered: { hoverTimer.stop(); base.showTooltip(catalog.i18nc("@label", "This setting is normally calculated, but it currently has an absolute value set.\n\nClick to restore the calculated value.")) }
                onExited: base.showTooltip(base.createTooltipText())
            }
        }

        Item
        {
            id: controlContainer

            enabled: propertyProvider.isValueUsed

            anchors.right: parent.right
            anchors.verticalCenter: parent.verticalCenter
            width: UM.Theme.getSize("setting_control").width
            height: UM.Theme.getSize("setting_control").height
        }
    }
}