ContextMenu.qml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. Cura.MenuItem { action: Cura.Actions.dropAll }
  65. // Group actions
  66. Cura.MenuSeparator {}
  67. Cura.MenuItem { action: Cura.Actions.groupObjects }
  68. Cura.MenuItem { action: Cura.Actions.mergeObjects }
  69. Cura.MenuItem { action: Cura.Actions.unGroupObjects }
  70. // Edit print sequence actions
  71. Cura.MenuSeparator { visible: PrintOrderManager.shouldShowEditPrintOrderActions }
  72. Cura.MenuItem
  73. {
  74. action: Cura.Actions.printObjectBeforePrevious
  75. visible: PrintOrderManager.shouldShowEditPrintOrderActions
  76. }
  77. Cura.MenuItem
  78. {
  79. action: Cura.Actions.printObjectAfterNext
  80. visible: PrintOrderManager.shouldShowEditPrintOrderActions
  81. }
  82. Connections
  83. {
  84. target: UM.Controller
  85. function onContextMenuRequested() { base.popup() }
  86. }
  87. Connections
  88. {
  89. target: Cura.Actions.multiplySelection
  90. function onTriggered() { multiplyDialog.open() }
  91. }
  92. UM.SettingPropertyProvider
  93. {
  94. id: machineExtruderCount
  95. containerStack: Cura.MachineManager.activeMachine
  96. key: "machine_extruder_count"
  97. watchedProperties: [ "value" ]
  98. }
  99. UM.Dialog
  100. {
  101. id: multiplyDialog
  102. title: catalog.i18ncp("@title:window", "Multiply Selected Model", "Multiply Selected Models", UM.Selection.selectionCount)
  103. width: UM.Theme.getSize("small_popup_dialog").width
  104. height: UM.Theme.getSize("small_popup_dialog").height
  105. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  106. minimumHeight: UM.Theme.getSize("small_popup_dialog").height
  107. onAccepted: gridPlacementSelected.checked? CuraActions.multiplySelectionToGrid(copiesField.value) : CuraActions.multiplySelection(copiesField.value)
  108. buttonSpacing: UM.Theme.getSize("thin_margin").width
  109. rightButtons:
  110. [
  111. Cura.SecondaryButton
  112. {
  113. text: "Cancel"
  114. onClicked: multiplyDialog.reject()
  115. },
  116. Cura.PrimaryButton
  117. {
  118. text: "Ok"
  119. onClicked: multiplyDialog.accept()
  120. }
  121. ]
  122. Column
  123. {
  124. spacing: UM.Theme.getSize("default_margin").height
  125. Row
  126. {
  127. spacing: UM.Theme.getSize("default_margin").width
  128. UM.Label
  129. {
  130. text: catalog.i18nc("@label", "Number of Copies")
  131. anchors.verticalCenter: copiesField.verticalCenter
  132. width: contentWidth
  133. wrapMode: Text.NoWrap
  134. }
  135. Cura.SpinBox
  136. {
  137. id: copiesField
  138. editable: true
  139. focus: true
  140. from: 1
  141. to: 99
  142. width: 2 * UM.Theme.getSize("button").width
  143. value: 1
  144. }
  145. }
  146. UM.CheckBox
  147. {
  148. id: gridPlacementSelected
  149. text: catalog.i18nc("@label", "Grid Placement")
  150. UM.ToolTip
  151. {
  152. visible: parent.hovered
  153. targetPoint: Qt.point(parent.x + Math.round(parent.width / 2), parent.y)
  154. x: 0
  155. y: parent.y + parent.height + UM.Theme.getSize("default_margin").height
  156. tooltipText: catalog.i18nc("@info", "Multiply selected item and place them in a grid of build plate.")
  157. }
  158. }
  159. }
  160. }
  161. }