Use list model to display show hide buttons

CURA-9514
This commit is contained in:
c.lamboo 2022-08-31 07:58:05 +02:00
parent ac732e9604
commit 60b12b9247
3 changed files with 156 additions and 107 deletions

View file

@ -25,6 +25,7 @@ class MachineListModel(ListModel):
IsOnlineRole = Qt.ItemDataRole.UserRole + 5 IsOnlineRole = Qt.ItemDataRole.UserRole + 5
MachineCountRole = Qt.ItemDataRole.UserRole + 6 MachineCountRole = Qt.ItemDataRole.UserRole + 6
IsAbstractMachine = Qt.ItemDataRole.UserRole + 7 IsAbstractMachine = Qt.ItemDataRole.UserRole + 7
ListTypeRole = Qt.ItemDataRole.UserRole + 8
def __init__(self, parent=None) -> None: def __init__(self, parent=None) -> None:
super().__init__(parent) super().__init__(parent)
@ -40,6 +41,7 @@ class MachineListModel(ListModel):
self.addRoleName(self.IsOnlineRole, "isOnline") self.addRoleName(self.IsOnlineRole, "isOnline")
self.addRoleName(self.MachineCountRole, "machineCount") self.addRoleName(self.MachineCountRole, "machineCount")
self.addRoleName(self.IsAbstractMachine, "isAbstractMachine") self.addRoleName(self.IsAbstractMachine, "isAbstractMachine")
self.addRoleName(self.ListTypeRole, "listType")
self._change_timer = QTimer() self._change_timer = QTimer()
self._change_timer.setInterval(200) self._change_timer.setInterval(200)
@ -99,6 +101,16 @@ class MachineListModel(ListModel):
# Remove this machine from the other stack list # Remove this machine from the other stack list
other_machine_stacks.remove(stack) other_machine_stacks.remove(stack)
if len(abstract_machine_stacks) > 0:
if self._show_cloud_printers:
self.appendItem({ "listType": "HIDE_BUTTON",
"isOnline": True,
})
else:
self.appendItem({ "listType": "SHOW_BUTTON",
"isOnline": True,
})
for stack in other_machine_stacks: for stack in other_machine_stacks:
self.addItem(stack) self.addItem(stack)
@ -113,7 +125,9 @@ class MachineListModel(ListModel):
for connection_type in [ConnectionType.NetworkConnection.value, ConnectionType.CloudConnection.value]: for connection_type in [ConnectionType.NetworkConnection.value, ConnectionType.CloudConnection.value]:
has_connection |= connection_type in container_stack.configuredConnectionTypes has_connection |= connection_type in container_stack.configuredConnectionTypes
self.appendItem({"name": container_stack.getName(), self.appendItem({
"listType": "MACHINE",
"name": container_stack.getName(),
"id": container_stack.getId(), "id": container_stack.getId(),
"metadata": container_stack.getMetaData().copy(), "metadata": container_stack.getMetaData().copy(),
"isOnline": parseBool(container_stack.getMetaDataEntry("is_online", False)) and has_connection, "isOnline": parseBool(container_stack.getMetaDataEntry("is_online", False)) and has_connection,

View file

@ -7,11 +7,62 @@ import QtQuick.Controls 2.3
import UM 1.5 as UM import UM 1.5 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
Loader {
id: loader
width: parent.width
height: childrenRect.height
sourceComponent: {
switch (model.listType) {
case "HIDE_BUTTON":
hideButtonComponent
break;
case "SHOW_BUTTON":
showButtonComponent
break;
case "MACHINE":
machineListButtonComponent
break;
default:
}
}
property var onClicked
Component
{
id: hideButtonComponent
Cura.TertiaryButton
{
text: catalog.i18nc("@label", "Hide all connected printers")
height: UM.Theme.getSize("large_button").height
onClicked: if (loader.onClicked) loader.onClicked()
iconSource: UM.Theme.getIcon("ChevronSingleUp")
width: parent.width
}
}
Component
{
id: showButtonComponent
Cura.TertiaryButton
{
text: catalog.i18nc("@label", "Show all connected printers")
height: UM.Theme.getSize("large_button").height
onClicked: if (loader.onClicked) loader.onClicked()
iconSource: UM.Theme.getIcon("ChevronSingleDown")
width: parent.width
}
}
Component
{
id: machineListButtonComponent
Button Button
{ {
id: machineListButton id: machineListButton
onClicked: if (loader.onClicked) loader.onClicked()
width: parent.width width: parent.width
height: UM.Theme.getSize("large_button").height height: UM.Theme.getSize("large_button").height
leftPadding: UM.Theme.getSize("default_margin").width leftPadding: UM.Theme.getSize("default_margin").width
@ -50,7 +101,7 @@ Button
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
leftMargin: UM.Theme.getSize("default_margin").width leftMargin: UM.Theme.getSize("default_margin").width
} }
text: machineListButton.text text: model.name ? model.name : ""
font: model.isAbstractMachine ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium") font: model.isAbstractMachine ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium")
visible: text != "" visible: text != ""
elide: Text.ElideRight elide: Text.ElideRight
@ -85,3 +136,5 @@ Button
color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent" color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
} }
} }
}
}

View file

@ -19,53 +19,35 @@ ListView
id: scrollBar id: scrollBar
} }
section.delegate: Item section.delegate: UM.Label
{ {
text: section == "true" ? catalog.i18nc("@label", "Connected printers") : catalog.i18nc("@label", "Other printers")
height: UM.Theme.getSize("action_button").height
width: parent.width - scrollBar.width width: parent.width - scrollBar.width
height: childrenRect.height
UM.Label
{
visible: section == "true"
text: catalog.i18nc("@label", "Connected printers")
height: UM.Theme.getSize("action_button").height
leftPadding: UM.Theme.getSize("default_margin").width leftPadding: UM.Theme.getSize("default_margin").width
font: UM.Theme.getFont("medium") font: UM.Theme.getFont("medium")
color: UM.Theme.getColor("text_medium") color: UM.Theme.getColor("text_medium")
} }
Column
{
visible: section != "true"
height: childrenRect.height
Cura.TertiaryButton
{
text: listView.model.showCloudPrinters ? catalog.i18nc("@label", "Hide all connected printers") : catalog.i18nc("@label", "Show all connected printers")
onClicked: listView.model.setShowCloudPrinters(!listView.model.showCloudPrinters)
iconSource: listView.model.showCloudPrinters ? UM.Theme.getIcon("ChevronSingleUp") : UM.Theme.getIcon("ChevronSingleDown")
}
UM.Label
{
text: catalog.i18nc("@label", "Other printers")
height: UM.Theme.getSize("action_button").height
leftPadding: UM.Theme.getSize("default_margin").width
font: UM.Theme.getFont("medium")
color: UM.Theme.getColor("text_medium")
}
}
}
delegate: MachineListButton delegate: MachineListButton
{ {
text: model.name ? model.name : ""
width: listView.width - scrollBar.width width: listView.width - scrollBar.width
onClicked: onClicked: function()
{ {
switch (model.listType) {
case "HIDE_BUTTON":
listView.model.setShowCloudPrinters(false);
break;
case "SHOW_BUTTON":
listView.model.setShowCloudPrinters(true);
break;
case "MACHINE":
toggleContent() toggleContent()
Cura.MachineManager.setActiveMachine(model.id) Cura.MachineManager.setActiveMachine(model.id)
break;
default:
}
} }
} }
} }