MachinesPage.qml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. minimumWidth: UM.Theme.getSize("modal_window_minimum").width
  107. minimumHeight: UM.Theme.getSize("modal_window_minimum").height
  108. maximumWidth: minimumWidth * 3
  109. maximumHeight: minimumHeight * 3
  110. rightButtons: Button
  111. {
  112. text: catalog.i18nc("@action:button", "Close")
  113. iconName: "dialog-close"
  114. onClicked: actionDialog.reject()
  115. }
  116. }
  117. UM.I18nCatalog { id: catalog; name: "cura"; }
  118. UM.ConfirmRemoveDialog
  119. {
  120. id: confirmDialog
  121. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  122. text: base.currentItem ? base.currentItem.removalWarning : "";
  123. onYes:
  124. {
  125. Cura.MachineManager.removeMachine(base.currentItem.id)
  126. if(!base.currentItem)
  127. {
  128. objectList.currentIndex = activeMachineIndex()
  129. }
  130. //Force updating currentItem and the details panel
  131. objectList.onCurrentIndexChanged()
  132. }
  133. }
  134. UM.RenameDialog
  135. {
  136. id: renameDialog;
  137. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  138. property var machine_name_validator: Cura.MachineNameValidator { }
  139. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null;
  140. onAccepted:
  141. {
  142. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
  143. //Force updating currentItem and the details panel
  144. objectList.onCurrentIndexChanged()
  145. }
  146. }
  147. Connections
  148. {
  149. target: Cura.MachineManager
  150. onGlobalContainerChanged:
  151. {
  152. objectList.currentIndex = activeMachineIndex()
  153. objectList.onCurrentIndexChanged()
  154. }
  155. }
  156. }
  157. }