MachinesPage.qml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. Cura.SecondaryButton
  58. {
  59. text: machineActionRepeater.model[index].label
  60. onClicked:
  61. {
  62. var currentItem = machineActionRepeater.model[index]
  63. actionDialog.loader.manager = currentItem
  64. actionDialog.loader.source = currentItem.qmlPath
  65. actionDialog.title = currentItem.label
  66. actionDialog.show()
  67. }
  68. }
  69. }
  70. }
  71. }
  72. Item
  73. {
  74. UM.Dialog
  75. {
  76. id: actionDialog
  77. minimumWidth: UM.Theme.getSize("modal_window_minimum").width
  78. minimumHeight: UM.Theme.getSize("modal_window_minimum").height
  79. maximumWidth: minimumWidth * 3
  80. maximumHeight: minimumHeight * 3
  81. backgroundColor: UM.Theme.getColor("main_background")
  82. onVisibleChanged:
  83. {
  84. if(!visible)
  85. {
  86. actionDialog.loader.item.focus = true
  87. }
  88. }
  89. }
  90. UM.ConfirmRemoveDialog
  91. {
  92. id: confirmDialog
  93. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  94. text: base.currentItem ? base.currentItem.removalWarning : ""
  95. onAccepted:
  96. {
  97. Cura.MachineManager.removeMachine(base.currentItem.id)
  98. if(!base.currentItem)
  99. {
  100. objectList.currentIndex = activeMachineIndex()
  101. }
  102. //Force updating currentItem and the details panel
  103. objectList.onCurrentIndexChanged()
  104. }
  105. }
  106. Cura.RenameDialog
  107. {
  108. id: renameDialog
  109. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  110. property var machine_name_validator: Cura.MachineNameValidator { }
  111. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null
  112. onAccepted:
  113. {
  114. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim())
  115. //Force updating currentItem and the details panel
  116. objectList.onCurrentIndexChanged()
  117. }
  118. }
  119. Cura.Menu
  120. {
  121. id: menu
  122. Cura.MenuItem
  123. {
  124. text: catalog.i18nc("@action:button", "Activate")
  125. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMachine.id
  126. onTriggered: Cura.MachineManager.setActiveMachine(base.currentItem.id)
  127. }
  128. Cura.MenuItem
  129. {
  130. text: catalog.i18nc("@action:button", "Remove")
  131. enabled: base.currentItem != null && model.count > 1
  132. onTriggered: confirmDialog.open()
  133. }
  134. Cura.MenuItem
  135. {
  136. text: catalog.i18nc("@action:button", "Rename")
  137. enabled: base.currentItem != null && base.currentItem.metadata.group_name == null
  138. onTriggered: renameDialog.open()
  139. }
  140. }
  141. Connections
  142. {
  143. target: Cura.MachineManager
  144. function onGlobalContainerChanged()
  145. {
  146. objectList.currentIndex = activeMachineIndex()
  147. objectList.onCurrentIndexChanged()
  148. }
  149. }
  150. }
  151. }