MachinesPage.qml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  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. UM.ManagementPage
  9. {
  10. id: base
  11. property var machineActionManager: CuraApplication.getMachineActionManagerQml()
  12. Item { enabled: false; UM.I18nCatalog { id: catalog; name: "cura"} }
  13. title: catalog.i18nc("@title:tab", "Printers")
  14. detailsPlaneCaption: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  15. model: Cura.GlobalStacksModel { filterAbstractMachines: false }
  16. sectionRole: "discoverySource"
  17. activeId: Cura.MachineManager.activeMachine !== null ? Cura.MachineManager.activeMachine.id: ""
  18. activeIndex: activeMachineIndex()
  19. onHamburgeButtonClicked: {
  20. const hamburerButtonHeight = hamburger_button.height;
  21. menu.popup(hamburger_button, -menu.width + hamburger_button.width / 2, hamburger_button.height);
  22. // for some reason the height of the hamburger changes when opening the popup
  23. // reset height to initial heigt
  24. hamburger_button.height = hamburerButtonHeight;
  25. }
  26. hamburgerButtonVisible: Cura.MachineManager.activeMachine !== null
  27. function activeMachineIndex()
  28. {
  29. for(var i = 0; i < model.count; i++)
  30. {
  31. if (model.getItem(i).id == base.activeId)
  32. {
  33. return i;
  34. }
  35. }
  36. return -1;
  37. }
  38. buttons: [
  39. Cura.SecondaryButton
  40. {
  41. text: catalog.i18nc("@action:button", "Add New")
  42. onClicked: Cura.Actions.addMachine.trigger()
  43. }
  44. ]
  45. Flow
  46. {
  47. visible: base.currentItem != null && currentItem && currentItem.id == Cura.MachineManager.activeMachine.id
  48. anchors.fill: parent
  49. spacing: UM.Theme.getSize("default_margin").height
  50. Repeater
  51. {
  52. id: machineActionRepeater
  53. model: base.currentItem ? machineActionManager.getSupportedActions(Cura.MachineManager.getDefinitionByMachineId(base.currentItem.id)) : null
  54. Item
  55. {
  56. width: Math.round(childrenRect.width + 2 * screenScaleFactor)
  57. height: childrenRect.height
  58. visible: machineActionRepeater.model[index].visible
  59. Cura.SecondaryButton
  60. {
  61. text: machineActionRepeater.model[index].label
  62. onClicked:
  63. {
  64. var currentItem = machineActionRepeater.model[index]
  65. if (currentItem.shouldOpenAsDialog) {
  66. actionDialog.loader.manager = currentItem
  67. actionDialog.loader.source = currentItem.qmlPath
  68. actionDialog.title = currentItem.label
  69. actionDialog.show()
  70. } else {
  71. currentItem.execute()
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }
  78. Item
  79. {
  80. UM.Dialog
  81. {
  82. id: actionDialog
  83. minimumWidth: UM.Theme.getSize("modal_window_minimum").width
  84. minimumHeight: UM.Theme.getSize("modal_window_minimum").height
  85. maximumWidth: minimumWidth * 3
  86. maximumHeight: minimumHeight * 3
  87. backgroundColor: UM.Theme.getColor("main_background")
  88. onVisibleChanged:
  89. {
  90. if(!visible)
  91. {
  92. actionDialog.loader.item.focus = true
  93. }
  94. }
  95. }
  96. UM.ConfirmRemoveDialog
  97. {
  98. id: confirmDialog
  99. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  100. text: base.currentItem ? base.currentItem.removalWarning : ""
  101. onAccepted:
  102. {
  103. Cura.MachineManager.removeMachine(base.currentItem.id)
  104. if(!base.currentItem)
  105. {
  106. objectList.currentIndex = activeMachineIndex()
  107. }
  108. //Force updating currentItem and the details panel
  109. objectList.onCurrentIndexChanged()
  110. }
  111. }
  112. Cura.RenameDialog
  113. {
  114. id: renameDialog
  115. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  116. property var machine_name_validator: Cura.MachineNameValidator { }
  117. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null
  118. onAccepted:
  119. {
  120. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim())
  121. //Force updating currentItem and the details panel
  122. objectList.onCurrentIndexChanged()
  123. }
  124. }
  125. Cura.Menu
  126. {
  127. id: menu
  128. Cura.MenuItem
  129. {
  130. text: catalog.i18nc("@action:button", "Activate")
  131. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMachine.id
  132. onTriggered: Cura.MachineManager.setActiveMachine(base.currentItem.id)
  133. }
  134. Cura.MenuItem
  135. {
  136. text: catalog.i18nc("@action:button", "Remove")
  137. enabled: base.currentItem != null && model.count > 1
  138. onTriggered: confirmDialog.open()
  139. }
  140. Cura.MenuItem
  141. {
  142. text: catalog.i18nc("@action:button", "Rename")
  143. enabled: base.currentItem != null && base.currentItem.metadata.group_name == null
  144. onTriggered: renameDialog.open()
  145. }
  146. }
  147. Connections
  148. {
  149. target: Cura.MachineManager
  150. function onGlobalContainerChanged()
  151. {
  152. objectList.currentIndex = activeMachineIndex()
  153. objectList.onCurrentIndexChanged()
  154. }
  155. }
  156. }
  157. }