MachinesPage.qml 5.3 KB

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