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