mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-11-02 20:52:20 -07:00
Add a new printer selector button that is connected to the output
devices and shows labels containing the type of printers that are in the same group. Contributes to CURA-5942.
This commit is contained in:
parent
b890e40e81
commit
9720512f50
5 changed files with 121 additions and 37 deletions
179
resources/qml/PrinterSelector/MachineSelector.qml
Normal file
179
resources/qml/PrinterSelector/MachineSelector.qml
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
// 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.3
|
||||
import QtQuick.Controls.Styles 1.1
|
||||
import QtQuick.Layouts 1.1
|
||||
|
||||
import UM 1.2 as UM
|
||||
import Cura 1.0 as Cura
|
||||
|
||||
Cura.ExpandableComponent
|
||||
{
|
||||
id: machineSelector
|
||||
|
||||
property bool isNetworkPrinter: Cura.MachineManager.activeMachineNetworkKey != ""
|
||||
|
||||
popupPadding: 0
|
||||
popupAlignment: Cura.ExpandableComponent.PopupAlignment.AlignLeft
|
||||
iconSource: expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
|
||||
|
||||
UM.I18nCatalog
|
||||
{
|
||||
id: catalog
|
||||
name: "cura"
|
||||
}
|
||||
|
||||
headerItem: Label
|
||||
{
|
||||
text: isNetworkPrinter ? Cura.MachineManager.activeMachineNetworkGroupName : Cura.MachineManager.activeMachineName
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
height: parent.height
|
||||
elide: Text.ElideRight
|
||||
renderType: Text.NativeRendering
|
||||
font: UM.Theme.getFont("default")
|
||||
color: UM.Theme.getColor("text")
|
||||
}
|
||||
|
||||
popupItem: Item
|
||||
{
|
||||
id: popup
|
||||
width: UM.Theme.getSize("machine_selector_widget_content").width
|
||||
height: UM.Theme.getSize("machine_selector_widget_content").height
|
||||
|
||||
ScrollView
|
||||
{
|
||||
id: scroll
|
||||
width: parent.width
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: separator.top
|
||||
clip: true
|
||||
|
||||
Column
|
||||
{
|
||||
id: column
|
||||
|
||||
// Can't use parent.width since the parent is the flickable component and not the ScrollView
|
||||
width: scroll.width - 2 * UM.Theme.getSize("default_lining").width
|
||||
x: UM.Theme.getSize("default_lining").width
|
||||
|
||||
Label
|
||||
{
|
||||
text: catalog.i18nc("@label", "Network connected printers")
|
||||
visible: networkedPrintersModel.items.length > 0
|
||||
leftPadding: UM.Theme.getSize("default_margin").width
|
||||
height: visible ? contentHeight + 2 * UM.Theme.getSize("default_margin").height : 0
|
||||
renderType: Text.NativeRendering
|
||||
font: UM.Theme.getFont("medium")
|
||||
color: UM.Theme.getColor("text_medium")
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
|
||||
Repeater
|
||||
{
|
||||
id: networkedPrinters
|
||||
|
||||
model: UM.ContainerStacksModel
|
||||
{
|
||||
id: networkedPrintersModel
|
||||
filter: {"type": "machine", "um_network_key": "*", "hidden": "False"}
|
||||
}
|
||||
|
||||
delegate: MachineSelectorButton
|
||||
{
|
||||
text: model.metadata["connect_group_name"]
|
||||
checked: Cura.MachineManager.activeMachineNetworkGroupName == model.metadata["connect_group_name"]
|
||||
|
||||
Connections
|
||||
{
|
||||
target: Cura.MachineManager
|
||||
onActiveMachineNetworkGroupNameChanged: checked = Cura.MachineManager.activeMachineNetworkGroupName == model.metadata["connect_group_name"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Label
|
||||
{
|
||||
text: catalog.i18nc("@label", "Preset printers")
|
||||
visible: virtualPrintersModel.items.length > 0
|
||||
leftPadding: UM.Theme.getSize("default_margin").width
|
||||
height: visible ? contentHeight + 2 * UM.Theme.getSize("default_margin").height : 0
|
||||
renderType: Text.NativeRendering
|
||||
font: UM.Theme.getFont("medium")
|
||||
color: UM.Theme.getColor("text_medium")
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
|
||||
Repeater
|
||||
{
|
||||
id: virtualPrinters
|
||||
|
||||
model: UM.ContainerStacksModel
|
||||
{
|
||||
id: virtualPrintersModel
|
||||
filter: {"type": "machine", "um_network_key": null}
|
||||
}
|
||||
|
||||
delegate: MachineSelectorButton
|
||||
{
|
||||
text: model.name
|
||||
checked: Cura.MachineManager.activeMachineId == model.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle
|
||||
{
|
||||
id: separator
|
||||
|
||||
anchors.bottom: buttonRow.top
|
||||
width: parent.width
|
||||
height: UM.Theme.getSize("default_lining").height
|
||||
color: UM.Theme.getColor("lining")
|
||||
}
|
||||
|
||||
Row
|
||||
{
|
||||
id: buttonRow
|
||||
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
padding: UM.Theme.getSize("default_margin").width
|
||||
spacing: UM.Theme.getSize("default_margin").width
|
||||
|
||||
Cura.ActionButton
|
||||
{
|
||||
leftPadding: UM.Theme.getSize("default_margin").width
|
||||
rightPadding: UM.Theme.getSize("default_margin").width
|
||||
text: catalog.i18nc("@button", "Add printer")
|
||||
color: UM.Theme.getColor("secondary")
|
||||
hoverColor: UM.Theme.getColor("secondary")
|
||||
textColor: UM.Theme.getColor("primary")
|
||||
textHoverColor: UM.Theme.getColor("text")
|
||||
onClicked:
|
||||
{
|
||||
togglePopup()
|
||||
Cura.Actions.addMachine.trigger()
|
||||
}
|
||||
}
|
||||
|
||||
Cura.ActionButton
|
||||
{
|
||||
leftPadding: UM.Theme.getSize("default_margin").width
|
||||
rightPadding: UM.Theme.getSize("default_margin").width
|
||||
text: catalog.i18nc("@button", "Manage printers")
|
||||
color: UM.Theme.getColor("secondary")
|
||||
hoverColor: UM.Theme.getColor("secondary")
|
||||
textColor: UM.Theme.getColor("primary")
|
||||
textHoverColor: UM.Theme.getColor("text")
|
||||
onClicked:
|
||||
{
|
||||
togglePopup()
|
||||
Cura.Actions.configureMachines.trigger()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
110
resources/qml/PrinterSelector/MachineSelectorButton.qml
Normal file
110
resources/qml/PrinterSelector/MachineSelectorButton.qml
Normal file
|
|
@ -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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue