ContextMenu.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. modality: Qt.ApplicationModal
  69. title: catalog.i18ncp("@title:window", "Multiply Selected Model", "Multiply Selected Models", UM.Selection.selectionCount)
  70. onAccepted: CuraActions.multiplySelection(copiesField.value)
  71. signal reset()
  72. onReset:
  73. {
  74. copiesField.value = 1;
  75. copiesField.focus = true;
  76. }
  77. onVisibleChanged:
  78. {
  79. copiesField.forceActiveFocus();
  80. }
  81. standardButtons: StandardButton.Ok | StandardButton.Cancel
  82. Row
  83. {
  84. spacing: UM.Theme.getSize("default_margin").width
  85. Label
  86. {
  87. text: catalog.i18nc("@label", "Number of Copies")
  88. anchors.verticalCenter: copiesField.verticalCenter
  89. }
  90. SpinBox
  91. {
  92. id: copiesField
  93. focus: true
  94. minimumValue: 1
  95. maximumValue: 99
  96. }
  97. }
  98. }
  99. // Find the index of an item in the list of child items of this menu.
  100. //
  101. // This is primarily intended as a helper function so we do not have to
  102. // hard-code the position of the extruder selection actions.
  103. //
  104. // \param item The item to find the index of.
  105. //
  106. // \return The index of the item or -1 if it was not found.
  107. function findItemIndex(item)
  108. {
  109. for(var i in base.items)
  110. {
  111. if(base.items[i] == item)
  112. {
  113. return i;
  114. }
  115. }
  116. return -1;
  117. }
  118. UM.I18nCatalog { id: catalog; name: "cura" }
  119. }