mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -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
|
||||
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,
|
||||
|
|
|
@ -7,11 +7,62 @@ import QtQuick.Controls 2.3
|
|||
import UM 1.5 as UM
|
||||
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
|
||||
|
||||
Button
|
||||
{
|
||||
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
|
||||
{
|
||||
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
|
||||
|
@ -50,7 +101,7 @@ Button
|
|||
verticalCenter: parent.verticalCenter
|
||||
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")
|
||||
visible: text != ""
|
||||
elide: Text.ElideRight
|
||||
|
@ -84,4 +135,6 @@ Button
|
|||
id: backgroundRect
|
||||
color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delegate: MachineListButton
|
||||
{
|
||||
text: model.name ? model.name : ""
|
||||
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()
|
||||
Cura.MachineManager.setActiveMachine(model.id)
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue