ContextMenu.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura is released under the terms of the AGPLv3 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.0 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: 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. // Global actions
  36. MenuSeparator {}
  37. MenuItem { action: Cura.Actions.selectAll; }
  38. MenuItem { action: Cura.Actions.arrangeAll; }
  39. MenuItem { action: Cura.Actions.deleteAll; }
  40. MenuItem { action: Cura.Actions.reloadAll; }
  41. MenuItem { action: Cura.Actions.resetAllTranslation; }
  42. MenuItem { action: Cura.Actions.resetAll; }
  43. // Group actions
  44. MenuSeparator {}
  45. MenuItem { action: Cura.Actions.groupObjects; }
  46. MenuItem { action: Cura.Actions.mergeObjects; }
  47. MenuItem { action: Cura.Actions.unGroupObjects; }
  48. Connections
  49. {
  50. target: UM.Controller
  51. onContextMenuRequested: base.popup();
  52. }
  53. Connections
  54. {
  55. target: Cura.Actions.multiplySelection
  56. onTriggered: multiplyDialog.open()
  57. }
  58. UM.SettingPropertyProvider
  59. {
  60. id: machineExtruderCount
  61. containerStackId: Cura.MachineManager.activeMachineId
  62. key: "machine_extruder_count"
  63. watchedProperties: [ "value" ]
  64. }
  65. Dialog
  66. {
  67. id: multiplyDialog
  68. title: catalog.i18ncp("@title:window", "Multiply Selected Model", "Multiply Selected Models", UM.Selection.selectionCount)
  69. onAccepted: CuraActions.multiplySelection(copiesField.value)
  70. signal reset()
  71. onReset:
  72. {
  73. copiesField.value = 1;
  74. copiesField.focus = true;
  75. }
  76. onVisibleChanged:
  77. {
  78. copiesField.forceActiveFocus();
  79. }
  80. standardButtons: StandardButton.Ok | StandardButton.Cancel
  81. Row
  82. {
  83. spacing: UM.Theme.getSize("default_margin").width
  84. Label
  85. {
  86. text: catalog.i18nc("@label", "Number of Copies")
  87. anchors.verticalCenter: copiesField.verticalCenter
  88. }
  89. SpinBox
  90. {
  91. id: copiesField
  92. focus: true
  93. minimumValue: 1
  94. maximumValue: 99
  95. }
  96. }
  97. }
  98. // Find the index of an item in the list of child items of this menu.
  99. //
  100. // This is primarily intended as a helper function so we do not have to
  101. // hard-code the position of the extruder selection actions.
  102. //
  103. // \param item The item to find the index of.
  104. //
  105. // \return The index of the item or -1 if it was not found.
  106. function findItemIndex(item)
  107. {
  108. for(var i in base.items)
  109. {
  110. if(base.items[i] == item)
  111. {
  112. return i;
  113. }
  114. }
  115. return -1;
  116. }
  117. UM.I18nCatalog { id: catalog; name: "cura" }
  118. }