Skip to content

Commit cacac20

Browse files
committed
Add initial support for Cura 5.0
1 parent 3fc19c2 commit cacac20

10 files changed

Lines changed: 557 additions & 96 deletions

resources/qml/ExtruderTabs50.qml

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
// Copyright (c) 2021 Aldo Hoeben / fieldOfView
2+
// SidebarGUIPlugin is released under the terms of the AGPLv3 or higher.
3+
4+
import QtQuick 2.7
5+
import QtQuick.Controls 2.3
6+
7+
import UM 1.5 as UM
8+
import Cura 1.1 as Cura
9+
10+
TabRow
11+
{
12+
id: tabBar
13+
14+
property var extrudersModel: CuraApplication.getExtrudersModel()
15+
property bool hasMaterials:
16+
{
17+
if (CuraSDKVersion >= "6.2.0") {
18+
return (Cura.MachineManager.activeMachine != null) ? Cura.MachineManager.activeMachine.hasMaterials : false
19+
} else {
20+
return Cura.MachineManager.hasMaterials
21+
}
22+
}
23+
property bool hasVariants:
24+
{
25+
if (CuraSDKVersion >= "6.2.0") {
26+
return (Cura.MachineManager.activeMachine != null) ? Cura.MachineManager.activeMachine.hasVariants : false
27+
} else {
28+
return Cura.MachineManager.hasVariants
29+
}
30+
}
31+
32+
visible: hasMaterials || hasVariants
33+
width: parent.width
34+
35+
Repeater
36+
{
37+
id: repeater
38+
model: extrudersModel
39+
delegate: TabRowButton
40+
{
41+
contentItem: Item
42+
{
43+
Cura.ExtruderIcon
44+
{
45+
id: extruderIcon
46+
materialColor: model.color
47+
extruderEnabled: model.enabled
48+
49+
anchors.left: parent.left
50+
height: parent.height
51+
width: height
52+
}
53+
54+
// Label for the brand of the material
55+
Label
56+
{
57+
id: typeAndBrandNameLabel
58+
59+
text: model.material_brand + " " + model.material
60+
elide: Text.ElideRight
61+
font: UM.Theme.getFont("default")
62+
color: UM.Theme.getColor("text")
63+
renderType: Text.NativeRendering
64+
65+
visible: hasMaterials
66+
67+
anchors
68+
{
69+
top: extruderIcon.top
70+
left: extruderIcon.right
71+
leftMargin: UM.Theme.getSize("default_margin").width
72+
right: configurationWarning.left
73+
rightMargin: UM.Theme.getSize("default_margin").width
74+
}
75+
}
76+
77+
// Label that shows the name of the variant
78+
Label
79+
{
80+
id: variantLabel
81+
82+
visible: hasVariants
83+
84+
text: model.variant
85+
elide: Text.ElideRight
86+
font: UM.Theme.getFont("default_bold")
87+
color: UM.Theme.getColor("text")
88+
renderType: Text.NativeRendering
89+
90+
anchors
91+
{
92+
left: extruderIcon.right
93+
leftMargin: UM.Theme.getSize("default_margin").width
94+
top: typeAndBrandNameLabel.bottom
95+
}
96+
}
97+
98+
UM.StatusIcon
99+
{
100+
id: configurationWarning
101+
102+
visible: status != UM.StatusIcon.Status.NEUTRAL
103+
height: visible ? UM.Theme.getSize("message_type_icon").height: 0
104+
width: visible ? UM.Theme.getSize("message_type_icon").height : 0
105+
106+
property var extruderStack:
107+
{
108+
return (Cura.MachineManager.activeMachine != null) ? Cura.MachineManager.activeMachine.extruderList[model.index] : undefined;
109+
}
110+
111+
anchors.right: parent.right
112+
anchors.verticalCenter: parent.verticalCenter
113+
114+
status:
115+
{
116+
if (model.enabled && (tabBar.hasMaterials || tabBar.hasVariants))
117+
{
118+
if (extruderStack != undefined && Cura.ContainerManager.getContainerMetaDataEntry(extruderStack.material.id, "compatible", "") != "True")
119+
{
120+
return UM.StatusIcon.Status.ERROR
121+
}
122+
if (!Cura.SidebarGUIPlugin.getExtruderHasQualityForMaterial(extruderStack))
123+
{
124+
return UM.StatusIcon.Status.WARNING
125+
}
126+
}
127+
return UM.StatusIcon.Status.NEUTRAL
128+
}
129+
130+
MouseArea // Connection status tooltip hover area
131+
{
132+
id: tooltipHoverArea
133+
anchors.fill: parent
134+
hoverEnabled: tooltip.text != ""
135+
acceptedButtons: Qt.NoButton // react to hover only, don't steal clicks
136+
137+
onEntered: tooltip.show()
138+
onExited: tooltip.hide()
139+
}
140+
141+
UM.ToolTip
142+
{
143+
id: tooltip
144+
x: 0
145+
y: parent.height + UM.Theme.getSize("default_margin").height
146+
width: UM.Theme.getSize("tooltip").width
147+
targetPoint: Qt.point(Math.round(extruderIcon.width / 2), 0)
148+
text:
149+
{
150+
if (configurationWarning.status == UM.StatusIcon.Status.ERROR)
151+
{
152+
return catalog.i18nc("@tooltip", "The configuration of this extruder is not allowed, and prohibits slicing.")
153+
}
154+
if (configurationWarning.status == UM.StatusIcon.Status.WARNING)
155+
{
156+
return catalog.i18nc("@tooltip", "There are no profiles matching the configuration of this extruder.")
157+
}
158+
return ""
159+
}
160+
}
161+
}
162+
}
163+
onClicked:
164+
{
165+
Cura.ExtruderManager.setActiveExtruderIndex(tabBar.currentIndex)
166+
}
167+
}
168+
}
169+
170+
//When active extruder changes for some other reason, switch tabs.
171+
//Don't directly link currentIndex to Cura.ExtruderManager.activeExtruderIndex!
172+
//This causes a segfault in Qt 5.11. Something with VisualItemModel removing index -1. We have to use setCurrentIndex instead.
173+
Connections
174+
{
175+
target: Cura.ExtruderManager
176+
function onActiveExtruderChanged()
177+
{
178+
tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex);
179+
}
180+
}
181+
182+
//When the model of the extruders is rebuilt, the list of extruders is briefly emptied and rebuilt.
183+
//This causes the currentIndex of the tab to be in an invalid position which resets it to 0.
184+
//Therefore we need to change it back to what it was: The active extruder index.
185+
Connections
186+
{
187+
target: repeater.model
188+
function onModelChanged()
189+
{
190+
tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex)
191+
}
192+
}
193+
194+
//When switching back to the stage, make sure the active extruder is selected
195+
Component.onCompleted:
196+
{
197+
tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex)
198+
}
199+
}

resources/qml/OpenFileButton411.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Button
1515
property var fileProviderModel: CuraApplication.getFileProviderModel()
1616

1717
height: UM.Theme.getSize("button").height
18-
width: height
18+
width: Math.floor(height * 1.125) // Magic number is magic
1919
onClicked:
2020
{
2121
if (fileProviderModel.count <= 1)

0 commit comments

Comments
 (0)