ContextMenu.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.deleteAll }
  60. Cura.MenuItem { action: Cura.Actions.reloadAll }
  61. Cura.MenuItem { action: Cura.Actions.resetAllTranslation }
  62. Cura.MenuItem { action: Cura.Actions.resetAll }
  63. // Group actions
  64. Cura.MenuSeparator {}
  65. Cura.MenuItem { action: Cura.Actions.groupObjects }
  66. Cura.MenuItem { action: Cura.Actions.mergeObjects }
  67. Cura.MenuItem { action: Cura.Actions.unGroupObjects }
  68. Connections
  69. {
  70. target: UM.Controller
  71. function onContextMenuRequested() { base.popup() }
  72. }
  73. Connections
  74. {
  75. target: Cura.Actions.multiplySelection
  76. function onTriggered() { multiplyDialog.open() }
  77. }
  78. UM.SettingPropertyProvider
  79. {
  80. id: machineExtruderCount
  81. containerStack: Cura.MachineManager.activeMachine
  82. key: "machine_extruder_count"
  83. watchedProperties: [ "value" ]
  84. }
  85. UM.Dialog
  86. {
  87. id: multiplyDialog
  88. title: catalog.i18ncp("@title:window", "Multiply Selected Model", "Multiply Selected Models", UM.Selection.selectionCount)
  89. width: UM.Theme.getSize("small_popup_dialog").width
  90. height: UM.Theme.getSize("small_popup_dialog").height
  91. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  92. minimumHeight: UM.Theme.getSize("small_popup_dialog").height
  93. onAccepted: CuraActions.multiplySelection(copiesField.value)
  94. buttonSpacing: UM.Theme.getSize("thin_margin").width
  95. rightButtons:
  96. [
  97. Cura.SecondaryButton
  98. {
  99. text: "Cancel"
  100. onClicked: multiplyDialog.reject()
  101. },
  102. Cura.PrimaryButton
  103. {
  104. text: "Ok"
  105. onClicked: multiplyDialog.accept()
  106. }
  107. ]
  108. Row
  109. {
  110. spacing: UM.Theme.getSize("default_margin").width
  111. UM.Label
  112. {
  113. text: catalog.i18nc("@label", "Number of Copies")
  114. anchors.verticalCenter: copiesField.verticalCenter
  115. width: contentWidth
  116. wrapMode: Text.NoWrap
  117. }
  118. Cura.SpinBox
  119. {
  120. id: copiesField
  121. editable: true
  122. focus: true
  123. from: 1
  124. to: 99
  125. width: 2 * UM.Theme.getSize("button").width
  126. value: 1
  127. }
  128. }
  129. }
  130. }