MaterialMenu.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.4
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. Cura.Menu
  8. {
  9. id: materialMenu
  10. title: catalog.i18nc("@label:category menu label", "Material")
  11. property int extruderIndex: 0
  12. property string currentRootMaterialId:
  13. {
  14. var value = Cura.MachineManager.currentRootMaterialId[extruderIndex]
  15. return (value === undefined) ? "" : value
  16. }
  17. property var activeExtruder:
  18. {
  19. var activeMachine = Cura.MachineManager.activeMachine
  20. return (activeMachine === null) ? null : activeMachine.extruderList[extruderIndex]
  21. }
  22. property bool isActiveExtruderEnabled: (activeExtruder === null || activeExtruder === undefined) ? false : activeExtruder.isEnabled
  23. property string activeMaterialId: (activeExtruder === null || activeExtruder === undefined) ? "" : activeExtruder.material.id
  24. property bool updateModels: true
  25. Cura.FavoriteMaterialsModel
  26. {
  27. id: favoriteMaterialsModel
  28. extruderPosition: materialMenu.extruderIndex
  29. enabled: updateModels
  30. }
  31. Cura.GenericMaterialsModel
  32. {
  33. id: genericMaterialsModel
  34. extruderPosition: materialMenu.extruderIndex
  35. enabled: updateModels
  36. }
  37. Cura.MaterialBrandsModel
  38. {
  39. id: brandModel
  40. extruderPosition: materialMenu.extruderIndex
  41. enabled: updateModels
  42. }
  43. Cura.MenuItem
  44. {
  45. text: catalog.i18nc("@label:category menu label", "Favorites")
  46. enabled: false
  47. visible: favoriteMaterialsModel.items.length > 0
  48. }
  49. Instantiator
  50. {
  51. model: favoriteMaterialsModel
  52. delegate: Cura.MenuItem
  53. {
  54. text: model.brand + " " + model.name
  55. checkable: true
  56. enabled: isActiveExtruderEnabled
  57. checked: model.root_material_id === materialMenu.currentRootMaterialId
  58. onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node)
  59. }
  60. onObjectAdded: function(index, object) { materialMenu.insertItem(index + 1, object) }
  61. onObjectRemoved: function(index, object) { materialMenu.removeItem(index) }
  62. }
  63. Cura.MenuSeparator { visible: favoriteMaterialsModel.items.length > 0}
  64. Cura.Menu
  65. {
  66. id: genericMenu
  67. title: catalog.i18nc("@label:category menu label", "Generic")
  68. enabled: genericMaterialsModel.items.length > 0
  69. Instantiator
  70. {
  71. model: genericMaterialsModel
  72. delegate: Cura.MenuItem
  73. {
  74. text: model.name
  75. checkable: true
  76. enabled: isActiveExtruderEnabled
  77. checked: model.root_material_id === materialMenu.currentRootMaterialId
  78. onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node)
  79. }
  80. onObjectAdded: function(index, object) { genericMenu.insertItem(index, object)}
  81. onObjectRemoved: function(index, object) {genericMenu.removeItem(index) }
  82. }
  83. }
  84. Cura.MenuSeparator {}
  85. Instantiator
  86. {
  87. model: brandModel
  88. delegate: Cura.MaterialBrandMenu
  89. {
  90. materialTypesModel: model
  91. }
  92. onObjectAdded: function(index, object) { materialMenu.insertItem(index + 4, object)}
  93. onObjectRemoved: function(index, object) { materialMenu.removeItem(index) }
  94. }
  95. Cura.MenuSeparator {}
  96. Cura.MenuItem
  97. {
  98. action: Cura.Actions.manageMaterials
  99. }
  100. Cura.MenuSeparator {}
  101. Cura.MenuItem
  102. {
  103. action: Cura.Actions.marketplaceMaterials
  104. }
  105. }