Show submenu with material types

It's quite a hassle to get it to keep displaying...

Contributes to issue CURA-8640.
This commit is contained in:
Ghostkeeper 2022-04-08 14:58:39 +02:00
parent 11b557b3d9
commit 3de824e1a4
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A
2 changed files with 62 additions and 5 deletions

View file

@ -16,6 +16,9 @@ Cura.MenuItem
id: materialBrandMenu id: materialBrandMenu
overrideShowArrow: true overrideShowArrow: true
property var materialTypesModel
text: materialTypesModel.name
contentItem: MouseArea contentItem: MouseArea
{ {
hoverEnabled: true hoverEnabled: true
@ -63,7 +66,7 @@ Cura.MenuItem
function restartTimer() function restartTimer()
{ {
restart(); restart();
running = materialBrandMenu.enabled && materialBrandMenu.contentItem.containsMouse; running = Qt.binding(function() { return materialBrandMenu.enabled && materialBrandMenu.contentItem.containsMouse; });
hideTimer.running = false; hideTimer.running = false;
} }
onTriggered: menuPopup.open() onTriggered: menuPopup.open()
@ -75,7 +78,7 @@ Cura.MenuItem
function restartTimer() //Restart but re-evaluate the running property then. function restartTimer() //Restart but re-evaluate the running property then.
{ {
restart(); restart();
running = materialBrandMenu.enabled && !materialBrandMenu.contentItem.containsMouse && !submenuArea.containsMouse; running = Qt.binding(function() { return materialBrandMenu.enabled && !materialBrandMenu.contentItem.containsMouse && !menuPopup.itemHovered > 0; });
showTimer.running = false; showTimer.running = false;
} }
onTriggered: menuPopup.close() onTriggered: menuPopup.close()
@ -86,9 +89,14 @@ Cura.MenuItem
id: menuPopup id: menuPopup
x: parent.width x: parent.width
y: 0 y: 0
width: 100 width: materialTypesList.width + padding * 2
height: 100 height: materialTypesList.height + padding * 2
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 MouseArea
{ {
id: submenuArea id: submenuArea
@ -97,5 +105,54 @@ Cura.MenuItem
hoverEnabled: true hoverEnabled: true
onEntered: hideTimer.restartTimer() 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
Repeater
{
model: materialTypesModel.material_types
//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: Item
{
width: materialTypeLabel.width
height: materialTypeLabel.height
Rectangle
{
width: materialTypesList.width
height: parent.height
color: materialTypeButton.containsMouse ? UM.Theme.getColor("background_2") : UM.Theme.getColor("background_1")
MouseArea
{
id: materialTypeButton
anchors.fill: parent
hoverEnabled: true
onEntered: menuPopup.itemHovered += 1
onExited: menuPopup.itemHovered -= 1
}
}
UM.Label
{
id: materialTypeLabel
text: model.name
}
}
}
}
} }
} }

View file

@ -100,7 +100,7 @@ Cura.Menu
model: brandModel model: brandModel
delegate: Cura.MaterialBrandMenu delegate: Cura.MaterialBrandMenu
{ {
text: model.name materialTypesModel: model
} }
onObjectAdded: function(index, object) { materialMenu.insertItem(index + 4, object)} onObjectAdded: function(index, object) { materialMenu.insertItem(index + 4, object)}
onObjectRemoved: function(object) { materialMenu.removeItem(index) } onObjectRemoved: function(object) { materialMenu.removeItem(index) }