MachinesPage.qml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.MachineManagementModel { }
  13. activeId: Cura.MachineManager.activeMachineId
  14. activeIndex: activeMachineIndex()
  15. function activeMachineIndex()
  16. {
  17. for(var i = 0; i < model.count; i++)
  18. {
  19. if (model.getItem(i).id == Cura.MachineManager.activeMachineId)
  20. {
  21. return i;
  22. }
  23. }
  24. return -1;
  25. }
  26. buttons: [
  27. Button
  28. {
  29. text: catalog.i18nc("@action:button", "Activate");
  30. iconName: "list-activate";
  31. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId
  32. onClicked: Cura.MachineManager.setActiveMachine(base.currentItem.id)
  33. },
  34. Button
  35. {
  36. text: catalog.i18nc("@action:button", "Add");
  37. iconName: "list-add";
  38. onClicked: CuraApplication.requestAddPrinter()
  39. },
  40. Button
  41. {
  42. text: catalog.i18nc("@action:button", "Remove");
  43. iconName: "list-remove";
  44. enabled: base.currentItem != null && model.count > 1
  45. onClicked: confirmDialog.open();
  46. },
  47. Button
  48. {
  49. text: catalog.i18nc("@action:button", "Rename");
  50. iconName: "edit-rename";
  51. enabled: base.currentItem != null && base.currentItem.metadata.group_name == null
  52. onClicked: renameDialog.open();
  53. }
  54. ]
  55. Item
  56. {
  57. visible: base.currentItem != null
  58. anchors.fill: parent
  59. Label
  60. {
  61. id: machineName
  62. text: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  63. font: UM.Theme.getFont("large_bold")
  64. width: parent.width
  65. elide: Text.ElideRight
  66. }
  67. Flow
  68. {
  69. id: machineActions
  70. visible: currentItem && currentItem.id == Cura.MachineManager.activeMachineId
  71. anchors.left: parent.left
  72. anchors.right: parent.right
  73. anchors.top: machineName.bottom
  74. anchors.topMargin: UM.Theme.getSize("default_margin").height
  75. Repeater
  76. {
  77. id: machineActionRepeater
  78. model: base.currentItem ? Cura.MachineActionManager.getSupportedActions(Cura.MachineManager.getDefinitionByMachineId(base.currentItem.id)) : null
  79. Item
  80. {
  81. width: Math.round(childrenRect.width + 2 * screenScaleFactor)
  82. height: childrenRect.height
  83. Button
  84. {
  85. text: machineActionRepeater.model[index].label
  86. onClicked:
  87. {
  88. actionDialog.content = machineActionRepeater.model[index].displayItem;
  89. machineActionRepeater.model[index].displayItem.reset();
  90. actionDialog.title = machineActionRepeater.model[index].label;
  91. actionDialog.show();
  92. }
  93. }
  94. }
  95. }
  96. }
  97. UM.Dialog
  98. {
  99. id: actionDialog
  100. property var content
  101. onContentChanged:
  102. {
  103. contents = content;
  104. content.onCompleted.connect(hide)
  105. content.dialog = actionDialog
  106. }
  107. rightButtons: Button
  108. {
  109. text: catalog.i18nc("@action:button", "Close")
  110. iconName: "dialog-close"
  111. onClicked: actionDialog.reject()
  112. }
  113. }
  114. UM.I18nCatalog { id: catalog; name: "cura"; }
  115. UM.ConfirmRemoveDialog
  116. {
  117. id: confirmDialog
  118. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  119. onYes:
  120. {
  121. Cura.MachineManager.removeMachine(base.currentItem.id)
  122. if(!base.currentItem)
  123. {
  124. objectList.currentIndex = activeMachineIndex()
  125. }
  126. //Force updating currentItem and the details panel
  127. objectList.onCurrentIndexChanged()
  128. }
  129. }
  130. UM.RenameDialog
  131. {
  132. id: renameDialog;
  133. width: 300 * screenScaleFactor
  134. height: 150 * screenScaleFactor
  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. onGlobalContainerChanged:
  149. {
  150. objectList.currentIndex = activeMachineIndex()
  151. objectList.onCurrentIndexChanged()
  152. }
  153. }
  154. }
  155. }