Cura/resources/qml/Preferences/MachinesPage.qml
Jaime van Kessel 8feaa32769 Codestyle cleanups
Mostly just removing ;'s from QML

CURA-8949
2022-02-18 11:28:40 +01:00

181 lines
5.7 KiB
QML

// Copyright (c) 2022 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.Window 2.1
import UM 1.5 as UM
import Cura 1.0 as Cura
UM.ManagementPage
{
id: base
title: catalog.i18nc("@title:tab", "Printers")
model: Cura.GlobalStacksModel { }
sectionRole: "discoverySource"
activeId: Cura.MachineManager.activeMachine !== null ? Cura.MachineManager.activeMachine.id: ""
activeIndex: activeMachineIndex()
function activeMachineIndex()
{
for(var i = 0; i < model.count; i++)
{
if (model.getItem(i).id == base.activeId)
{
return i;
}
}
return -1;
}
buttons: [
Button
{
id: activateMenuButton
text: catalog.i18nc("@action:button", "Activate")
icon.name: "list-activate"
enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMachine.id
onClicked: Cura.MachineManager.setActiveMachine(base.currentItem.id)
},
Button
{
id: addMenuButton
text: catalog.i18nc("@action:button", "Add")
icon.name: "list-add"
onClicked: Cura.Actions.addMachine.trigger()
},
Button
{
id: removeMenuButton
text: catalog.i18nc("@action:button", "Remove")
icon.name: "list-remove"
enabled: base.currentItem != null && model.count > 1
onClicked: confirmDialog.open()
},
Button
{
id: renameMenuButton
text: catalog.i18nc("@action:button", "Rename")
icon.name: "edit-rename"
enabled: base.currentItem != null && base.currentItem.metadata.group_name == null
onClicked: renameDialog.open()
}
]
Item
{
visible: base.currentItem != null
anchors.fill: parent
UM.Label
{
id: machineName
text: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
font: UM.Theme.getFont("large_bold")
width: parent.width
elide: Text.ElideRight
}
Flow
{
id: machineActions
visible: currentItem && currentItem.id == Cura.MachineManager.activeMachine.id
anchors
{
left: parent.left
right: parent.right
top: machineName.bottom
topMargin: UM.Theme.getSize("default_margin").height
}
spacing: UM.Theme.getSize("default_margin").height
Repeater
{
id: machineActionRepeater
model: base.currentItem ? Cura.MachineActionManager.getSupportedActions(Cura.MachineManager.getDefinitionByMachineId(base.currentItem.id)) : null
Item
{
width: Math.round(childrenRect.width + 2 * screenScaleFactor)
height: childrenRect.height
Cura.SecondaryButton
{
text: machineActionRepeater.model[index].label
onClicked:
{
var currentItem = machineActionRepeater.model[index]
actionDialog.loader.manager = currentItem
actionDialog.loader.source = currentItem.qmlPath
actionDialog.title = currentItem.label
actionDialog.show()
}
}
}
}
}
UM.Dialog
{
id: actionDialog
minimumWidth: UM.Theme.getSize("modal_window_minimum").width
minimumHeight: UM.Theme.getSize("modal_window_minimum").height
maximumWidth: minimumWidth * 3
maximumHeight: minimumHeight * 3
rightButtons: Button
{
text: catalog.i18nc("@action:button", "Close")
icon.name: "dialog-close"
onClicked: actionDialog.reject()
}
}
UM.I18nCatalog { id: catalog; name: "cura"; }
UM.ConfirmRemoveDialog
{
id: confirmDialog
object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
text: base.currentItem ? base.currentItem.removalWarning : ""
onAccepted:
{
Cura.MachineManager.removeMachine(base.currentItem.id)
if(!base.currentItem)
{
objectList.currentIndex = activeMachineIndex()
}
//Force updating currentItem and the details panel
objectList.onCurrentIndexChanged()
}
}
UM.RenameDialog
{
id: renameDialog
object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
property var machine_name_validator: Cura.MachineNameValidator { }
validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null
onAccepted:
{
Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim())
//Force updating currentItem and the details panel
objectList.onCurrentIndexChanged()
}
}
Connections
{
target: Cura.MachineManager
function onGlobalContainerChanged()
{
objectList.currentIndex = activeMachineIndex()
objectList.onCurrentIndexChanged()
}
}
}
}