1// Copyright (c) 2018 Ultimaker B.V. 2// Uranium is released under the terms of the LGPLv3 or higher. 3 4import QtQuick 2.7 5import QtQuick.Controls 1.4 6import QtQuick.Layouts 1.3 7import QtQuick.Dialogs 1.2 8 9import UM 1.2 as UM 10import Cura 1.0 as Cura 11 12Item 13{ 14 id: detailsPanel 15 16 property var currentItem: null 17 18 onCurrentItemChanged: 19 { 20 // When the current item changes, the detail view needs to be updated 21 if (currentItem != null) 22 { 23 updateMaterialPropertiesObject() 24 materialDetailsView.currentMaterialNode = currentItem.container_node 25 } 26 } 27 28 function updateMaterialPropertiesObject() 29 { 30 // DRAGON WARNING!!! DO NOT TOUCH THIS IF YOU DON'T KNOW. 31 // TL;DR: Always update "container_id" first! 32 // 33 // Other widgets such as MaterialsView have bindings towards "materialProperties" and its properties. Here the 34 // properties are updated one by one, and each change can trigger a reaction on those widgets that have 35 // connections to the property gets changed, and some reactions will use functions such as 36 // ContainerManager.getContainerMetaDataEntry() to fetch data using the "container_id" as the reference. 37 // We need to change "container_id" first so any underlying triggers will use the correct "container_id" to 38 // fetch data. Or, for example, if we change GUID first, which triggered the weight widget to fetch weight 39 // before we can update "container_id", so it will fetch weight with the wrong (old) "container_id". 40 materialProperties.container_id = currentItem.id 41 42 materialProperties.name = currentItem.name || "Unknown" 43 materialProperties.guid = currentItem.GUID 44 materialProperties.brand = currentItem.brand || "Unknown" 45 materialProperties.material = currentItem.material || "Unknown" 46 materialProperties.color_name = currentItem.color_name || "Yellow" 47 materialProperties.color_code = currentItem.color_code || "yellow" 48 materialProperties.description = currentItem.description || "" 49 materialProperties.adhesion_info = currentItem.adhesion_info || "" 50 materialProperties.density = currentItem.density || 0.0 51 materialProperties.diameter = currentItem.diameter || 0.0 52 materialProperties.approximate_diameter = currentItem.approximate_diameter || "0" 53 } 54 55 Item 56 { 57 anchors.fill: parent 58 59 Item // Material title Label 60 { 61 id: profileName 62 63 width: parent.width 64 height: childrenRect.height 65 66 Label { 67 width: parent.width 68 text: materialProperties.name 69 font: UM.Theme.getFont("large_bold") 70 elide: Text.ElideRight 71 } 72 } 73 74 MaterialsView // Material detailed information view below the title Label 75 { 76 id: materialDetailsView 77 anchors 78 { 79 left: parent.left 80 right: parent.right 81 top: profileName.bottom 82 topMargin: UM.Theme.getSize("default_margin").height 83 bottom: parent.bottom 84 } 85 86 editingEnabled: currentItem != null && !currentItem.is_read_only 87 onResetSelectedMaterial: base.resetExpandedActiveMaterial() 88 89 properties: materialProperties 90 containerId: currentItem != null ? currentItem.id : "" 91 currentMaterialNode: currentItem.container_node 92 } 93 94 QtObject 95 { 96 id: materialProperties 97 98 property string guid: "00000000-0000-0000-0000-000000000000" 99 property string container_id: "Unknown"; 100 property string name: "Unknown"; 101 property string profile_type: "Unknown"; 102 property string brand: "Unknown"; 103 property string material: "Unknown"; // This needs to be named as "material" to be consistent with 104 // the material container's metadata entry 105 106 property string color_name: "Yellow"; 107 property color color_code: "yellow"; 108 109 property real density: 0.0; 110 property real diameter: 0.0; 111 property string approximate_diameter: "0"; 112 113 property real spool_cost: 0.0; 114 property real spool_weight: 0.0; 115 property real spool_length: 0.0; 116 property real cost_per_meter: 0.0; 117 118 property string description: ""; 119 property string adhesion_info: ""; 120 } 121 } 122}