diff --git a/cura/Machines/Models/MachineListModel.py b/cura/Machines/Models/MachineListModel.py index 6814600307..9b1ffd16c6 100644 --- a/cura/Machines/Models/MachineListModel.py +++ b/cura/Machines/Models/MachineListModel.py @@ -5,7 +5,7 @@ # online cloud connected printers are represented within this ListModel. Additional information such as the number of # connected printers for each printer type is gathered. -from PyQt6.QtCore import Qt, QTimer +from PyQt6.QtCore import Qt, QTimer, pyqtSlot, pyqtProperty, pyqtSignal from UM.Qt.ListModel import ListModel from UM.Settings.ContainerStack import ContainerStack @@ -29,6 +29,8 @@ class MachineListModel(ListModel): def __init__(self, parent=None) -> None: super().__init__(parent) + self._show_cloud_printers = True + self._catalog = i18nCatalog("cura") self.addRoleName(self.NameRole, "name") @@ -50,6 +52,18 @@ class MachineListModel(ListModel): CuraContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChanged) self._updateDelayed() + showCloutPrintersChanged = pyqtSignal(bool) + + @pyqtProperty(bool, notify=showCloutPrintersChanged) + def showCloudPrinters(self) -> bool: + return self._show_cloud_printers + + @pyqtSlot(bool, name="setShowCloudPrinters") + def set_show_cloud_printers(self, show_cloud_printers: bool) -> None: + self._show_cloud_printers = show_cloud_printers + self._updateDelayed() + self.showCloutPrintersChanged.emit(show_cloud_printers) + def _onContainerChanged(self, container) -> None: """Handler for container added/removed events from registry""" @@ -80,7 +94,8 @@ class MachineListModel(ListModel): # Create list of machines that are children of the abstract machine for stack in online_machine_stacks: - self.addItem(stack) + if self._show_cloud_printers: + self.addItem(stack) # Remove this machine from the other stack list other_machine_stacks.remove(stack) diff --git a/resources/qml/PrinterSelector/MachineSelectorList.qml b/resources/qml/PrinterSelector/MachineSelectorList.qml index 06c2fdb40c..6c5124969a 100644 --- a/resources/qml/PrinterSelector/MachineSelectorList.qml +++ b/resources/qml/PrinterSelector/MachineSelectorList.qml @@ -19,14 +19,42 @@ ListView id: scrollBar } - section.delegate: UM.Label + section.delegate: Item { - text: section == "true" ? catalog.i18nc("@label", "Connected printers") : catalog.i18nc("@label", "Other printers") width: parent.width - scrollBar.width - 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") + 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 + font: UM.Theme.getFont("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