MaterialMenu.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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(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. Instantiator
  69. {
  70. model: genericMaterialsModel
  71. delegate: Cura.MenuItem
  72. {
  73. text: model.name
  74. checkable: true
  75. enabled: isActiveExtruderEnabled
  76. checked: model.root_material_id === materialMenu.currentRootMaterialId
  77. onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node)
  78. }
  79. onObjectAdded: function(index, object) { genericMenu.insertItem(index, object)}
  80. onObjectRemoved: function(object) {genericMenu.removeItem(index) }
  81. }
  82. }
  83. Cura.MenuSeparator {}
  84. Instantiator
  85. {
  86. model: brandModel
  87. delegate: Cura.MaterialBrandMenu
  88. {
  89. materialTypesModel: model
  90. }
  91. onObjectAdded: function(index, object) { materialMenu.insertItem(index + 4, object)}
  92. onObjectRemoved: function(object) { materialMenu.removeItem(index) }
  93. }
  94. Cura.MenuSeparator {}
  95. Cura.MenuItem
  96. {
  97. action: Cura.Actions.manageMaterials
  98. }
  99. Cura.MenuSeparator {}
  100. Cura.MenuItem
  101. {
  102. action: Cura.Actions.marketplaceMaterials
  103. }
  104. }