blob: e256e75904ca3c93948533b20d07f7a3949175a6 (
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
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
|
// 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.4
import QtQuick.Layouts 2.7
import UM 1.5 as UM
import Cura 1.7 as Cura
/* This element is a workaround for MacOS, where it can crash in Qt6 when nested menus are closed.
Instead we'll use a pop-up which doesn't seem to have that problem. */
Cura.MenuItem
{
id: materialBrandMenu
overrideShowArrow: true
property var materialTypesModel
text: materialTypesModel.name
contentItem: MouseArea
{
hoverEnabled: true
RowLayout
{
spacing: 0
opacity: materialBrandMenu.enabled ? 1 : 0.5
Item
{
// Spacer
width: UM.Theme.getSize("default_margin").width
}
UM.Label
{
text: replaceText(materialBrandMenu.text)
Layout.fillWidth: true
Layout.fillHeight:true
elide: Label.ElideRight
wrapMode: Text.NoWrap
}
Item
{
Layout.fillWidth: true
}
Item
{
// Right side margin
width: UM.Theme.getSize("default_margin").width
}
}
onEntered: showTimer.restartTimer()
onExited: hideTimer.restartTimer()
}
Timer
{
id: showTimer
interval: 250
function restartTimer()
{
restart();
running = Qt.binding(function() { return materialBrandMenu.enabled && materialBrandMenu.contentItem.containsMouse; });
hideTimer.running = false;
}
onTriggered: menuPopup.open()
}
Timer
{
id: hideTimer
interval: 250
function restartTimer() //Restart but re-evaluate the running property then.
{
restart();
running = Qt.binding(function() { return materialBrandMenu.enabled && !materialBrandMenu.contentItem.containsMouse && !menuPopup.itemHovered > 0; });
showTimer.running = false;
}
onTriggered: menuPopup.close()
}
Popup
{
id: menuPopup
width: materialTypesList.width + padding * 2
height: materialTypesList.height + padding * 2
property var flipped: false
x: parent.width - UM.Theme.getSize("default_lining").width
y: {
// Checks if popup is more than halfway down the screen AND further than 400 down (this avoids popup going off the top of screen)
// If it is then the popup will push up instead of down
// This fixes the popups appearing bellow the bottom of the screen.
if (materialBrandMenu.parent.height / 2 < parent.y && parent.y > 400) {
flipped = true
return -UM.Theme.getSize("default_lining").width - height + UM.Theme.getSize("menu").height
}
flipped = false
return -UM.Theme.getSize("default_lining").width
}
padding: background.border.width
// Nasty hack to ensure that we can keep track if the popup contains the mouse.
// Since we also want a hover for the sub items (and these events are sent async)
// We have to keep a count of itemHovered (instead of just a bool)
property int itemHovered: 0
MouseArea
{
id: submenuArea
anchors.fill: parent
hoverEnabled: true
onEntered: hideTimer.restartTimer()
}
background: Rectangle
{
color: UM.Theme.getColor("main_background")
border.color: UM.Theme.getColor("lining")
border.width: UM.Theme.getSize("default_lining").width
}
Column
{
id: materialTypesList
spacing: 0
property var brandMaterials: materialTypesModel.material_types
Repeater
{
model: parent.brandMaterials
//Use a MouseArea and Rectangle, not a button, because the button grabs mouse events which makes the parent pop-up think it's no longer being hovered.
//With a custom MouseArea, we can prevent the events from being accepted.
delegate: Rectangle
{
id: brandMaterialBase
height: UM.Theme.getSize("menu").height
width: UM.Theme.getSize("menu").width
color: materialTypeButton.containsMouse ? UM.Theme.getColor("background_2") : UM.Theme.getColor("background_1")
property var isFlipped: menuPopup.flipped
RowLayout
{
spacing: 0
opacity: materialBrandMenu.enabled ? 1 : 0.5
height: parent.height
width: parent.width
Item
{
// Spacer
width: UM.Theme.getSize("default_margin").width
}
UM.Label
{
text: model.name
Layout.fillWidth: true
Layout.fillHeight: true
elide: Label.ElideRight
wrapMode: Text.NoWrap
}
Item
{
Layout.fillWidth: true
}
UM.ColorImage
{
height: UM.Theme.getSize("default_arrow").height
width: UM.Theme.getSize("default_arrow").width
color: UM.Theme.getColor("setting_control_text")
source: UM.Theme.getIcon("ChevronSingleRight")
}
Item
{
// Right side margin
width: UM.Theme.getSize("default_margin").width
}
}
MouseArea
{
id: materialTypeButton
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.NoButton
onEntered:
{
menuPopup.itemHovered += 1;
showSubTimer.restartTimer();
}
onExited:
{
menuPopup.itemHovered -= 1;
hideSubTimer.restartTimer();
}
}
Timer
{
id: showSubTimer
interval: 250
function restartTimer()
{
restart();
running = Qt.binding(function() { return materialTypeButton.containsMouse; });
hideSubTimer.running = false;
}
onTriggered: colorPopup.open()
}
Timer
{
id: hideSubTimer
interval: 250
function restartTimer() //Restart but re-evaluate the running property then.
{
restart();
running = Qt.binding(function() { return !materialTypeButton.containsMouse && !colorPopup.itemHovered > 0; });
showSubTimer.running = false;
}
onTriggered: colorPopup.close()
}
Popup
{
id: colorPopup
width: materialColorsList.width + padding * 2
height: materialColorsList.height + padding * 2
x: parent.width
y: {
// If flipped the popup should push up rather than down from the parent
if (brandMaterialBase.isFlipped) {
return -height + UM.Theme.getSize("menu").height + UM.Theme.getSize("default_lining").width
}
return -UM.Theme.getSize("default_lining").width
}
property int itemHovered: 0
padding: background.border.width
background: Rectangle
{
color: UM.Theme.getColor("main_background")
border.color: UM.Theme.getColor("lining")
border.width: UM.Theme.getSize("default_lining").width
}
Column
{
id: materialColorsList
property var brandColors: model.colors
spacing: 0
Repeater
{
model: parent.brandColors
delegate: Rectangle
{
height: UM.Theme.getSize("menu").height
width: UM.Theme.getSize("menu").width
color: materialColorButton.containsMouse ? UM.Theme.getColor("background_2") : UM.Theme.getColor("background_1")
Item
{
opacity: materialBrandMenu.enabled ? 1 : 0.5
anchors.fill: parent
//Checkmark, if the material is selected.
UM.ColorImage
{
id: checkmark
visible: model.id === materialMenu.activeMaterialId
height: UM.Theme.getSize("default_arrow").height
width: height
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width
anchors.verticalCenter: parent.verticalCenter
source: UM.Theme.getIcon("Check", "low")
color: UM.Theme.getColor("setting_control_text")
}
UM.Label
{
text: model.name
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width + UM.Theme.getSize("default_arrow").height
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("default_margin").width
elide: Label.ElideRight
wrapMode: Text.NoWrap
}
}
MouseArea
{
id: materialColorButton
anchors.fill: parent
hoverEnabled: true
onClicked:
{
Cura.MachineManager.setMaterial(extruderIndex, model.container_node);
menuPopup.close();
colorPopup.close();
materialMenu.close();
}
onEntered:
{
menuPopup.itemHovered += 1;
colorPopup.itemHovered += 1;
}
onExited:
{
menuPopup.itemHovered -= 1;
colorPopup.itemHovered -= 1;
}
}
}
}
}
}
}
}
}
}
}
|