ContextMenu.qml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // Copyright (c) 2022 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.1
  5. import QtQuick.Window 2.1
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. Cura.Menu
  9. {
  10. id: base
  11. property bool shouldShowExtruders: machineExtruderCount.properties.value > 1;
  12. property var multiBuildPlateModel: CuraApplication.getMultiBuildPlateModel()
  13. // Selection-related actions.
  14. Cura.MenuItem { action: Cura.Actions.centerSelection; }
  15. Cura.MenuItem { action: Cura.Actions.deleteSelection; }
  16. Cura.MenuItem { action: Cura.Actions.copy; }
  17. Cura.MenuItem { action: Cura.Actions.paste; }
  18. Cura.MenuItem { action: Cura.Actions.multiplySelection; }
  19. // Extruder selection - only visible if there is more than 1 extruder
  20. Cura.MenuSeparator { visible: base.shouldShowExtruders }
  21. Cura.MenuItem
  22. {
  23. id: extruderHeader
  24. text: catalog.i18ncp("@label", "Print Selected Model With:", "Print Selected Models With:", UM.Selection.selectionCount)
  25. enabled: false
  26. visible: base.shouldShowExtruders
  27. }
  28. Instantiator
  29. {
  30. model: CuraApplication.getExtrudersModel()
  31. Cura.MenuItem
  32. {
  33. text: "%1: %2 - %3".arg(model.name).arg(model.material).arg(model.variant)
  34. visible: base.shouldShowExtruders
  35. enabled: UM.Selection.hasSelection && model.enabled
  36. checkable: true
  37. checked: Cura.ExtruderManager.selectedObjectExtruders.indexOf(model.id) != -1
  38. onTriggered: CuraActions.setExtruderForSelection(model.id)
  39. shortcut: "Ctrl+" + (model.index + 1)
  40. }
  41. onObjectAdded: function(index, object) {
  42. var extruder_header_location = 5;
  43. // Find the location of the extruder header and insert it below that.
  44. for (var i = 0; i < base.count; i++)
  45. {
  46. if(base.itemAt(i) === extruderHeader)
  47. {
  48. extruder_header_location = i + 1;
  49. }
  50. }
  51. base.insertItem(extruder_header_location + index, object)
  52. }
  53. onObjectRemoved: function(index, object) { base.removeItem(object) }
  54. }
  55. // Global actions
  56. Cura.MenuSeparator {}
  57. Cura.MenuItem { action: Cura.Actions.selectAll }
  58. Cura.MenuItem { action: Cura.Actions.arrangeAll }
  59. Cura.MenuItem { action: Cura.Actions.arrangeAllGrid }
  60. Cura.MenuItem { action: Cura.Actions.deleteAll }
  61. Cura.MenuItem { action: Cura.Actions.reloadAll }
  62. Cura.MenuItem { action: Cura.Actions.resetAllTranslation }
  63. Cura.MenuItem { action: Cura.Actions.resetAll }
  64. // Group actions
  65. Cura.MenuSeparator {}
  66. Cura.MenuItem { action: Cura.Actions.groupObjects }
  67. Cura.MenuItem { action: Cura.Actions.mergeObjects }
  68. Cura.MenuItem { action: Cura.Actions.unGroupObjects }
  69. // Edit print sequence actions
  70. Cura.MenuSeparator { visible: PrintOrderManager.shouldShowEditPrintOrderActions }
  71. Cura.MenuItem
  72. {
  73. action: Cura.Actions.printObjectBeforePrevious
  74. visible: PrintOrderManager.shouldShowEditPrintOrderActions
  75. }
  76. Cura.MenuItem
  77. {
  78. action: Cura.Actions.printObjectAfterNext
  79. visible: PrintOrderManager.shouldShowEditPrintOrderActions
  80. }
  81. Connections
  82. {
  83. target: UM.Controller
  84. function onContextMenuRequested() { base.popup() }
  85. }
  86. Connections
  87. {
  88. target: Cura.Actions.multiplySelection
  89. function onTriggered() { multiplyDialog.open() }
  90. }
  91. UM.SettingPropertyProvider
  92. {
  93. id: machineExtruderCount
  94. containerStack: Cura.MachineManager.activeMachine
  95. key: "machine_extruder_count"
  96. watchedProperties: [ "value" ]
  97. }
  98. UM.Dialog
  99. {
  100. id: multiplyDialog
  101. title: catalog.i18ncp("@title:window", "Multiply Selected Model", "Multiply Selected Models", UM.Selection.selectionCount)
  102. width: UM.Theme.getSize("small_popup_dialog").width
  103. height: UM.Theme.getSize("small_popup_dialog").height
  104. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  105. minimumHeight: UM.Theme.getSize("small_popup_dialog").height
  106. onAccepted: gridPlacementSelected.checked? CuraActions.multiplySelectionToGrid(copiesField.value) : CuraActions.multiplySelection(copiesField.value)
  107. buttonSpacing: UM.Theme.getSize("thin_margin").width
  108. rightButtons:
  109. [
  110. Cura.SecondaryButton
  111. {
  112. text: "Cancel"
  113. onClicked: multiplyDialog.reject()
  114. },
  115. Cura.PrimaryButton
  116. {
  117. text: "Ok"
  118. onClicked: multiplyDialog.accept()
  119. }
  120. ]
  121. Column
  122. {
  123. spacing: UM.Theme.getSize("default_margin").height
  124. Row
  125. {
  126. spacing: UM.Theme.getSize("default_margin").width
  127. UM.Label
  128. {
  129. text: catalog.i18nc("@label", "Number of Copies")
  130. anchors.verticalCenter: copiesField.verticalCenter
  131. width: contentWidth
  132. wrapMode: Text.NoWrap
  133. }
  134. Cura.SpinBox
  135. {
  136. id: copiesField
  137. editable: true
  138. focus: true
  139. from: 1
  140. to: 99
  141. width: 2 * UM.Theme.getSize("button").width
  142. value: 1
  143. }
  144. }
  145. UM.CheckBox
  146. {
  147. id: gridPlacementSelected
  148. text: catalog.i18nc("@label", "Grid Placement")
  149. UM.ToolTip
  150. {
  151. visible: parent.hovered
  152. targetPoint: Qt.point(parent.x + Math.round(parent.width / 2), parent.y)
  153. x: 0
  154. y: parent.y + parent.height + UM.Theme.getSize("default_margin").height
  155. tooltipText: catalog.i18nc("@info", "Multiply selected item and place them in a grid of build plate.")
  156. }
  157. }
  158. }
  159. }
  160. }