MaterialsDetailsPanel.qml 4.5 KB

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