MaterialMenu.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //Copyright (c) 2020 Ultimaker B.V.
  2. //Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 1.4
  5. import UM 1.2 as UM
  6. import Cura 1.0 as Cura
  7. Menu
  8. {
  9. id: menu
  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) ? false : activeExtruder.material.id
  24. property bool updateModels: true
  25. Cura.FavoriteMaterialsModel
  26. {
  27. id: favoriteMaterialsModel
  28. extruderPosition: menu.extruderIndex
  29. enabled: updateModels
  30. }
  31. Cura.GenericMaterialsModel
  32. {
  33. id: genericMaterialsModel
  34. extruderPosition: menu.extruderIndex
  35. enabled: updateModels
  36. }
  37. Cura.MaterialBrandsModel
  38. {
  39. id: brandModel
  40. extruderPosition: menu.extruderIndex
  41. enabled: updateModels
  42. }
  43. 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: MenuItem
  53. {
  54. text: model.brand + " " + model.name
  55. checkable: true
  56. enabled: isActiveExtruderEnabled
  57. checked: model.root_material_id === menu.currentRootMaterialId
  58. onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node)
  59. exclusiveGroup: favoriteGroup // One favorite and one item from the others can be active at the same time.
  60. }
  61. onObjectAdded: menu.insertItem(index, object)
  62. onObjectRemoved: menu.removeItem(index)
  63. }
  64. MenuSeparator {}
  65. Menu
  66. {
  67. id: genericMenu
  68. title: catalog.i18nc("@label:category menu label", "Generic")
  69. Instantiator
  70. {
  71. model: genericMaterialsModel
  72. delegate: MenuItem
  73. {
  74. text: model.name
  75. checkable: true
  76. enabled: isActiveExtruderEnabled
  77. checked: model.root_material_id === menu.currentRootMaterialId
  78. exclusiveGroup: group
  79. onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node)
  80. }
  81. onObjectAdded: genericMenu.insertItem(index, object)
  82. onObjectRemoved: genericMenu.removeItem(index)
  83. }
  84. }
  85. MenuSeparator {}
  86. Instantiator
  87. {
  88. model: brandModel
  89. Menu
  90. {
  91. id: brandMenu
  92. title: brandName
  93. property string brandName: model.name
  94. property var brandMaterials: model.material_types
  95. Instantiator
  96. {
  97. model: brandMaterials
  98. delegate: Menu
  99. {
  100. id: brandMaterialsMenu
  101. title: materialName
  102. property string materialName: model.name
  103. property var brandMaterialColors: model.colors
  104. Instantiator
  105. {
  106. model: brandMaterialColors
  107. delegate: MenuItem
  108. {
  109. text: model.name
  110. checkable: true
  111. enabled: isActiveExtruderEnabled
  112. checked: model.id === menu.activeMaterialId
  113. exclusiveGroup: group
  114. onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node)
  115. }
  116. onObjectAdded: brandMaterialsMenu.insertItem(index, object)
  117. onObjectRemoved: brandMaterialsMenu.removeItem(object)
  118. }
  119. }
  120. onObjectAdded: brandMenu.insertItem(index, object)
  121. onObjectRemoved: brandMenu.removeItem(object)
  122. }
  123. }
  124. onObjectAdded: menu.insertItem(index, object)
  125. onObjectRemoved: menu.removeItem(object)
  126. }
  127. ExclusiveGroup
  128. {
  129. id: group
  130. }
  131. ExclusiveGroup
  132. {
  133. id: favoriteGroup
  134. }
  135. MenuSeparator {}
  136. MenuItem
  137. {
  138. action: Cura.Actions.manageMaterials
  139. }
  140. MenuSeparator {}
  141. MenuItem
  142. {
  143. action: Cura.Actions.marketplaceMaterials
  144. }
  145. }