Make "add printer" sections individually collapsable

CURA-10484
This commit is contained in:
c.lamboo 2023-04-06 21:46:51 +02:00
parent 66d43d52aa
commit 20b171dbeb

View file

@ -17,11 +17,9 @@ Item
id: base id: base
// The currently selected machine item in the local machine list. // The currently selected machine item in the local machine list.
property var currentItem: (machineList.currentIndex >= 0) property var currentItem: machineList.currentIndex >= 0 ? machineList.model.getItem(machineList.currentIndex) : null
? machineList.model.getItem(machineList.currentIndex)
: null
// The currently active (expanded) section/category, where section/category is the grouping of local machine items. // The currently active (expanded) section/category, where section/category is the grouping of local machine items.
property string currentSection: "Ultimaker B.V." property var currentSection: new Set()
// By default (when this list shows up) we always expand the "Ultimaker" section. // By default (when this list shows up) we always expand the "Ultimaker" section.
property var preferredCategories: { property var preferredCategories: {
"Ultimaker B.V.": -2, "Ultimaker B.V.": -2,
@ -37,16 +35,16 @@ Item
printerName = currentItem == null ? "" : currentItem.name printerName = currentItem == null ? "" : currentItem.name
} }
function updateCurrentItemUponSectionChange() function updateCurrentItemUponSectionChange(section)
{ {
// Find the first machine from this section // Find the first machine from this section
for (var i = 0; i < machineList.count; i ++) for (var i = 0; i < machineList.count; i ++)
{ {
var item = machineList.model.getItem(i) const item = machineList.model.getItem(i);
if (item.section == base.currentSection) if (item.section == section)
{ {
machineList.currentIndex = i machineList.currentIndex = i;
break break;
} }
} }
} }
@ -68,7 +66,9 @@ Item
Component.onCompleted: Component.onCompleted:
{ {
updateCurrentItemUponSectionChange() const initialSection = "Ultimaker B.V.";
base.currentSections.add(initialSection);
updateCurrentItemUponSectionChange(initialSection);
} }
Row Row
@ -102,7 +102,7 @@ Item
height: UM.Theme.getSize("action_button").height height: UM.Theme.getSize("action_button").height
text: section text: section
property bool isActive: base.currentSection == section property bool isActive: base.currentSections.has(section)
background: Rectangle background: Rectangle
{ {
@ -122,7 +122,7 @@ Item
width: UM.Theme.getSize("standard_arrow").width width: UM.Theme.getSize("standard_arrow").width
height: UM.Theme.getSize("standard_arrow").height height: UM.Theme.getSize("standard_arrow").height
color: UM.Theme.getColor("text") color: UM.Theme.getColor("text")
source: base.currentSection == section ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleRight") source: isActive ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleRight")
} }
UM.Label UM.Label
@ -137,8 +137,17 @@ Item
onClicked: onClicked:
{ {
base.currentSection = section if (base.currentSections.has(section))
base.updateCurrentItemUponSectionChange() {
base.currentSections.delete(section);
}
else
{
base.currentSections.add(section);
base.updateCurrentItemUponSectionChange(section);
}
// Trigger update on base.currentSections
base.currentSections = base.currentSections;
} }
} }
@ -157,7 +166,7 @@ Item
checked: machineList.currentIndex == index checked: machineList.currentIndex == index
text: name text: name
visible: base.currentSection.toLowerCase() === section.toLowerCase() visible: base.currentSections.has(section)
onClicked: machineList.currentIndex = index onClicked: machineList.currentIndex = index
} }
} }