mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-11-02 20:52:20 -07:00
Implement basic styling of material management page
CURA-8979
This commit is contained in:
parent
01ecc799fa
commit
f9a5cb33fd
4 changed files with 648 additions and 642 deletions
|
|
@ -3,13 +3,12 @@
|
|||
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtQuick.Dialogs 1.2
|
||||
|
||||
import UM 1.5 as UM
|
||||
import Cura 1.5 as Cura
|
||||
|
||||
Item
|
||||
UM.ManagementPage
|
||||
{
|
||||
id: base
|
||||
|
||||
|
|
@ -36,12 +35,6 @@ Item
|
|||
property var extruder_position: Cura.ExtruderManager.activeExtruderIndex
|
||||
property var active_root_material_id: Cura.MachineManager.currentRootMaterialId[extruder_position]
|
||||
|
||||
UM.I18nCatalog
|
||||
{
|
||||
id: catalog
|
||||
name: "cura"
|
||||
}
|
||||
|
||||
function resetExpandedActiveMaterial()
|
||||
{
|
||||
materialListView.expandActiveMaterial(active_root_material_id)
|
||||
|
|
@ -74,57 +67,14 @@ Item
|
|||
}
|
||||
}
|
||||
|
||||
// Main layout
|
||||
Label
|
||||
{
|
||||
id: titleLabel
|
||||
anchors
|
||||
{
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
margins: 5 * screenScaleFactor
|
||||
}
|
||||
font.pointSize: 18
|
||||
text: catalog.i18nc("@title:tab", "Materials")
|
||||
}
|
||||
title: catalog.i18nc("@title:tab", "Materials")
|
||||
scrollviewCaption: catalog.i18nc("@label", "Materials compatible with active printer:") + `<br /><b>${Cura.MachineManager.activeMachine.name}</b>`
|
||||
|
||||
// Button Row
|
||||
Row
|
||||
{
|
||||
id: buttonRow
|
||||
anchors
|
||||
{
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
top: titleLabel.bottom
|
||||
}
|
||||
height: childrenRect.height
|
||||
|
||||
// Activate button
|
||||
Button
|
||||
{
|
||||
id: activateMenuButton
|
||||
text: catalog.i18nc("@action:button", "Activate")
|
||||
icon.name: "list-activate"
|
||||
enabled: !isCurrentItemActivated && Cura.MachineManager.activeMachine.hasMaterials
|
||||
onClicked:
|
||||
{
|
||||
forceActiveFocus()
|
||||
|
||||
// Set the current material as the one to be activated (needed to force the UI update)
|
||||
base.newRootMaterialIdToSwitchTo = base.currentItem.root_material_id
|
||||
const extruder_position = Cura.ExtruderManager.activeExtruderIndex
|
||||
Cura.MachineManager.setMaterial(extruder_position, base.currentItem.container_node)
|
||||
}
|
||||
}
|
||||
|
||||
// Create button
|
||||
Button
|
||||
buttons: [
|
||||
Cura.SecondaryButton
|
||||
{
|
||||
id: createMenuButton
|
||||
text: catalog.i18nc("@action:button", "Create")
|
||||
icon.name: "list-add"
|
||||
text: catalog.i18nc("@action:button", "Create new")
|
||||
enabled: Cura.MachineManager.activeMachine.hasMaterials
|
||||
onClicked:
|
||||
{
|
||||
|
|
@ -132,72 +82,22 @@ Item
|
|||
base.newRootMaterialIdToSwitchTo = base.materialManagementModel.createMaterial();
|
||||
base.toActivateNewMaterial = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Duplicate button
|
||||
Button
|
||||
{
|
||||
id: duplicateMenuButton
|
||||
text: catalog.i18nc("@action:button", "Duplicate");
|
||||
icon.name: "list-add"
|
||||
enabled: base.hasCurrentItem
|
||||
onClicked:
|
||||
{
|
||||
forceActiveFocus();
|
||||
base.newRootMaterialIdToSwitchTo = base.materialManagementModel.duplicateMaterial(base.currentItem.container_node);
|
||||
base.toActivateNewMaterial = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove button
|
||||
Button
|
||||
{
|
||||
id: removeMenuButton
|
||||
text: catalog.i18nc("@action:button", "Remove")
|
||||
icon.name: "list-remove"
|
||||
enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated && base.materialManagementModel.canMaterialBeRemoved(base.currentItem.container_node)
|
||||
|
||||
onClicked:
|
||||
{
|
||||
forceActiveFocus();
|
||||
confirmRemoveMaterialDialog.open();
|
||||
}
|
||||
}
|
||||
|
||||
// Import button
|
||||
Button
|
||||
},
|
||||
Cura.SecondaryButton
|
||||
{
|
||||
id: importMenuButton
|
||||
text: catalog.i18nc("@action:button", "Import")
|
||||
icon.name: "document-import"
|
||||
onClicked:
|
||||
{
|
||||
forceActiveFocus();
|
||||
importMaterialDialog.open();
|
||||
}
|
||||
enabled: Cura.MachineManager.activeMachine.hasMaterials
|
||||
}
|
||||
|
||||
// Export button
|
||||
Button
|
||||
{
|
||||
id: exportMenuButton
|
||||
text: catalog.i18nc("@action:button", "Export")
|
||||
icon.name: "document-export"
|
||||
onClicked:
|
||||
{
|
||||
forceActiveFocus();
|
||||
exportMaterialDialog.open();
|
||||
}
|
||||
enabled: base.hasCurrentItem
|
||||
}
|
||||
|
||||
//Sync button.
|
||||
Button
|
||||
},
|
||||
Cura.SecondaryButton
|
||||
{
|
||||
id: syncMaterialsButton
|
||||
text: catalog.i18nc("@action:button Sending materials to printers", "Sync with Printers")
|
||||
icon.name: "sync-synchronizing"
|
||||
text: catalog.i18nc("@action:button", "Sync with Printers")
|
||||
onClicked:
|
||||
{
|
||||
forceActiveFocus();
|
||||
|
|
@ -205,181 +105,176 @@ Item
|
|||
}
|
||||
visible: Cura.MachineManager.activeMachine.supportsMaterialExport
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Item
|
||||
onHamburgeButtonClicked: menu.popup(content_item, content_item.width - menu.width, hamburger_button.height)
|
||||
|
||||
listContent: ScrollView
|
||||
{
|
||||
id: contentsItem
|
||||
anchors
|
||||
{
|
||||
top: titleLabel.bottom
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
margins: 5 * screenScaleFactor
|
||||
bottomMargin: 0
|
||||
}
|
||||
id: materialScrollView
|
||||
anchors.fill: parent
|
||||
anchors.margins: parent.border.width
|
||||
width: (parent.width * 0.4) | 0
|
||||
|
||||
clip: true
|
||||
}
|
||||
|
||||
Item
|
||||
{
|
||||
anchors
|
||||
ScrollBar.vertical: UM.ScrollBar
|
||||
{
|
||||
top: buttonRow.bottom
|
||||
topMargin: UM.Theme.getSize("default_margin").height
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
}
|
||||
|
||||
SystemPalette { id: palette }
|
||||
|
||||
Label
|
||||
{
|
||||
id: captionLabel
|
||||
id: materialScrollBar
|
||||
parent: materialScrollView
|
||||
anchors
|
||||
{
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
}
|
||||
visible: text != ""
|
||||
text:
|
||||
{
|
||||
var caption = catalog.i18nc("@action:label", "Printer") + ": " + Cura.MachineManager.activeMachine.name;
|
||||
if (Cura.MachineManager.activeMachine.hasVariants)
|
||||
{
|
||||
var activeVariantName = ""
|
||||
if(Cura.MachineManager.activeStack != null)
|
||||
{
|
||||
activeVariantName = Cura.MachineManager.activeStack.variant.name
|
||||
}
|
||||
caption += ", " + Cura.MachineManager.activeDefinitionVariantsName + ": " + activeVariantName;
|
||||
}
|
||||
return caption;
|
||||
}
|
||||
width: materialScrollView.width
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
ScrollView
|
||||
{
|
||||
id: materialScrollView
|
||||
anchors
|
||||
{
|
||||
top: captionLabel.visible ? captionLabel.bottom : parent.top
|
||||
topMargin: captionLabel.visible ? UM.Theme.getSize("default_margin").height : 0
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
left: parent.left
|
||||
}
|
||||
width: (parent.width * 0.4) | 0
|
||||
}
|
||||
contentHeight: materialListView.height //For some reason, this is not determined automatically with this ScrollView. Very weird!
|
||||
|
||||
clip: true
|
||||
ScrollBar.vertical: UM.ScrollBar
|
||||
MaterialsList
|
||||
{
|
||||
id: materialListView
|
||||
width: materialScrollView.width - materialScrollBar.width
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Item
|
||||
{
|
||||
id: content_item
|
||||
anchors.fill: parent
|
||||
|
||||
Cura.Menu
|
||||
{
|
||||
id: menu
|
||||
Cura.MenuItem
|
||||
{
|
||||
id: materialScrollBar
|
||||
parent: materialScrollView
|
||||
anchors
|
||||
id: activateMenuButton
|
||||
text: catalog.i18nc("@action:button", "Activate")
|
||||
onClicked:
|
||||
{
|
||||
top: parent.top
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
forceActiveFocus()
|
||||
|
||||
// Set the current material as the one to be activated (needed to force the UI update)
|
||||
base.newRootMaterialIdToSwitchTo = base.currentItem.root_material_id
|
||||
const extruder_position = Cura.ExtruderManager.activeExtruderIndex
|
||||
Cura.MachineManager.setMaterial(extruder_position, base.currentItem.container_node)
|
||||
}
|
||||
}
|
||||
contentHeight: materialListView.height //For some reason, this is not determined automatically with this ScrollView. Very weird!
|
||||
|
||||
MaterialsList
|
||||
Cura.MenuItem
|
||||
{
|
||||
id: materialListView
|
||||
width: materialScrollView.width - materialScrollBar.width
|
||||
id: duplicateMenuButton
|
||||
text: catalog.i18nc("@action:button", "Duplicate");
|
||||
enabled: base.hasCurrentItem
|
||||
onClicked:
|
||||
{
|
||||
forceActiveFocus();
|
||||
base.newRootMaterialIdToSwitchTo = base.materialManagementModel.duplicateMaterial(base.currentItem.container_node);
|
||||
base.toActivateNewMaterial = true;
|
||||
}
|
||||
}
|
||||
Cura.MenuItem
|
||||
{
|
||||
id: removeMenuButton
|
||||
text: catalog.i18nc("@action:button", "Remove")
|
||||
enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated && base.materialManagementModel.canMaterialBeRemoved(base.currentItem.container_node)
|
||||
|
||||
onClicked:
|
||||
{
|
||||
forceActiveFocus();
|
||||
confirmRemoveMaterialDialog.open();
|
||||
}
|
||||
}
|
||||
Cura.MenuItem
|
||||
{
|
||||
id: exportMenuButton
|
||||
text: catalog.i18nc("@action:button", "Export")
|
||||
onClicked:
|
||||
{
|
||||
forceActiveFocus();
|
||||
exportMaterialDialog.open();
|
||||
}
|
||||
enabled: base.hasCurrentItem
|
||||
}
|
||||
}
|
||||
|
||||
MaterialsDetailsPanel
|
||||
{
|
||||
id: materialDetailsPanel
|
||||
anchors
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
// Dialogs
|
||||
Cura.MessageDialog
|
||||
{
|
||||
id: confirmRemoveMaterialDialog
|
||||
title: catalog.i18nc("@title:window", "Confirm Remove")
|
||||
property string materialName: base.currentItem !== null ? base.currentItem.name : ""
|
||||
|
||||
text: catalog.i18nc("@label (%1 is object name)", "Are you sure you wish to remove %1? This cannot be undone!").arg(materialName)
|
||||
standardButtons: Dialog.Yes | Dialog.No
|
||||
onAccepted:
|
||||
{
|
||||
left: materialScrollView.right
|
||||
leftMargin: UM.Theme.getSize("default_margin").width
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
right: parent.right
|
||||
// Set the active material as the fallback. It will be selected when the current material is deleted
|
||||
base.newRootMaterialIdToSwitchTo = base.active_root_material_id
|
||||
base.materialManagementModel.removeMaterial(base.currentItem.container_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dialogs
|
||||
Cura.MessageDialog
|
||||
{
|
||||
id: confirmRemoveMaterialDialog
|
||||
title: catalog.i18nc("@title:window", "Confirm Remove")
|
||||
property string materialName: base.currentItem !== null ? base.currentItem.name : ""
|
||||
|
||||
text: catalog.i18nc("@label (%1 is object name)", "Are you sure you wish to remove %1? This cannot be undone!").arg(materialName)
|
||||
standardButtons: Dialog.Yes | Dialog.No
|
||||
onAccepted:
|
||||
FileDialog
|
||||
{
|
||||
// Set the active material as the fallback. It will be selected when the current material is deleted
|
||||
base.newRootMaterialIdToSwitchTo = base.active_root_material_id
|
||||
base.materialManagementModel.removeMaterial(base.currentItem.container_node);
|
||||
}
|
||||
}
|
||||
|
||||
FileDialog
|
||||
{
|
||||
id: importMaterialDialog
|
||||
title: catalog.i18nc("@title:window", "Import Material")
|
||||
selectExisting: true
|
||||
nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
|
||||
folder: CuraApplication.getDefaultPath("dialog_material_path")
|
||||
onAccepted:
|
||||
{
|
||||
const result = Cura.ContainerManager.importMaterialContainer(fileUrl);
|
||||
|
||||
const messageDialog = Qt.createQmlObject("import Cura 1.5 as Cura; Cura.MessageDialog { onClosed: destroy() }", base);
|
||||
messageDialog.standardButtons = Dialog.Ok;
|
||||
messageDialog.title = catalog.i18nc("@title:window", "Import Material");
|
||||
switch (result.status)
|
||||
id: importMaterialDialog
|
||||
title: catalog.i18nc("@title:window", "Import Material")
|
||||
selectExisting: true
|
||||
nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
|
||||
folder: CuraApplication.getDefaultPath("dialog_material_path")
|
||||
onAccepted:
|
||||
{
|
||||
case "success":
|
||||
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag <filename>!", "Successfully imported material <filename>%1</filename>").arg(fileUrl);
|
||||
break;
|
||||
default:
|
||||
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message);
|
||||
break;
|
||||
const result = Cura.ContainerManager.importMaterialContainer(fileUrl);
|
||||
|
||||
const messageDialog = Qt.createQmlObject("import Cura 1.5 as Cura; Cura.MessageDialog { onClosed: destroy() }", base);
|
||||
messageDialog.standardButtons = Dialog.Ok;
|
||||
messageDialog.title = catalog.i18nc("@title:window", "Import Material");
|
||||
switch (result.status)
|
||||
{
|
||||
case "success":
|
||||
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag <filename>!", "Successfully imported material <filename>%1</filename>").arg(fileUrl);
|
||||
break;
|
||||
default:
|
||||
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message);
|
||||
break;
|
||||
}
|
||||
messageDialog.open();
|
||||
CuraApplication.setDefaultPath("dialog_material_path", folder);
|
||||
}
|
||||
messageDialog.open();
|
||||
CuraApplication.setDefaultPath("dialog_material_path", folder);
|
||||
}
|
||||
}
|
||||
|
||||
FileDialog
|
||||
{
|
||||
id: exportMaterialDialog
|
||||
title: catalog.i18nc("@title:window", "Export Material")
|
||||
selectExisting: false
|
||||
nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
|
||||
folder: CuraApplication.getDefaultPath("dialog_material_path")
|
||||
onAccepted:
|
||||
FileDialog
|
||||
{
|
||||
const result = Cura.ContainerManager.exportContainer(base.currentItem.root_material_id, selectedNameFilter, fileUrl);
|
||||
|
||||
const messageDialog = Qt.createQmlObject("import Cura 1.5 as Cura; Cura.MessageDialog { onClosed: destroy() }", base);
|
||||
messageDialog.title = catalog.i18nc("@title:window", "Export Material");
|
||||
messageDialog.standardButtons = Dialog.Ok;
|
||||
switch (result.status)
|
||||
id: exportMaterialDialog
|
||||
title: catalog.i18nc("@title:window", "Export Material")
|
||||
selectExisting: false
|
||||
nameFilters: Cura.ContainerManager.getContainerNameFilters("material")
|
||||
folder: CuraApplication.getDefaultPath("dialog_material_path")
|
||||
onAccepted:
|
||||
{
|
||||
case "error":
|
||||
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> and <message>!", "Failed to export material to <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message);
|
||||
break;
|
||||
case "success":
|
||||
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag <filename>!", "Successfully exported material to <filename>%1</filename>").arg(result.path);
|
||||
break;
|
||||
}
|
||||
messageDialog.open();
|
||||
const result = Cura.ContainerManager.exportContainer(base.currentItem.root_material_id, selectedNameFilter, fileUrl);
|
||||
|
||||
CuraApplication.setDefaultPath("dialog_material_path", folder);
|
||||
const messageDialog = Qt.createQmlObject("import Cura 1.5 as Cura; Cura.MessageDialog { onClosed: destroy() }", base);
|
||||
messageDialog.title = catalog.i18nc("@title:window", "Export Material");
|
||||
messageDialog.standardButtons = Dialog.Ok;
|
||||
switch (result.status)
|
||||
{
|
||||
case "error":
|
||||
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> and <message>!", "Failed to export material to <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message);
|
||||
break;
|
||||
case "success":
|
||||
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag <filename>!", "Successfully exported material to <filename>%1</filename>").arg(result.path);
|
||||
break;
|
||||
}
|
||||
messageDialog.open();
|
||||
|
||||
CuraApplication.setDefaultPath("dialog_material_path", folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue