Skip to content

Commit 348d06a

Browse files
committed
Use status icon component for extruder tab warnings in Cura 4.11
1 parent 4df0d11 commit 348d06a

4 files changed

Lines changed: 189 additions & 2 deletions

File tree

resources/qml/ExtruderTabs411.qml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright (c) 2020 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.4 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 (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+
}
131+
onClicked:
132+
{
133+
Cura.ExtruderManager.setActiveExtruderIndex(tabBar.currentIndex)
134+
}
135+
}
136+
}
137+
138+
//When active extruder changes for some other reason, switch tabs.
139+
//Don't directly link currentIndex to Cura.ExtruderManager.activeExtruderIndex!
140+
//This causes a segfault in Qt 5.11. Something with VisualItemModel removing index -1. We have to use setCurrentIndex instead.
141+
Connections
142+
{
143+
target: Cura.ExtruderManager
144+
onActiveExtruderChanged:
145+
{
146+
tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex);
147+
}
148+
}
149+
150+
//When the model of the extruders is rebuilt, the list of extruders is briefly emptied and rebuilt.
151+
//This causes the currentIndex of the tab to be in an invalid position which resets it to 0.
152+
//Therefore we need to change it back to what it was: The active extruder index.
153+
Connections
154+
{
155+
target: repeater.model
156+
onModelChanged:
157+
{
158+
tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex)
159+
}
160+
}
161+
162+
//When switching back to the stage, make sure the active extruder is selected
163+
Component.onCompleted:
164+
{
165+
tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex)
166+
}
167+
}

resources/qml/PrintSetupSummary.qml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Cura.RoundedRectangle
7272
}
7373
}
7474

75-
ExtruderTabs
75+
Loader
7676
{
7777
id: extruderSummary
7878
enabled: false
@@ -88,6 +88,16 @@ Cura.RoundedRectangle
8888
rightMargin: UM.Theme.getSize("default_margin").width
8989
bottomMargin: UM.Theme.getSize("default_margin").width
9090
}
91+
92+
source:
93+
{
94+
var is411 = (CuraSDKVersion >= "7.7.0");
95+
if(is411) {
96+
return "ExtruderTabs411.qml";
97+
} else {
98+
return "ExtruderTabs40.qml";
99+
}
100+
}
91101
}
92102

93103
Label

resources/qml/SidebarContents.qml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Cura.RoundedRectangle
5555
color: UM.Theme.getColor("lining")
5656
visible: extruderSelector.visible && extruderSelector.enabled
5757
}
58-
ExtruderTabs
58+
Loader
5959
{
6060
id: extruderSelector
6161
enabled:
@@ -77,6 +77,16 @@ Cura.RoundedRectangle
7777
right: showExtruderConfigurationPanel.left
7878
rightMargin: UM.Theme.getSize("default_margin").width + UM.Theme.getSize("default_lining").width
7979
}
80+
81+
source:
82+
{
83+
var is411 = (CuraSDKVersion >= "7.7.0");
84+
if(is411) {
85+
return "ExtruderTabs411.qml";
86+
} else {
87+
return "ExtruderTabs40.qml";
88+
}
89+
}
8090
}
8191

8292
UM.SimpleButton

0 commit comments

Comments
 (0)