blob: bb30cded9fe7eef03b9646d7b353865347bfacc7 (
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
|
// Copyright (c) 2018 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
import QtQuick.Controls 2.3
import UM 1.1 as UM
import Cura 1.0 as Cura
Button
{
id: machineSelectorButton
width: parent.width
height: UM.Theme.getSize("action_button").height
leftPadding: UM.Theme.getSize("thick_margin").width
rightPadding: UM.Theme.getSize("thick_margin").width
checkable: true
hoverEnabled: true
property bool selected: checked
property bool printerTypeLabelAutoFit: false
property var outputDevice: null
property var printerTypesList: []
// Indicates if only to update the printer types list when this button is checked
property bool updatePrinterTypesOnlyWhenChecked: true
property var updatePrinterTypesFunction: updatePrinterTypesList
// This function converts the printer type string to another string.
property var printerTypeLabelConversionFunction: Cura.MachineManager.getAbbreviatedMachineName
function updatePrinterTypesList()
{
var to_update = (updatePrinterTypesOnlyWhenChecked && checked) || !updatePrinterTypesOnlyWhenChecked
printerTypesList = (to_update && outputDevice != null) ? outputDevice.uniquePrinterTypes : []
}
contentItem: Item
{
width: machineSelectorButton.width - machineSelectorButton.leftPadding
height: UM.Theme.getSize("action_button").height
Label
{
id: buttonText
anchors
{
left: parent.left
right: printerTypes.left
verticalCenter: parent.verticalCenter
}
text: machineSelectorButton.text
color: enabled ? UM.Theme.getColor("text") : UM.Theme.getColor("small_button_text")
font: UM.Theme.getFont("medium")
visible: text != ""
renderType: Text.NativeRendering
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
Row
{
id: printerTypes
width: childrenRect.width
anchors
{
right: parent.right
verticalCenter: parent.verticalCenter
}
spacing: UM.Theme.getSize("narrow_margin").width
visible: (updatePrinterTypesOnlyWhenChecked && machineSelectorButton.checked) || !updatePrinterTypesOnlyWhenChecked
Repeater
{
model: printerTypesList
delegate: Cura.PrinterTypeLabel
{
autoFit: printerTypeLabelAutoFit
text: printerTypeLabelConversionFunction(modelData)
}
}
}
}
background: Rectangle
{
id: backgroundRect
color:
{
if (!machineSelectorButton.enabled)
{
return UM.Theme.getColor("action_button_disabled")
}
return machineSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
}
radius: UM.Theme.getSize("action_button_radius").width
border.width: UM.Theme.getSize("default_lining").width
border.color: machineSelectorButton.selected ? UM.Theme.getColor("primary") : "transparent"
}
Connections
{
target: outputDevice
function onUniqueConfigurationsChanged() { updatePrinterTypesFunction() }
}
Connections
{
target: Cura.MachineManager
function onOutputDevicesChanged() { updatePrinterTypesFunction() }
}
Component.onCompleted: updatePrinterTypesFunction()
}
|