Skip to content

Commit 0d850fc

Browse files
committed
Fix compatibility with Qt6 and Cura 5
1 parent 489f316 commit 0d850fc

9 files changed

Lines changed: 707 additions & 34 deletions

SidebarGUIProxy.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,20 @@ def checkRectangleOnScreen(self, rectangle):
9696
# Check if rectangle is not outside the currently available screens
9797
application = Application.getInstance()
9898
screen_found = False
99-
for screen_number in range(0, application.desktop().screenCount()):
100-
if rectangle.intersects(
101-
QRectF(application.desktop().availableGeometry(screen_number))
102-
):
103-
screen_found = True
104-
break
99+
try:
100+
# Qt6, Cura 5.0 and later
101+
for screen in application.screens():
102+
if rectangle.intersects(QRectF(screen.availableGeometry())):
103+
screen_found = True
104+
break
105+
except AttributeError:
106+
# Qt5, Cura 4.13 and before
107+
for screen_number in range(0, application.desktop().screenCount()):
108+
if rectangle.intersects(
109+
QRectF(application.desktop().availableGeometry(screen_number))
110+
):
111+
screen_found = True
112+
break
105113
if not screen_found:
106114
return False
107115
return True

resources/qml/ExtruderTabs50.qml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ TabRow
3131

3232
visible: hasMaterials || hasVariants
3333
width: parent.width
34+
height: UM.Theme.getSize("extruder_icon").height + UM.Theme.getSize("narrow_margin").height
35+
36+
property int extrudersCount: extrudersModel.count
3437

3538
Repeater
3639
{
3740
id: repeater
3841
model: extrudersModel
3942
delegate: TabRowButton
4043
{
44+
width: Math.floor((tabBar.width - (extrudersCount - 1) * UM.Theme.getSize("narrow_margin").width) / extrudersCount)
4145
contentItem: Item
4246
{
4347
Cura.ExtruderIcon
@@ -52,7 +56,7 @@ TabRow
5256
}
5357

5458
// Label for the brand of the material
55-
Label
59+
UM.Label
5660
{
5761
id: typeAndBrandNameLabel
5862

@@ -75,7 +79,7 @@ TabRow
7579
}
7680

7781
// Label that shows the name of the variant
78-
Label
82+
UM.Label
7983
{
8084
id: variantLabel
8185

@@ -115,7 +119,7 @@ TabRow
115119
{
116120
if (model.enabled && (tabBar.hasMaterials || tabBar.hasVariants))
117121
{
118-
if (extruderStack != undefined && Cura.ContainerManager.getContainerMetaDataEntry(extruderStack.material.id, "compatible", "") != "True")
122+
if (extruderStack != undefined && Cura.ContainerManager.getContainerMetaDataEntry(extruderStack.material.id, "compatible") != "True")
119123
{
120124
return UM.StatusIcon.Status.ERROR
121125
}

resources/qml/OpenFileButton50.qml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// Copyright (c) 2022 Aldo Hoeben / fieldOfView
2+
// SidebarGUIPlugin is released under the terms of the AGPLv3 or higher.
3+
4+
import QtQuick 2.9
5+
import QtQuick.Layouts 1.1
6+
import QtQuick.Controls 2.3
7+
8+
import UM 1.3 as UM
9+
import Cura 1.1 as Cura
10+
11+
Button
12+
{
13+
id: openFileButton
14+
15+
property var fileProviderModel: CuraApplication.getFileProviderModel()
16+
17+
height: UM.Theme.getSize("button").height
18+
width: height
19+
x: -4 * UM.Theme.getSize("default_lining").width
20+
onClicked:
21+
{
22+
if (fileProviderModel.count <= 1)
23+
{
24+
Cura.Actions.open.trigger()
25+
}
26+
else
27+
{
28+
toggleContent()
29+
}
30+
}
31+
function toggleContent()
32+
{
33+
if (openFileButtonMenu.visible)
34+
{
35+
openFileButtonMenu.close()
36+
}
37+
else
38+
{
39+
openFileButtonMenu.open()
40+
}
41+
}
42+
43+
hoverEnabled: true
44+
45+
contentItem: Rectangle
46+
{
47+
anchors.left: parent.left
48+
anchors.leftMargin: UM.Theme.getSize("thin_margin").width
49+
50+
opacity: parent.enabled ? 1.0 : 0.2
51+
radius: Math.round(width * 0.5)
52+
53+
color:
54+
{
55+
if(parent.hovered)
56+
{
57+
return UM.Theme.getColor("toolbar_button_hover")
58+
}
59+
return UM.Theme.getColor("toolbar_background")
60+
}
61+
62+
UM.ColorImage
63+
{
64+
id: buttonIcon
65+
anchors.centerIn: parent
66+
width: height
67+
height: parent.height - UM.Theme.getSize("default_margin").height
68+
source: UM.Theme.getIcon("Folder", "medium")
69+
color: UM.Theme.getColor("icon")
70+
}
71+
72+
UM.ColorImage
73+
{
74+
anchors
75+
{
76+
right: parent.right
77+
rightMargin: -4 * UM.Theme.getSize("default_lining").width
78+
bottom: parent.bottom
79+
bottomMargin: -2 * UM.Theme.getSize("default_lining").height
80+
}
81+
source: UM.Theme.getIcon("ChevronSingleDown")
82+
visible: fileProviderModel.count > 1
83+
width: UM.Theme.getSize("standard_arrow").width
84+
height: UM.Theme.getSize("standard_arrow").height
85+
color: UM.Theme.getColor("icon")
86+
}
87+
}
88+
89+
background: Cura.RoundedRectangle
90+
{
91+
id: buttonBackground
92+
height: UM.Theme.getSize("button").height
93+
width: UM.Theme.getSize("button").width + UM.Theme.getSize("narrow_margin").width
94+
95+
radius: UM.Theme.getSize("default_radius").width
96+
cornerSide: Cura.RoundedRectangle.Direction.Right
97+
98+
color: UM.Theme.getColor("toolbar_background")
99+
border.width: UM.Theme.getSize("default_lining").width
100+
border.color: UM.Theme.getColor("lining")
101+
}
102+
103+
Popup
104+
{
105+
id: openFileButtonMenu
106+
107+
// Make the content aligned with the rest, using the property contentAlignment to decide whether is right or left.
108+
// In case of right alignment, the 3x padding is due to left, right and padding between the button & text.
109+
y: buttonBackground.height + 2 * UM.Theme.getSize("default_lining").height
110+
padding: UM.Theme.getSize("default_margin").width
111+
closePolicy: Popup.CloseOnPressOutsideParent
112+
113+
background: Cura.RoundedRectangle
114+
{
115+
cornerSide: Cura.RoundedRectangle.Direction.All
116+
color: UM.Theme.getColor("action_button")
117+
border.width: UM.Theme.getSize("default_lining").width
118+
border.color: UM.Theme.getColor("lining")
119+
radius: UM.Theme.getSize("default_radius").width
120+
}
121+
122+
contentItem: Item
123+
{
124+
id: popup
125+
126+
Column
127+
{
128+
id: openProviderColumn
129+
130+
//The column doesn't automatically listen to its children rect if the children change internally, so we need to explicitly update the size.
131+
onChildrenRectChanged:
132+
{
133+
popup.height = childrenRect.height
134+
popup.width = childrenRect.width
135+
}
136+
onPositioningComplete:
137+
{
138+
popup.height = childrenRect.height
139+
popup.width = childrenRect.width
140+
}
141+
142+
Repeater
143+
{
144+
model: openFileButton.fileProviderModel
145+
delegate: Button
146+
{
147+
leftPadding: UM.Theme.getSize("default_margin").width
148+
rightPadding: UM.Theme.getSize("default_margin").width
149+
width: contentItem.width + leftPadding + rightPadding
150+
height: UM.Theme.getSize("action_button").height
151+
hoverEnabled: true
152+
153+
contentItem: Label
154+
{
155+
text: model.displayText
156+
color: UM.Theme.getColor("text")
157+
font: UM.Theme.getFont("medium")
158+
renderType: Text.NativeRendering
159+
verticalAlignment: Text.AlignVCenter
160+
161+
width: contentWidth
162+
height: parent.height
163+
}
164+
165+
onClicked:
166+
{
167+
if(model.index == 0) //The 0th element is the "From Disk" option, which should activate the open local file dialog.
168+
{
169+
Cura.Actions.open.trigger();
170+
}
171+
else
172+
{
173+
openFileButton.fileProviderModel.trigger(model.name);
174+
}
175+
openFileButton.toggleContent();
176+
}
177+
178+
background: Rectangle
179+
{
180+
color: parent.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
181+
radius: UM.Theme.getSize("action_button_radius").width
182+
width: popup.width
183+
}
184+
}
185+
}
186+
}
187+
}
188+
}
189+
}

resources/qml/PrepareStageLegend50.qml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import QtQuick 2.7
55
import QtQuick.Controls 2.3
6-
7-
import QtGraphicalEffects 1.0 // for the linear gradient
6+
import QtQuick.Shapes 1.2
87

98
import UM 1.5 as UM
109
import Cura 1.0 as Cura
@@ -132,21 +131,22 @@ Cura.ExpandableComponent
132131

133132
Rectangle
134133
{
134+
id: outsideBuildVolumeSwatch
135135
anchors.verticalCenter: parent.verticalCenter
136136
anchors.right: parent.right
137137

138138
width: UM.Theme.getSize("layerview_legend_size").width
139139
height: UM.Theme.getSize("layerview_legend_size").height
140+
clip: true
140141

141142
border.width: UM.Theme.getSize("default_lining").width
142143
border.color: UM.Theme.getColor("lining")
143144

144-
LinearGradient
145+
Rectangle
145146
{
146147
anchors.fill: parent
147-
anchors.margins: UM.Theme.getSize("default_lining").width
148-
start: Qt.point(0, 0)
149-
end: Qt.point(width, height)
148+
scale: Math.sqrt(2)
149+
rotation: 45
150150
gradient: Gradient
151151
{
152152
GradientStop { position: 0.5; color: UM.Theme.getColor("model_unslicable") }
@@ -176,17 +176,10 @@ Cura.ExpandableComponent
176176
border.width: UM.Theme.getSize("default_lining").width
177177
border.color: UM.Theme.getColor("lining")
178178

179-
LinearGradient
179+
gradient: LinearGradient
180180
{
181-
anchors.fill: parent
182-
anchors.margins: UM.Theme.getSize("default_lining").width
183-
start: Qt.point(0, 0)
184-
end: Qt.point(width, 0)
185-
gradient: Gradient
186-
{
187-
GradientStop { position: 0.0; color: UM.Theme.getColor("xray") }
188-
GradientStop { position: 1.0; color: "white" }
189-
}
181+
GradientStop { position: 0.0; color: UM.Theme.getColor("xray") }
182+
GradientStop { position: 1.0; color: "white" }
190183
}
191184
}
192185
}
@@ -208,7 +201,7 @@ Cura.ExpandableComponent
208201
width: UM.Theme.getSize("layerview_legend_size").width
209202
height: UM.Theme.getSize("layerview_legend_size").height
210203

211-
color: UM.Theme.getColor("xray_error")
204+
color: UM.Theme.getColor("error_area")
212205

213206
border.width: UM.Theme.getSize("default_lining").width
214207
border.color: UM.Theme.getColor("lining")

0 commit comments

Comments
 (0)