ContextMenu.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Dialogs 1.2
  6. import QtQuick.Window 2.1
  7. import UM 1.2 as UM
  8. import Cura 1.2 as Cura
  9. Menu
  10. {
  11. id: base
  12. property bool shouldShowExtruders: machineExtruderCount.properties.value > 1;
  13. // Selection-related actions.
  14. MenuItem { action: Cura.Actions.centerSelection; }
  15. MenuItem { action: Cura.Actions.deleteSelection; }
  16. MenuItem { action: Cura.Actions.multiplySelection; }
  17. // Extruder selection - only visible if there is more than 1 extruder
  18. MenuSeparator { visible: base.shouldShowExtruders }
  19. MenuItem { id: extruderHeader; text: catalog.i18ncp("@label", "Print Selected Model With:", "Print Selected Models With:", UM.Selection.selectionCount); enabled: false; visible: base.shouldShowExtruders }
  20. Instantiator
  21. {
  22. model: Cura.ExtrudersModel { id: extrudersModel }
  23. MenuItem {
  24. text: "%1: %2 - %3".arg(model.name).arg(model.material).arg(model.variant)
  25. visible: base.shouldShowExtruders
  26. enabled: UM.Selection.hasSelection
  27. checkable: true
  28. checked: Cura.ExtruderManager.selectedObjectExtruders.indexOf(model.id) != -1
  29. onTriggered: CuraActions.setExtruderForSelection(model.id)
  30. shortcut: "Ctrl+" + (model.index + 1)
  31. }
  32. onObjectAdded: base.insertItem(index, object)
  33. onObjectRemoved: base.removeItem(object)
  34. }
  35. MenuSeparator {
  36. visible: UM.Preferences.getValue("cura/use_multi_build_plate")
  37. }
  38. Instantiator
  39. {
  40. model: Cura.BuildPlateModel
  41. MenuItem {
  42. text: Cura.BuildPlateModel.getItem(index).name;
  43. onTriggered: CuraActions.setBuildPlateForSelection(Cura.BuildPlateModel.getItem(index).buildPlateNumber);
  44. checkable: true
  45. checked: Cura.BuildPlateModel.selectionBuildPlates.indexOf(Cura.BuildPlateModel.getItem(index).buildPlateNumber) != -1;
  46. visible: UM.Preferences.getValue("cura/use_multi_build_plate")
  47. }
  48. onObjectAdded: base.insertItem(index, object);
  49. onObjectRemoved: base.removeItem(object);
  50. }
  51. MenuItem {
  52. text: "New build plate";
  53. onTriggered: {
  54. CuraActions.setBuildPlateForSelection(Cura.BuildPlateModel.maxBuildPlate + 1);
  55. checked = false;
  56. }
  57. checkable: true
  58. checked: false
  59. visible: UM.Preferences.getValue("cura/use_multi_build_plate")
  60. }
  61. // Global actions
  62. MenuSeparator {}
  63. MenuItem { action: Cura.Actions.selectAll; }
  64. MenuItem { action: Cura.Actions.arrangeAll; }
  65. MenuItem { action: Cura.Actions.deleteAll; }
  66. MenuItem { action: Cura.Actions.reloadAll; }
  67. MenuItem { action: Cura.Actions.resetAllTranslation; }
  68. MenuItem { action: Cura.Actions.resetAll; }
  69. // Group actions
  70. MenuSeparator {}
  71. MenuItem { action: Cura.Actions.groupObjects; }
  72. MenuItem { action: Cura.Actions.mergeObjects; }
  73. MenuItem { action: Cura.Actions.unGroupObjects; }
  74. Connections
  75. {
  76. target: UM.Controller
  77. onContextMenuRequested: base.popup();
  78. }
  79. Connections
  80. {
  81. target: Cura.Actions.multiplySelection
  82. onTriggered: multiplyDialog.open()
  83. }
  84. UM.SettingPropertyProvider
  85. {
  86. id: machineExtruderCount
  87. containerStackId: Cura.MachineManager.activeMachineId
  88. key: "machine_extruder_count"
  89. watchedProperties: [ "value" ]
  90. }
  91. Dialog
  92. {
  93. id: multiplyDialog
  94. modality: Qt.ApplicationModal
  95. title: catalog.i18ncp("@title:window", "Multiply Selected Model", "Multiply Selected Models", UM.Selection.selectionCount)
  96. onAccepted: CuraActions.multiplySelection(copiesField.value)
  97. signal reset()
  98. onReset:
  99. {
  100. copiesField.value = 1;
  101. copiesField.focus = true;
  102. }
  103. onVisibleChanged:
  104. {
  105. copiesField.forceActiveFocus();
  106. }
  107. standardButtons: StandardButton.Ok | StandardButton.Cancel
  108. Row
  109. {
  110. spacing: UM.Theme.getSize("default_margin").width
  111. Label
  112. {
  113. text: catalog.i18nc("@label", "Number of Copies")
  114. anchors.verticalCenter: copiesField.verticalCenter
  115. }
  116. SpinBox
  117. {
  118. id: copiesField
  119. focus: true
  120. minimumValue: 1
  121. maximumValue: 99
  122. }
  123. }
  124. }
  125. // Find the index of an item in the list of child items of this menu.
  126. //
  127. // This is primarily intended as a helper function so we do not have to
  128. // hard-code the position of the extruder selection actions.
  129. //
  130. // \param item The item to find the index of.
  131. //
  132. // \return The index of the item or -1 if it was not found.
  133. function findItemIndex(item)
  134. {
  135. for(var i in base.items)
  136. {
  137. if(base.items[i] == item)
  138. {
  139. return i;
  140. }
  141. }
  142. return -1;
  143. }
  144. UM.I18nCatalog { id: catalog; name: "cura" }
  145. }