MachinesPage.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Window 2.1
  6. import UM 1.2 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. iconName: "list-activate";
  33. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId
  34. onClicked: Cura.MachineManager.setActiveMachine(base.currentItem.id)
  35. },
  36. Button
  37. {
  38. id: addMenuButton
  39. text: catalog.i18nc("@action:button", "Add");
  40. iconName: "list-add";
  41. onClicked: Cura.Actions.addMachine.trigger()
  42. },
  43. Button
  44. {
  45. id: removeMenuButton
  46. text: catalog.i18nc("@action:button", "Remove");
  47. iconName: "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. iconName: "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. 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. rightButtons: Button
  107. {
  108. text: catalog.i18nc("@action:button", "Close")
  109. iconName: "dialog-close"
  110. onClicked: actionDialog.reject()
  111. }
  112. }
  113. UM.I18nCatalog { id: catalog; name: "cura"; }
  114. UM.ConfirmRemoveDialog
  115. {
  116. id: confirmDialog
  117. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  118. onYes:
  119. {
  120. Cura.MachineManager.removeMachine(base.currentItem.id)
  121. if(!base.currentItem)
  122. {
  123. objectList.currentIndex = activeMachineIndex()
  124. }
  125. //Force updating currentItem and the details panel
  126. objectList.onCurrentIndexChanged()
  127. }
  128. }
  129. UM.RenameDialog
  130. {
  131. id: renameDialog;
  132. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  133. property var machine_name_validator: Cura.MachineNameValidator { }
  134. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null;
  135. onAccepted:
  136. {
  137. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
  138. //Force updating currentItem and the details panel
  139. objectList.onCurrentIndexChanged()
  140. }
  141. }
  142. Connections
  143. {
  144. target: Cura.MachineManager
  145. onGlobalContainerChanged:
  146. {
  147. objectList.currentIndex = activeMachineIndex()
  148. objectList.onCurrentIndexChanged()
  149. }
  150. }
  151. }
  152. }