ContextMenu.qml 5.2 KB

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