MaterialMenu.qml 3.9 KB

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