MachinesPage.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 { }
  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. }
  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. }