diff --git a/cura/Machines/Models/MachineListModel.py b/cura/Machines/Models/MachineListModel.py index 9b1ffd16c6..2225e014e8 100644 --- a/cura/Machines/Models/MachineListModel.py +++ b/cura/Machines/Models/MachineListModel.py @@ -25,6 +25,7 @@ class MachineListModel(ListModel): IsOnlineRole = Qt.ItemDataRole.UserRole + 5 MachineCountRole = Qt.ItemDataRole.UserRole + 6 IsAbstractMachine = Qt.ItemDataRole.UserRole + 7 + ListTypeRole = Qt.ItemDataRole.UserRole + 8 def __init__(self, parent=None) -> None: super().__init__(parent) @@ -40,6 +41,7 @@ class MachineListModel(ListModel): self.addRoleName(self.IsOnlineRole, "isOnline") self.addRoleName(self.MachineCountRole, "machineCount") self.addRoleName(self.IsAbstractMachine, "isAbstractMachine") + self.addRoleName(self.ListTypeRole, "listType") self._change_timer = QTimer() self._change_timer.setInterval(200) @@ -99,6 +101,16 @@ class MachineListModel(ListModel): # Remove this machine from the other stack list 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: self.addItem(stack) @@ -113,7 +125,9 @@ class MachineListModel(ListModel): for connection_type in [ConnectionType.NetworkConnection.value, ConnectionType.CloudConnection.value]: 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(), "metadata": container_stack.getMetaData().copy(), "isOnline": parseBool(container_stack.getMetaDataEntry("is_online", False)) and has_connection, diff --git a/resources/qml/PrinterSelector/MachineListButton.qml b/resources/qml/PrinterSelector/MachineListButton.qml index 55ae5497d9..039c9c054b 100644 --- a/resources/qml/PrinterSelector/MachineListButton.qml +++ b/resources/qml/PrinterSelector/MachineListButton.qml @@ -7,81 +7,134 @@ import QtQuick.Controls 2.3 import UM 1.5 as UM import Cura 1.0 as Cura - -Button -{ - id: machineListButton - +Loader { + id: loader width: parent.width - height: UM.Theme.getSize("large_button").height - leftPadding: UM.Theme.getSize("default_margin").width - rightPadding: UM.Theme.getSize("default_margin").width - checkable: true - hoverEnabled: true + 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 - contentItem: Item + Component { - width: machineListButton.width - machineListButton.leftPadding - machineListButton.rightPadding - height: UM.Theme.getSize("action_button").height - - UM.ColorImage + id: hideButtonComponent + Cura.TertiaryButton { - id: printerIcon - height: UM.Theme.getSize("medium_button").height - width: UM.Theme.getSize("medium_button").width - color: UM.Theme.getColor("machine_selector_printer_icon") - visible: model.isAbstractMachine || !model.isOnline - source: model.isAbstractMachine ? UM.Theme.getIcon("PrinterTriple", "medium") : UM.Theme.getIcon("Printer", "medium") - - anchors - { - left: parent.left - verticalCenter: parent.verticalCenter - } - } - - UM.Label - { - id: buttonText - anchors - { - left: printerIcon.right - right: printerCount.left - verticalCenter: parent.verticalCenter - leftMargin: UM.Theme.getSize("default_margin").width - } - text: machineListButton.text - font: model.isAbstractMachine ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium") - visible: text != "" - elide: Text.ElideRight - } - - Rectangle - { - id: printerCount - color: UM.Theme.getColor("background_2") - radius: height - width: height - anchors - { - right: parent.right - top: buttonText.top - bottom: buttonText.bottom - } - visible: model.isAbstractMachine - - UM.Label - { - text: model.machineCount - anchors.centerIn: parent - font: UM.Theme.getFont("default_bold") - } + 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 } } - background: Rectangle + Component { - id: backgroundRect - color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent" + 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 + { + id: machineListButton + + onClicked: if (loader.onClicked) loader.onClicked() + + width: parent.width + height: UM.Theme.getSize("large_button").height + leftPadding: UM.Theme.getSize("default_margin").width + rightPadding: UM.Theme.getSize("default_margin").width + checkable: true + hoverEnabled: true + + contentItem: Item + { + width: machineListButton.width - machineListButton.leftPadding - machineListButton.rightPadding + height: UM.Theme.getSize("action_button").height + + UM.ColorImage + { + id: printerIcon + height: UM.Theme.getSize("medium_button").height + width: UM.Theme.getSize("medium_button").width + color: UM.Theme.getColor("machine_selector_printer_icon") + visible: model.isAbstractMachine || !model.isOnline + source: model.isAbstractMachine ? UM.Theme.getIcon("PrinterTriple", "medium") : UM.Theme.getIcon("Printer", "medium") + + anchors + { + left: parent.left + verticalCenter: parent.verticalCenter + } + } + + UM.Label + { + id: buttonText + anchors + { + left: printerIcon.right + right: printerCount.left + verticalCenter: parent.verticalCenter + leftMargin: UM.Theme.getSize("default_margin").width + } + text: model.name ? model.name : "" + font: model.isAbstractMachine ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium") + visible: text != "" + elide: Text.ElideRight + } + + Rectangle + { + id: printerCount + color: UM.Theme.getColor("background_2") + radius: height + width: height + anchors + { + right: parent.right + top: buttonText.top + bottom: buttonText.bottom + } + visible: model.isAbstractMachine + + UM.Label + { + text: model.machineCount + anchors.centerIn: parent + font: UM.Theme.getFont("default_bold") + } + } + } + + background: Rectangle + { + id: backgroundRect + color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent" + } + } } } diff --git a/resources/qml/PrinterSelector/MachineSelectorList.qml b/resources/qml/PrinterSelector/MachineSelectorList.qml index 6c5124969a..d4a4c4a5ce 100644 --- a/resources/qml/PrinterSelector/MachineSelectorList.qml +++ b/resources/qml/PrinterSelector/MachineSelectorList.qml @@ -19,53 +19,35 @@ ListView 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 - 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") - } - } + leftPadding: UM.Theme.getSize("default_margin").width + font: UM.Theme.getFont("medium") + color: UM.Theme.getColor("text_medium") } delegate: MachineListButton { - text: model.name ? model.name : "" width: listView.width - scrollBar.width - onClicked: + onClicked: function() { - toggleContent() - Cura.MachineManager.setActiveMachine(model.id) + switch (model.listType) { + case "HIDE_BUTTON": + listView.model.setShowCloudPrinters(false); + break; + case "SHOW_BUTTON": + listView.model.setShowCloudPrinters(true); + break; + case "MACHINE": + toggleContent() + Cura.MachineManager.setActiveMachine(model.id) + break; + default: + } } } }