Implement sub-submenus for material selection

Getting a bit complex with the timers there and which pop-ups need to stay open. But it seems to be working reliably now.

Contributes to issue CURA-8640.
This commit is contained in:
Ghostkeeper 2022-04-08 15:57:32 +02:00
parent b40900e146
commit 7aafd95429
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -118,9 +118,11 @@ Cura.MenuItem
id: materialTypesList
spacing: 0
property var brandMaterials: materialTypesModel.material_types
Repeater
{
model: materialTypesModel.material_types
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.
@ -131,15 +133,6 @@ Cura.MenuItem
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
}
RowLayout
{
spacing: 0
@ -172,6 +165,138 @@ Cura.MenuItem
width: UM.Theme.getSize("default_margin").width
}
}
MouseArea
{
id: materialTypeButton
anchors.fill: parent
hoverEnabled: true
onEntered:
{
menuPopup.itemHovered += 1;
showSubTimer.restartTimer();
}
onExited:
{
menuPopup.itemHovered -= 1;
hideSubTimer.restartTimer();
}
}
Timer
{
id: showSubTimer
interval: 100
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: 0
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")
RowLayout
{
spacing: 0
opacity: materialBrandMenu.enabled ? 1 : 0.5
height: parent.height
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
}
Item
{
// Right side margin
width: UM.Theme.getSize("default_margin").width
}
}
MouseArea
{
id: materialColorButton
anchors.fill: parent
hoverEnabled: true
onEntered:
{
menuPopup.itemHovered += 1;
colorPopup.itemHovered += 1;
}
onExited:
{
menuPopup.itemHovered -= 1;
colorPopup.itemHovered -= 1;
}
}
}
}
}
}
}
}
}