ContextMenu.qml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.multiplySelection; }
  17. // Extruder selection - only visible if there is more than 1 extruder
  18. Cura.MenuSeparator { visible: base.shouldShowExtruders }
  19. Cura.MenuItem
  20. {
  21. id: extruderHeader
  22. text: catalog.i18ncp("@label", "Print Selected Model With:", "Print Selected Models With:", UM.Selection.selectionCount)
  23. enabled: false
  24. visible: base.shouldShowExtruders
  25. }
  26. Instantiator
  27. {
  28. model: CuraApplication.getExtrudersModel()
  29. Cura.MenuItem
  30. {
  31. text: "%1: %2 - %3".arg(model.name).arg(model.material).arg(model.variant)
  32. visible: base.shouldShowExtruders
  33. enabled: UM.Selection.hasSelection && model.enabled
  34. checkable: true
  35. checked: Cura.ExtruderManager.selectedObjectExtruders.indexOf(model.id) != -1
  36. onTriggered: CuraActions.setExtruderForSelection(model.id)
  37. shortcut: "Ctrl+" + (model.index + 1)
  38. }
  39. onObjectAdded: function(index, object) {
  40. var extruder_header_location = 5;
  41. // Find the location of the extruder header and insert it below that.
  42. for (var i = 0; i < base.count; i++)
  43. {
  44. if(base.itemAt(i) === extruderHeader)
  45. {
  46. extruder_header_location = i + 1;
  47. }
  48. }
  49. base.insertItem(extruder_header_location + index, object)
  50. }
  51. onObjectRemoved: function(index, object) { base.removeItem(object) }
  52. }
  53. // Global actions
  54. Cura.MenuSeparator {}
  55. Cura.MenuItem { action: Cura.Actions.selectAll }
  56. Cura.MenuItem { action: Cura.Actions.arrangeAll }
  57. Cura.MenuItem { action: Cura.Actions.deleteAll }
  58. Cura.MenuItem { action: Cura.Actions.reloadAll }
  59. Cura.MenuItem { action: Cura.Actions.resetAllTranslation }
  60. Cura.MenuItem { action: Cura.Actions.resetAll }
  61. // Group actions
  62. Cura.MenuSeparator {}
  63. Cura.MenuItem { action: Cura.Actions.groupObjects }
  64. Cura.MenuItem { action: Cura.Actions.mergeObjects }
  65. Cura.MenuItem { action: Cura.Actions.unGroupObjects }
  66. Connections
  67. {
  68. target: UM.Controller
  69. function onContextMenuRequested() { base.popup() }
  70. }
  71. Connections
  72. {
  73. target: Cura.Actions.multiplySelection
  74. function onTriggered() { multiplyDialog.open() }
  75. }
  76. UM.SettingPropertyProvider
  77. {
  78. id: machineExtruderCount
  79. containerStack: Cura.MachineManager.activeMachine
  80. key: "machine_extruder_count"
  81. watchedProperties: [ "value" ]
  82. }
  83. UM.Dialog
  84. {
  85. id: multiplyDialog
  86. title: catalog.i18ncp("@title:window", "Multiply Selected Model", "Multiply Selected Models", UM.Selection.selectionCount)
  87. width: UM.Theme.getSize("small_popup_dialog").width
  88. height: UM.Theme.getSize("small_popup_dialog").height
  89. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  90. minimumHeight: UM.Theme.getSize("small_popup_dialog").height
  91. onAccepted: CuraActions.multiplySelection(copiesField.value)
  92. buttonSpacing: UM.Theme.getSize("thin_margin").width
  93. rightButtons:
  94. [
  95. Cura.SecondaryButton
  96. {
  97. text: "Cancel"
  98. onClicked: multiplyDialog.reject()
  99. },
  100. Cura.PrimaryButton
  101. {
  102. text: "Ok"
  103. onClicked: multiplyDialog.accept()
  104. }
  105. ]
  106. Row
  107. {
  108. spacing: UM.Theme.getSize("default_margin").width
  109. UM.Label
  110. {
  111. text: catalog.i18nc("@label", "Number of Copies")
  112. anchors.verticalCenter: copiesField.verticalCenter
  113. width: contentWidth
  114. wrapMode: Text.NoWrap
  115. }
  116. Cura.SpinBox
  117. {
  118. id: copiesField
  119. editable: true
  120. focus: true
  121. from: 1
  122. to: 99
  123. width: 2 * UM.Theme.getSize("button").width
  124. value: 1
  125. }
  126. }
  127. }
  128. }