diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index 969aa3c460..f8a663f0e4 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -211,6 +211,11 @@ class PrinterOutputDevice(QObject, OutputDevice): self._unique_configurations.sort(key = lambda k: k.printerType) self.uniqueConfigurationsChanged.emit() + # Returns the unique configurations of the printers within this output device + @pyqtProperty("QVariantList", notify = uniqueConfigurationsChanged) + def uniquePrinterTypes(self) -> List[str]: + return list(set([configuration.printerType for configuration in self._unique_configurations])) + def _onPrintersChanged(self) -> None: for printer in self._printers: printer.configurationChanged.connect(self._updateUniqueConfigurations) diff --git a/resources/qml/Menus/ConfigurationMenu/ConfigurationListView.qml b/resources/qml/Menus/ConfigurationMenu/ConfigurationListView.qml index 7aaf87b4df..210ff6057f 100644 --- a/resources/qml/Menus/ConfigurationMenu/ConfigurationListView.qml +++ b/resources/qml/Menus/ConfigurationMenu/ConfigurationListView.qml @@ -21,7 +21,7 @@ Column { // FIXME For now the model should be removed and then created again, otherwise changes in the printer don't automatically update the UI configurationList.model = [] - if(outputDevice) + if (outputDevice) { configurationList.model = outputDevice.uniqueConfigurations } diff --git a/resources/qml/MachineSelector.qml b/resources/qml/PrinterSelector/MachineSelector.qml similarity index 79% rename from resources/qml/MachineSelector.qml rename to resources/qml/PrinterSelector/MachineSelector.qml index 14e1ebb48e..9280c45cf4 100644 --- a/resources/qml/MachineSelector.qml +++ b/resources/qml/PrinterSelector/MachineSelector.qml @@ -8,8 +8,6 @@ import QtQuick.Layouts 1.1 import UM 1.2 as UM import Cura 1.0 as Cura -import "Menus" - Cura.ExpandableComponent { @@ -18,7 +16,7 @@ Cura.ExpandableComponent property bool isNetworkPrinter: Cura.MachineManager.activeMachineNetworkKey != "" popupPadding: 0 - popupAlignment: ExpandableComponent.PopupAlignment.AlignLeft + popupAlignment: Cura.ExpandableComponent.PopupAlignment.AlignLeft iconSource: expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left") UM.I18nCatalog @@ -82,25 +80,10 @@ Cura.ExpandableComponent filter: {"type": "machine", "um_network_key": "*", "hidden": "False"} } - delegate: Cura.ActionButton + delegate: MachineSelectorButton { text: model.metadata["connect_group_name"] - width: parent.width - height: UM.Theme.getSize("action_button").height checked: Cura.MachineManager.activeMachineNetworkGroupName == model.metadata["connect_group_name"] - checkable: true - - color: "transparent" - hoverColor: UM.Theme.getColor("action_button_hovered") - textColor: UM.Theme.getColor("text") - textHoverColor: UM.Theme.getColor("text") - outlineColor: checked ? UM.Theme.getColor("primary") : "transparent" - - onClicked: - { - togglePopup() - Cura.MachineManager.setActiveMachine(model.id) - } Connections { @@ -132,25 +115,10 @@ Cura.ExpandableComponent filter: {"type": "machine", "um_network_key": null} } - delegate: Cura.ActionButton + delegate: MachineSelectorButton { text: model.name - width: parent.width - height: UM.Theme.getSize("action_button").height checked: Cura.MachineManager.activeMachineId == model.id - checkable: true - - color: "transparent" - hoverColor: UM.Theme.getColor("action_button_hovered") - textColor: UM.Theme.getColor("text") - textHoverColor: UM.Theme.getColor("text") - outlineColor: checked ? UM.Theme.getColor("primary") : "transparent" - - onClicked: - { - togglePopup() - Cura.MachineManager.setActiveMachine(model.id) - } } } } diff --git a/resources/qml/PrinterSelector/MachineSelectorButton.qml b/resources/qml/PrinterSelector/MachineSelectorButton.qml new file mode 100644 index 0000000000..5ba229c31c --- /dev/null +++ b/resources/qml/PrinterSelector/MachineSelectorButton.qml @@ -0,0 +1,110 @@ +// Copyright (c) 2018 Ultimaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. + +import QtQuick 2.7 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.3 + +import UM 1.1 as UM +import Cura 1.0 as Cura + +Button +{ + id: machineSelectorButton + + width: parent.width + height: UM.Theme.getSize("action_button").height + leftPadding: Math.round(1.5 * UM.Theme.getSize("default_margin").width) + checkable: true + + property var outputDevice: Cura.MachineManager.printerOutputDevices[0] + property var printerTypesList: [] + + function setPrinterTypesList() + { + printerTypesList = (checked && (outputDevice != null)) ? outputDevice.uniquePrinterTypes : [] + } + + contentItem: Item + { + width: machineSelectorButton.width - machineSelectorButton.leftPadding + height: UM.Theme.getSize("action_button").height + + Label + { + id: buttonText + anchors + { + left: parent.left + right: printerTypes.left + verticalCenter: parent.verticalCenter + } + text: machineSelectorButton.text + color: UM.Theme.getColor("text") + font: UM.Theme.getFont("action_button") + visible: text != "" + renderType: Text.NativeRendering + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + + Row + { + id: printerTypes + width: childrenRect.width + + anchors + { + right: parent.right + verticalCenter: parent.verticalCenter + } + spacing: UM.Theme.getSize("narrow_margin").width + + Repeater + { + model: printerTypesList + delegate: Label + { + text: modelData + } + } + } + } + + background: Rectangle + { + id: backgroundRect + color: machineSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent" + radius: UM.Theme.getSize("action_button_radius").width + border.width: UM.Theme.getSize("default_lining").width + border.color: machineSelectorButton.checked ? UM.Theme.getColor("primary") : "transparent" + } + + onClicked: + { + togglePopup() + Cura.MachineManager.setActiveMachine(model.id) + } + + MouseArea + { + id: mouseArea + anchors.fill: parent + onPressed: mouse.accepted = false + hoverEnabled: true + } + + Connections + { + target: outputDevice + onUniqueConfigurationsChanged: setPrinterTypesList() + } + + Connections + { + target: Cura.MachineManager + onOutputDevicesChanged: setPrinterTypesList() + } + + Component.onCompleted: setPrinterTypesList() +} diff --git a/resources/qml/qmldir b/resources/qml/qmldir index d5e4106d33..458338c78a 100644 --- a/resources/qml/qmldir +++ b/resources/qml/qmldir @@ -9,4 +9,5 @@ MaterialMenu 1.0 MaterialMenu.qml NozzleMenu 1.0 NozzleMenu.qml ActionPanelWidget 1.0 ActionPanelWidget.qml IconLabel 1.0 IconLabel.qml -OutputDevicesActionButton 1.0 OutputDevicesActionButton.qml \ No newline at end of file +OutputDevicesActionButton 1.0 OutputDevicesActionButton.qml +ExpandableComponent 1.0 ExpandableComponent.qml \ No newline at end of file