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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
// Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7
import QtQuick.Controls 2.1
import UM 1.5 as UM
import Cura 1.0 as Cura
import "../Menus"
Item
{
id: settingsView
property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel()
property bool findingSettings
Item
{
id: filterContainer
anchors
{
top: parent.top
left: parent.left
right: settingVisibilityMenu.left
}
height: UM.Theme.getSize("print_setup_big_item").height
Timer
{
id: settingsSearchTimer
onTriggered: filter.editingFinished()
interval: 500
running: false
repeat: false
}
Cura.TextField
{
id: filter
height: parent.height
anchors.left: parent.left
anchors.right: parent.right
topPadding: height / 4
leftPadding: searchIcon.width + UM.Theme.getSize("default_margin").width * 2
placeholderText: catalog.i18nc("@label:textbox", "Search settings")
font.italic: true
property var expandedCategories
property bool lastFindingSettings: false
UM.ColorImage
{
id: searchIcon
anchors
{
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: UM.Theme.getSize("default_margin").width
}
source: UM.Theme.getIcon("Magnifier")
height: UM.Theme.getSize("small_button_icon").height
width: height
color: UM.Theme.getColor("text")
}
onTextChanged: settingsSearchTimer.restart()
onEditingFinished:
{
definitionsModel.filter = {"i18n_label|i18n_description" : "*" + text}
findingSettings = (text.length > 0)
if (findingSettings != lastFindingSettings)
{
updateDefinitionModel()
lastFindingSettings = findingSettings
}
}
Keys.onEscapePressed: filter.text = ""
function updateDefinitionModel()
{
if (findingSettings)
{
expandedCategories = definitionsModel.expanded.slice()
definitionsModel.expanded = [""] // keep categories closed while to prevent render while making settings visible one by one
definitionsModel.showAncestors = true
definitionsModel.showAll = true
definitionsModel.expanded = ["*"]
}
else
{
if (expandedCategories)
{
definitionsModel.expanded = expandedCategories
}
definitionsModel.showAncestors = false
definitionsModel.showAll = false
}
}
}
UM.SimpleButton
{
id: clearFilterButton
iconSource: UM.Theme.getIcon("Cancel")
visible: findingSettings
height: Math.round(parent.height * 0.4)
width: visible ? height : 0
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("default_margin").width
color: UM.Theme.getColor("setting_control_button")
hoverColor: UM.Theme.getColor("setting_control_button_hover")
onClicked:
{
filter.text = ""
filter.forceActiveFocus()
}
}
}
SettingVisibilityPresetsMenu
{
id: settingVisibilityPresetsMenu
onCollapseAllCategories:
{
settingsSearchTimer.stop()
filter.text = "" // clear search field
filter.editingFinished()
definitionsModel.collapseAllCategories()
}
}
UM.BurgerButton
{
id: settingVisibilityMenu
anchors
{
verticalCenter: filterContainer.verticalCenter
right: parent.right
}
onClicked:
{
settingVisibilityPresetsMenu.popup(
popupContainer,
-settingVisibilityPresetsMenu.width + UM.Theme.getSize("default_margin").width,
settingVisibilityMenu.height
)
}
}
Item
{
// Work around to prevent the buttom from being rescaled if a popup is attached
id: popupContainer
anchors.bottom: settingVisibilityMenu.bottom
anchors.right: settingVisibilityMenu.right
}
// Mouse area that gathers the scroll events to not propagate it to the main view.
MouseArea
{
anchors.fill: contents
acceptedButtons: Qt.AllButtons
onWheel: (wheel) => { wheel.accepted = true }
}
ListView
{
id: contents
maximumFlickVelocity: 1000 * screenScaleFactor
anchors
{
top: filterContainer.bottom
topMargin: UM.Theme.getSize("default_margin").height
bottom: parent.bottom
right: parent.right
left: parent.left
}
clip: true
cacheBuffer: 1000000 // Set a large cache to effectively just cache every list item.
ScrollBar.vertical: UM.ScrollBar
{
id: scrollBar
onPositionChanged: {
// This removes focus from items when scrolling.
// This fixes comboboxes staying open and scrolling container
if (!activeFocus && !filter.activeFocus) {
forceActiveFocus();
}
}
}
model: UM.SettingDefinitionsModel
{
id: definitionsModel
containerId: Cura.MachineManager.activeMachine !== null ? Cura.MachineManager.activeMachine.definition.id: ""
visibilityHandler: UM.SettingPreferenceVisibilityHandler { }
exclude: ["machine_settings", "command_line_settings", "infill_mesh", "infill_mesh_order", "cutting_mesh", "support_mesh", "anti_overhang_mesh"] // TODO: infill_mesh settings are excluded hardcoded, but should be based on the fact that settable_globally, settable_per_meshgroup and settable_per_extruder are false.
expanded: CuraApplication.expandedCategories
onExpandedChanged:
{
if (!findingSettings)
{
// Do not change expandedCategories preference while filtering settings
// because all categories are expanded while filtering
CuraApplication.setExpandedCategories(expanded)
}
}
onVisibilityChanged: Cura.SettingInheritanceManager.scheduleUpdate()
}
property int indexWithFocus: -1
property string activeMachineId: Cura.MachineManager.activeMachine !== null ? Cura.MachineManager.activeMachine.id : ""
delegate: Loader
{
id: delegate
width: contents.width - (scrollBar.width + UM.Theme.getSize("narrow_margin").width)
opacity: enabled ? 1 : 0
enabled: provider.properties.enabled === "True"
property var definition: model
property var settingDefinitionsModel: definitionsModel
property var propertyProvider: provider
property var globalPropertyProvider: inheritStackProvider
property bool externalResetHandler: false
//Qt5.4.2 and earlier has a bug where this causes a crash: https://bugreports.qt.io/browse/QTBUG-35989
//In addition, while it works for 5.5 and higher, the ordering of the actual combo box drop down changes,
//causing nasty issues when selecting different options. So disable asynchronous loading of enum type completely.
asynchronous: model.type !== "enum" && model.type !== "extruder" && model.type !== "optional_extruder"
active: model.type !== undefined
source:
{
switch(model.type)
{
case "int":
return "SettingTextField.qml"
case "[int]":
return "SettingTextField.qml"
case "float":
return "SettingTextField.qml"
case "enum":
return "SettingComboBox.qml"
case "extruder":
return "SettingExtruder.qml"
case "bool":
return "SettingCheckBox.qml"
case "str":
return "SettingTextField.qml"
case "category":
return "SettingCategory.qml"
case "optional_extruder":
return "SettingOptionalExtruder.qml"
default:
return "SettingUnknown.qml"
}
}
// Binding to ensure that the right containerstack ID is set for the provider.
// This ensures that if a setting has a limit_to_extruder id (for instance; Support speed points to the
// extruder that actually prints the support, as that is the setting we need to use to calculate the value)
Binding
{
target: provider
property: "containerStackId"
when: model.settable_per_extruder || (inheritStackProvider.properties.limit_to_extruder !== undefined && inheritStackProvider.properties.limit_to_extruder >= 0);
value:
{
// Associate this binding with Cura.MachineManager.activeMachine.id in the beginning so this
// binding will be triggered when activeMachineId is changed too.
// Otherwise, if this value only depends on the extruderIds, it won't get updated when the
// machine gets changed.
if (!model.settable_per_extruder)
{
//Not settable per extruder or there only is global, so we must pick global.
return contents.activeMachineId
}
if (inheritStackProvider.properties.limit_to_extruder !== undefined && inheritStackProvider.properties.limit_to_extruder >= 0)
{
//We have limit_to_extruder, so pick that stack.
return Cura.ExtruderManager.extruderIds[inheritStackProvider.properties.limit_to_extruder]
}
if (Cura.ExtruderManager.activeExtruderStackId)
{
//We're on an extruder tab. Pick the current extruder.
return Cura.ExtruderManager.activeExtruderStackId
}
//No extruder tab is selected. Pick the global stack. Shouldn't happen any more since we removed the global tab.
return contents.activeMachineId
}
}
// Specialty provider that only watches global_inherits (we can't filter on what property changed we get events
// so we bypass that to make a dedicated provider).
UM.SettingPropertyProvider
{
id: inheritStackProvider
containerStackId: contents.activeMachineId
key: model.key
watchedProperties: [ "limit_to_extruder" ]
}
UM.SettingPropertyProvider
{
id: provider
containerStackId: contents.activeMachineId
key: model.key
watchedProperties: [ "value", "enabled", "state", "validationState", "settable_per_extruder", "resolve" ]
storeIndex: 0
removeUnusedValue: model.resolve === undefined
}
Connections
{
target: item
function onContextMenuRequested()
{
contextMenu.key = model.key
contextMenu.settingVisible = model.visible
contextMenu.provider = provider
contextMenu.popup() //iconName: model.icon_name
}
function onShowTooltip(text) { base.showTooltip(delegate, Qt.point(-settingsView.x - UM.Theme.getSize("default_margin").width, 0), text) }
function onHideTooltip() { base.hideTooltip() }
function onShowAllHiddenInheritedSettings()
{
var children_with_override = Cura.SettingInheritanceManager.getChildrenKeysWithOverride(category_id)
for(var i = 0; i < children_with_override.length; i++)
{
definitionsModel.setVisible(children_with_override[i], true)
}
Cura.SettingInheritanceManager.manualRemoveOverride(category_id)
}
function onFocusReceived()
{
contents.indexWithFocus = index
contents.positionViewAtIndex(index, ListView.Contain)
}
function onSetActiveFocusToNextSetting(forward)
{
if (forward == undefined || forward)
{
contents.currentIndex = contents.indexWithFocus + 1
while(contents.currentItem && contents.currentItem.height <= 0)
{
contents.currentIndex++
}
if (contents.currentItem)
{
contents.currentItem.item.focusItem.forceActiveFocus()
}
}
else
{
contents.currentIndex = contents.indexWithFocus - 1
while(contents.currentItem && contents.currentItem.height <= 0)
{
contents.currentIndex--
}
if (contents.currentItem)
{
contents.currentItem.item.focusItem.forceActiveFocus()
}
}
}
}
}
Cura.Menu
{
id: contextMenu
property string key
property var provider
property bool settingVisible
Cura.MenuItem
{
//: Settings context menu action
text: catalog.i18nc("@action:menu", "Copy value to all extruders")
visible: machineExtruderCount.properties.value > 1
enabled: contextMenu.provider !== undefined && contextMenu.provider.properties.settable_per_extruder !== "False"
onTriggered: Cura.MachineManager.copyValueToExtruders(contextMenu.key)
}
Cura.MenuItem
{
//: Settings context menu action
text: catalog.i18nc("@action:menu", "Copy all changed values to all extruders")
visible: machineExtruderCount.properties.value > 1
enabled: contextMenu.provider !== undefined
onTriggered: Cura.MachineManager.copyAllValuesToExtruders()
}
Cura.MenuSeparator
{
visible: machineExtruderCount.properties.value > 1
}
Instantiator
{
id: customMenuItems
model: Cura.SidebarCustomMenuItemsModel { }
Cura.MenuItem
{
text: model.name
onTriggered:
{
customMenuItems.model.callMenuItemMethod(name, model.actions, {"key": contextMenu.key})
}
}
onObjectAdded: contextMenu.insertItem(index, object)
onObjectRemoved: contextMenu.removeItem(object)
}
Cura.MenuSeparator
{
visible: customMenuItems.count > 0
}
Cura.MenuItem
{
//: Settings context menu action
visible: !findingSettings
text: catalog.i18nc("@action:menu", "Hide this setting")
onTriggered:
{
definitionsModel.hide(contextMenu.key)
}
}
Cura.MenuItem
{
//: Settings context menu action
text:
{
if (contextMenu.settingVisible)
{
return catalog.i18nc("@action:menu", "Don't show this setting")
}
else
{
return catalog.i18nc("@action:menu", "Keep this setting visible")
}
}
visible: findingSettings
onTriggered:
{
if (contextMenu.settingVisible)
{
definitionsModel.hide(contextMenu.key)
}
else
{
definitionsModel.show(contextMenu.key)
}
}
}
Cura.MenuItem
{
//: Settings context menu action
text: catalog.i18nc("@action:menu", "Configure setting visibility...")
onTriggered: Cura.Actions.configureSettingVisibility.trigger(contextMenu)
}
}
UM.SettingPropertyProvider
{
id: machineExtruderCount
containerStackId: Cura.MachineManager.activeMachine !== null ? Cura.MachineManager.activeMachine.id : ""
key: "machine_extruder_count"
watchedProperties: [ "value" ]
storeIndex: 0
}
}
}
|