MaterialMenu.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright (c) 2018 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: Cura.MachineManager.currentRootMaterialId[extruderIndex]
  13. property string activeMaterialId: Cura.MachineManager.allActiveMaterialIds[Cura.ExtruderManager.extruderIds[extruderIndex]]
  14. property bool updateModels: true
  15. Cura.FavoriteMaterialsModel
  16. {
  17. id: favoriteMaterialsModel
  18. extruderPosition: menu.extruderIndex
  19. enabled: updateModels
  20. }
  21. Cura.GenericMaterialsModel
  22. {
  23. id: genericMaterialsModel
  24. extruderPosition: menu.extruderIndex
  25. enabled: updateModels
  26. }
  27. Cura.MaterialBrandsModel
  28. {
  29. id: brandModel
  30. extruderPosition: menu.extruderIndex
  31. enabled: updateModels
  32. }
  33. MenuItem
  34. {
  35. text: catalog.i18nc("@label:category menu label", "Favorites")
  36. enabled: false
  37. visible: favoriteMaterialsModel.items.length > 0
  38. }
  39. Instantiator
  40. {
  41. model: favoriteMaterialsModel
  42. delegate: MenuItem
  43. {
  44. text: model.brand + " " + model.name
  45. checkable: true
  46. checked: model.root_material_id === menu.currentRootMaterialId
  47. onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node)
  48. exclusiveGroup: group
  49. }
  50. onObjectAdded: menu.insertItem(index, object)
  51. onObjectRemoved: menu.removeItem(object) // TODO: This ain't gonna work, removeItem() takes an index, not object
  52. }
  53. MenuSeparator {}
  54. Menu
  55. {
  56. id: genericMenu
  57. title: catalog.i18nc("@label:category menu label", "Generic")
  58. Instantiator
  59. {
  60. model: genericMaterialsModel
  61. delegate: MenuItem
  62. {
  63. text: model.name
  64. checkable: true
  65. checked: model.root_material_id === menu.currentRootMaterialId
  66. exclusiveGroup: group
  67. onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node)
  68. }
  69. onObjectAdded: genericMenu.insertItem(index, object)
  70. onObjectRemoved: genericMenu.removeItem(object) // TODO: This ain't gonna work, removeItem() takes an index, not object
  71. }
  72. }
  73. MenuSeparator {}
  74. Instantiator
  75. {
  76. model: brandModel
  77. Menu
  78. {
  79. id: brandMenu
  80. title: brandName
  81. property string brandName: model.name
  82. property var brandMaterials: model.material_types
  83. Instantiator
  84. {
  85. model: brandMaterials
  86. delegate: Menu
  87. {
  88. id: brandMaterialsMenu
  89. title: materialName
  90. property string materialName: model.name
  91. property var brandMaterialColors: model.colors
  92. Instantiator
  93. {
  94. model: brandMaterialColors
  95. delegate: MenuItem
  96. {
  97. text: model.name
  98. checkable: true
  99. checked: model.id === menu.activeMaterialId
  100. exclusiveGroup: group
  101. onTriggered: Cura.MachineManager.setMaterial(extruderIndex, model.container_node)
  102. }
  103. onObjectAdded: brandMaterialsMenu.insertItem(index, object)
  104. onObjectRemoved: brandMaterialsMenu.removeItem(object)
  105. }
  106. }
  107. onObjectAdded: brandMenu.insertItem(index, object)
  108. onObjectRemoved: brandMenu.removeItem(object)
  109. }
  110. }
  111. onObjectAdded: menu.insertItem(index, object)
  112. onObjectRemoved: menu.removeItem(object)
  113. }
  114. ExclusiveGroup {
  115. id: group
  116. }
  117. MenuSeparator {}
  118. MenuItem
  119. {
  120. action: Cura.Actions.manageMaterials
  121. }
  122. }