MachinesPage.qml 5.4 KB

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