ContextMenu.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. // Add it to the fifth position (and above) as we want it to be added after the extruder header.
  40. onObjectAdded: function(index, object) { base.insertItem(index + 5, object) }
  41. onObjectRemoved: function(index, object) { base.removeItem(object) }
  42. }
  43. // Global actions
  44. Cura.MenuSeparator {}
  45. Cura.MenuItem { action: Cura.Actions.selectAll }
  46. Cura.MenuItem { action: Cura.Actions.arrangeAll }
  47. Cura.MenuItem { action: Cura.Actions.deleteAll }
  48. Cura.MenuItem { action: Cura.Actions.reloadAll }
  49. Cura.MenuItem { action: Cura.Actions.resetAllTranslation }
  50. Cura.MenuItem { action: Cura.Actions.resetAll }
  51. // Group actions
  52. Cura.MenuSeparator {}
  53. Cura.MenuItem { action: Cura.Actions.groupObjects }
  54. Cura.MenuItem { action: Cura.Actions.mergeObjects }
  55. Cura.MenuItem { action: Cura.Actions.unGroupObjects }
  56. Connections
  57. {
  58. target: UM.Controller
  59. function onContextMenuRequested() { base.popup() }
  60. }
  61. Connections
  62. {
  63. target: Cura.Actions.multiplySelection
  64. function onTriggered() { multiplyDialog.open() }
  65. }
  66. UM.SettingPropertyProvider
  67. {
  68. id: machineExtruderCount
  69. containerStack: Cura.MachineManager.activeMachine
  70. key: "machine_extruder_count"
  71. watchedProperties: [ "value" ]
  72. }
  73. UM.Dialog
  74. {
  75. id: multiplyDialog
  76. title: catalog.i18ncp("@title:window", "Multiply Selected Model", "Multiply Selected Models", UM.Selection.selectionCount)
  77. width: UM.Theme.getSize("small_popup_dialog").width
  78. height: UM.Theme.getSize("small_popup_dialog").height
  79. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  80. minimumHeight: UM.Theme.getSize("small_popup_dialog").height
  81. onAccepted: CuraActions.multiplySelection(copiesField.value)
  82. buttonSpacing: UM.Theme.getSize("thin_margin").width
  83. rightButtons:
  84. [
  85. Cura.SecondaryButton
  86. {
  87. text: "Cancel"
  88. onClicked: multiplyDialog.reject()
  89. },
  90. Cura.PrimaryButton
  91. {
  92. text: "Ok"
  93. onClicked: multiplyDialog.accept()
  94. }
  95. ]
  96. Row
  97. {
  98. spacing: UM.Theme.getSize("default_margin").width
  99. UM.Label
  100. {
  101. text: catalog.i18nc("@label", "Number of Copies")
  102. anchors.verticalCenter: copiesField.verticalCenter
  103. width: contentWidth
  104. wrapMode: Text.NoWrap
  105. }
  106. Cura.SpinBox
  107. {
  108. id: copiesField
  109. editable: true
  110. focus: true
  111. from: 1
  112. to: 99
  113. width: 2 * UM.Theme.getSize("button").width
  114. value: 1
  115. }
  116. }
  117. }
  118. }