MachinesPage.qml 5.4 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. 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. backgroundColor: UM.Theme.getColor("main_background")
  82. }
  83. UM.ConfirmRemoveDialog
  84. {
  85. id: confirmDialog
  86. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  87. text: base.currentItem ? base.currentItem.removalWarning : ""
  88. onAccepted:
  89. {
  90. Cura.MachineManager.removeMachine(base.currentItem.id)
  91. if(!base.currentItem)
  92. {
  93. objectList.currentIndex = activeMachineIndex()
  94. }
  95. //Force updating currentItem and the details panel
  96. objectList.onCurrentIndexChanged()
  97. }
  98. }
  99. Cura.RenameDialog
  100. {
  101. id: renameDialog
  102. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  103. property var machine_name_validator: Cura.MachineNameValidator { }
  104. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null
  105. onAccepted:
  106. {
  107. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim())
  108. //Force updating currentItem and the details panel
  109. objectList.onCurrentIndexChanged()
  110. }
  111. }
  112. Cura.Menu
  113. {
  114. id: menu
  115. Cura.MenuItem
  116. {
  117. text: catalog.i18nc("@action:button", "Activate")
  118. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMachine.id
  119. onTriggered: Cura.MachineManager.setActiveMachine(base.currentItem.id)
  120. }
  121. Cura.MenuItem
  122. {
  123. text: catalog.i18nc("@action:button", "Remove")
  124. enabled: base.currentItem != null && model.count > 1
  125. onTriggered: confirmDialog.open()
  126. }
  127. Cura.MenuItem
  128. {
  129. text: catalog.i18nc("@action:button", "Rename")
  130. enabled: base.currentItem != null && base.currentItem.metadata.group_name == null
  131. onTriggered: renameDialog.open()
  132. }
  133. }
  134. Connections
  135. {
  136. target: Cura.MachineManager
  137. function onGlobalContainerChanged()
  138. {
  139. objectList.currentIndex = activeMachineIndex()
  140. objectList.onCurrentIndexChanged()
  141. }
  142. }
  143. }
  144. }