MachinesPage.qml 5.6 KB

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