mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Use list model to display show hide buttons
CURA-9514
This commit is contained in:
parent
ac732e9604
commit
60b12b9247
3 changed files with 156 additions and 107 deletions
|
@ -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,
|
||||||
|
|
|
@ -7,81 +7,134 @@ 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 {
|
||||||
Button
|
id: loader
|
||||||
{
|
|
||||||
id: machineListButton
|
|
||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: UM.Theme.getSize("large_button").height
|
height: childrenRect.height
|
||||||
leftPadding: UM.Theme.getSize("default_margin").width
|
sourceComponent: {
|
||||||
rightPadding: UM.Theme.getSize("default_margin").width
|
switch (model.listType) {
|
||||||
checkable: true
|
case "HIDE_BUTTON":
|
||||||
hoverEnabled: true
|
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
|
id: hideButtonComponent
|
||||||
height: UM.Theme.getSize("action_button").height
|
Cura.TertiaryButton
|
||||||
|
|
||||||
UM.ColorImage
|
|
||||||
{
|
{
|
||||||
id: printerIcon
|
text: catalog.i18nc("@label", "Hide all connected printers")
|
||||||
height: UM.Theme.getSize("medium_button").height
|
height: UM.Theme.getSize("large_button").height
|
||||||
width: UM.Theme.getSize("medium_button").width
|
onClicked: if (loader.onClicked) loader.onClicked()
|
||||||
color: UM.Theme.getColor("machine_selector_printer_icon")
|
iconSource: UM.Theme.getIcon("ChevronSingleUp")
|
||||||
visible: model.isAbstractMachine || !model.isOnline
|
width: parent.width
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
background: Rectangle
|
Component
|
||||||
{
|
{
|
||||||
id: backgroundRect
|
id: showButtonComponent
|
||||||
color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
leftPadding: UM.Theme.getSize("default_margin").width
|
||||||
|
font: UM.Theme.getFont("medium")
|
||||||
UM.Label
|
color: UM.Theme.getColor("text_medium")
|
||||||
{
|
|
||||||
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
|
delegate: MachineListButton
|
||||||
{
|
{
|
||||||
text: model.name ? model.name : ""
|
|
||||||
width: listView.width - scrollBar.width
|
width: listView.width - scrollBar.width
|
||||||
|
|
||||||
onClicked:
|
onClicked: function()
|
||||||
{
|
{
|
||||||
toggleContent()
|
switch (model.listType) {
|
||||||
Cura.MachineManager.setActiveMachine(model.id)
|
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:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue