ContextMenu.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.2
  5. import QtQuick.Dialogs 1.2
  6. import QtQuick.Window 2.1
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. Menu
  10. {
  11. id: base
  12. property bool shouldShowExtruders: machineExtruderCount.properties.value > 1;
  13. property var multiBuildPlateModel: CuraApplication.getMultiBuildPlateModel()
  14. // Selection-related actions.
  15. MenuItem { action: Cura.Actions.centerSelection; }
  16. MenuItem { action: Cura.Actions.deleteSelection; }
  17. MenuItem { action: Cura.Actions.multiplySelection; }
  18. // Extruder selection - only visible if there is more than 1 extruder
  19. MenuSeparator { visible: base.shouldShowExtruders }
  20. MenuItem { id: extruderHeader; text: catalog.i18ncp("@label", "Print Selected Model With:", "Print Selected Models With:", UM.Selection.selectionCount); enabled: false; visible: base.shouldShowExtruders }
  21. Instantiator
  22. {
  23. model: CuraApplication.getExtrudersModel()
  24. MenuItem {
  25. text: "%1: %2 - %3".arg(model.name).arg(model.material).arg(model.variant)
  26. visible: base.shouldShowExtruders
  27. enabled: UM.Selection.hasSelection && model.enabled
  28. checkable: true
  29. checked: Cura.ExtruderManager.selectedObjectExtruders.indexOf(model.id) != -1
  30. onTriggered: CuraActions.setExtruderForSelection(model.id)
  31. shortcut: "Ctrl+" + (model.index + 1)
  32. }
  33. onObjectAdded: base.insertItem(index, object)
  34. onObjectRemoved: base.removeItem(object)
  35. }
  36. MenuSeparator {
  37. visible: UM.Preferences.getValue("cura/use_multi_build_plate")
  38. }
  39. Instantiator
  40. {
  41. model: base.multiBuildPlateModel
  42. MenuItem {
  43. enabled: UM.Selection.hasSelection
  44. text: base.multiBuildPlateModel.getItem(index).name;
  45. onTriggered: CuraActions.setBuildPlateForSelection(base.multiBuildPlateModel.getItem(index).buildPlateNumber);
  46. checkable: true
  47. checked: base.multiBuildPlateModel.selectionBuildPlates.indexOf(base.multiBuildPlateModel.getItem(index).buildPlateNumber) != -1;
  48. visible: UM.Preferences.getValue("cura/use_multi_build_plate")
  49. }
  50. onObjectAdded: base.insertItem(index, object);
  51. onObjectRemoved: base.removeItem(object);
  52. }
  53. MenuItem {
  54. enabled: UM.Selection.hasSelection
  55. text: "New build plate";
  56. onTriggered: {
  57. CuraActions.setBuildPlateForSelection(base.multiBuildPlateModel.maxBuildPlate + 1);
  58. checked = false;
  59. }
  60. checkable: true
  61. checked: false
  62. visible: UM.Preferences.getValue("cura/use_multi_build_plate")
  63. }
  64. // Global actions
  65. MenuSeparator {}
  66. MenuItem { action: Cura.Actions.selectAll; }
  67. MenuItem { action: Cura.Actions.arrangeAll; }
  68. MenuItem { action: Cura.Actions.deleteAll; }
  69. MenuItem { action: Cura.Actions.reloadAll; }
  70. MenuItem { action: Cura.Actions.resetAllTranslation; }
  71. MenuItem { action: Cura.Actions.resetAll; }
  72. // Group actions
  73. MenuSeparator {}
  74. MenuItem { action: Cura.Actions.groupObjects; }
  75. MenuItem { action: Cura.Actions.mergeObjects; }
  76. MenuItem { action: Cura.Actions.unGroupObjects; }
  77. Connections
  78. {
  79. target: UM.Controller
  80. function onContextMenuRequested() { base.popup(); }
  81. }
  82. Connections
  83. {
  84. target: Cura.Actions.multiplySelection
  85. function onTriggered() { multiplyDialog.open() }
  86. }
  87. UM.SettingPropertyProvider
  88. {
  89. id: machineExtruderCount
  90. containerStack: Cura.MachineManager.activeMachine
  91. key: "machine_extruder_count"
  92. watchedProperties: [ "value" ]
  93. }
  94. Dialog
  95. {
  96. id: multiplyDialog
  97. modality: Qt.ApplicationModal
  98. title: catalog.i18ncp("@title:window", "Multiply Selected Model", "Multiply Selected Models", UM.Selection.selectionCount)
  99. onAccepted: CuraActions.multiplySelection(copiesField.value)
  100. signal reset()
  101. onReset:
  102. {
  103. copiesField.value = 1;
  104. copiesField.focus = true;
  105. }
  106. onVisibleChanged:
  107. {
  108. copiesField.forceActiveFocus();
  109. }
  110. standardButtons: StandardButton.Ok | StandardButton.Cancel
  111. Row
  112. {
  113. spacing: UM.Theme.getSize("default_margin").width
  114. Label
  115. {
  116. text: catalog.i18nc("@label", "Number of Copies")
  117. anchors.verticalCenter: copiesField.verticalCenter
  118. }
  119. SpinBox
  120. {
  121. id: copiesField
  122. focus: true
  123. minimumValue: 1
  124. maximumValue: 99
  125. }
  126. }
  127. }
  128. // Find the index of an item in the list of child items of this menu.
  129. //
  130. // This is primarily intended as a helper function so we do not have to
  131. // hard-code the position of the extruder selection actions.
  132. //
  133. // \param item The item to find the index of.
  134. //
  135. // \return The index of the item or -1 if it was not found.
  136. function findItemIndex(item)
  137. {
  138. for(var i in base.items)
  139. {
  140. if(base.items[i] == item)
  141. {
  142. return i;
  143. }
  144. }
  145. return -1;
  146. }
  147. UM.I18nCatalog { id: catalog; name: "cura" }
  148. }