ContextMenu.qml 5.6 KB

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