Change MachineSelection so that it also uses the ExpandableComponent

CURA-5785
This commit is contained in:
Jaime van Kessel 2018-11-13 14:00:00 +01:00
parent fe4ed46496
commit c18b8241f5
2 changed files with 108 additions and 69 deletions

View file

@ -249,7 +249,6 @@ UM.MainWindow
source: UM.Controller.activeStage != null ? UM.Controller.activeStage.mainComponent : "" source: UM.Controller.activeStage != null ? UM.Controller.activeStage.mainComponent : ""
} }
Loader Loader
{ {
// The stage menu is, as the name implies, a menu that is defined by the active stage. // The stage menu is, as the name implies, a menu that is defined by the active stage.

View file

@ -2,7 +2,7 @@
// Cura is released under the terms of the LGPLv3 or higher. // Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.1 import QtQuick.Controls 2.4
import QtQuick.Controls.Styles 1.1 import QtQuick.Controls.Styles 1.1
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
@ -10,77 +10,117 @@ import UM 1.2 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
import "Menus" import "Menus"
ToolButton
Cura.ExpandableComponent
{ {
id: base id: machineSelector
property bool isNetworkPrinter: Cura.MachineManager.activeMachineNetworkKey != "" property bool isNetworkPrinter: Cura.MachineManager.activeMachineNetworkKey != ""
property bool printerConnected: Cura.MachineManager.printerConnected
property var printerStatus: Cura.MachineManager.printerConnected ? "connected" : "disconnected" iconSource: expanded ? UM.Theme.getIcon("arrow_left") : UM.Theme.getIcon("arrow_bottom")
UM.I18nCatalog
{
id: catalog
name: "cura"
}
headerItem: Item
{
Label
{
text: isNetworkPrinter ? Cura.MachineManager.activeMachineNetworkGroupName : Cura.MachineManager.activeMachineName text: isNetworkPrinter ? Cura.MachineManager.activeMachineNetworkGroupName : Cura.MachineManager.activeMachineName
verticalAlignment: Text.AlignVCenter
height: parent.height
}
}
tooltip: Cura.MachineManager.activeMachineName popupItem: Item
{
id: popup
width: 240 width: 240
style: ButtonStyle height: 200
{
background: Rectangle
{
color:
{
if (control.pressed) {
return UM.Theme.getColor("machine_selector_active");
}
else if (control.hovered) {
return UM.Theme.getColor("machine_selector_hover");
}
else {
return UM.Theme.getColor("machine_selector_bar");
}
}
Behavior on color { ColorAnimation { duration: 50; } }
UM.RecolorImage ScrollView
{ {
id: downArrow anchors.fill: parent
anchors.verticalCenter: parent.verticalCenter contentHeight: column.implicitHeight
anchors.right: parent.right contentWidth: row.implicitWidth
anchors.rightMargin: UM.Theme.getSize("default_margin").width clip: true
width: UM.Theme.getSize("standard_arrow").width ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
height: UM.Theme.getSize("standard_arrow").height
sourceSize.width: width Column
sourceSize.height: width {
color: UM.Theme.getColor("text_emphasis") id: column
source: UM.Theme.getIcon("arrow_bottom") anchors.fill: parent
Label
{
text: catalog.i18nc("@label", "Networked Printers")
visible: networkedPrintersModel.items.length > 0
height: visible ? contentHeight + 2 * UM.Theme.getSize("default_margin").height : 0
font: UM.Theme.getFont("medium_bold")
verticalAlignment: Text.AlignVCenter
} }
PrinterStatusIcon Repeater
{ {
id: printerStatusIcon id: networkedPrinters
visible: printerConnected || isNetworkPrinter
status: printerStatus model: UM.ContainerStacksModel
anchors
{ {
verticalCenter: parent.verticalCenter id: networkedPrintersModel
left: parent.left filter: {"type": "machine", "um_network_key": "*", "hidden": "False"}
leftMargin: UM.Theme.getSize("thick_margin").width
} }
delegate: RoundButton
{
text: name
width: parent.width
checkable: true
onClicked: Cura.MachineManager.setActiveMachine(model.id)
radius: UM.Theme.getSize("default_radius").width
Connections
{
target: Cura.MachineManager
onActiveMachineNetworkGroupNameChanged: checked = Cura.MachineManager.activeMachineNetworkGroupName == model.metadata["connect_group_name"]
}
}
} }
Label Label
{ {
id: sidebarComboBoxLabel text: catalog.i18nc("@label", "Virtual Printers")
color: UM.Theme.getColor("machine_selector_text_active") visible: virtualPrintersModel.items.length > 0
text: control.text; height: visible ? contentHeight + 2 * UM.Theme.getSize("default_margin").height : 0
elide: Text.ElideRight;
anchors.left: printerStatusIcon.visible ? printerStatusIcon.right : parent.left;
anchors.leftMargin: printerStatusIcon.visible ? UM.Theme.getSize("narrow_margin").width : UM.Theme.getSize("thick_margin").width
anchors.right: downArrow.left;
anchors.rightMargin: control.rightMargin;
anchors.verticalCenter: parent.verticalCenter;
font: UM.Theme.getFont("medium_bold") font: UM.Theme.getFont("medium_bold")
} verticalAlignment: Text.AlignVCenter
}
label: Label {}
} }
menu: PrinterMenu { } Repeater
{
id: virtualPrinters
model: UM.ContainerStacksModel
{
id: virtualPrintersModel
filter: {"type": "machine", "um_network_key": null}
}
delegate: RoundButton
{
text: name
width: parent.width
checked: Cura.MachineManager.activeMachineId == model.id
checkable: true
onClicked: Cura.MachineManager.setActiveMachine(model.id)
radius: UM.Theme.getSize("default_radius").width
}
}
}
}
}
} }