MachinesPage.qml 5.9 KB

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