MachinesPage.qml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.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. 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.activeMachineId
  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. actionDialog.content = machineActionRepeater.model[index].displayItem;
  94. machineActionRepeater.model[index].displayItem.reset();
  95. actionDialog.title = machineActionRepeater.model[index].label;
  96. actionDialog.show();
  97. }
  98. }
  99. }
  100. }
  101. }
  102. UM.Dialog
  103. {
  104. id: actionDialog
  105. property var content
  106. onContentChanged:
  107. {
  108. contents = content;
  109. content.onCompleted.connect(hide)
  110. content.dialog = actionDialog
  111. }
  112. rightButtons: Button
  113. {
  114. text: catalog.i18nc("@action:button", "Close")
  115. iconName: "dialog-close"
  116. onClicked: actionDialog.reject()
  117. }
  118. }
  119. UM.I18nCatalog { id: catalog; name: "cura"; }
  120. UM.ConfirmRemoveDialog
  121. {
  122. id: confirmDialog
  123. object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  124. onYes:
  125. {
  126. Cura.MachineManager.removeMachine(base.currentItem.id)
  127. if(!base.currentItem)
  128. {
  129. objectList.currentIndex = activeMachineIndex()
  130. }
  131. //Force updating currentItem and the details panel
  132. objectList.onCurrentIndexChanged()
  133. }
  134. }
  135. UM.RenameDialog
  136. {
  137. id: renameDialog;
  138. width: 300 * screenScaleFactor
  139. height: 150 * screenScaleFactor
  140. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  141. property var machine_name_validator: Cura.MachineNameValidator { }
  142. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null;
  143. onAccepted:
  144. {
  145. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
  146. //Force updating currentItem and the details panel
  147. objectList.onCurrentIndexChanged()
  148. }
  149. }
  150. Connections
  151. {
  152. target: Cura.MachineManager
  153. onGlobalContainerChanged:
  154. {
  155. objectList.currentIndex = activeMachineIndex()
  156. objectList.onCurrentIndexChanged()
  157. }
  158. }
  159. }
  160. }