MachinesPage.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. // Copyright (c) 2016 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.rowCount(); i++) {
  18. if (model.getItem(i).id == Cura.MachineManager.activeMachineId) {
  19. return i;
  20. }
  21. }
  22. return -1;
  23. }
  24. buttons: [
  25. Button
  26. {
  27. text: catalog.i18nc("@action:button", "Activate");
  28. iconName: "list-activate";
  29. enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId
  30. onClicked: Cura.MachineManager.setActiveMachine(base.currentItem.id)
  31. },
  32. Button
  33. {
  34. text: catalog.i18nc("@action:button", "Add");
  35. iconName: "list-add";
  36. onClicked: CuraApplication.requestAddPrinter()
  37. },
  38. Button
  39. {
  40. text: catalog.i18nc("@action:button", "Remove");
  41. iconName: "list-remove";
  42. enabled: base.currentItem != null && model.rowCount() > 1
  43. onClicked: confirmDialog.open();
  44. },
  45. Button
  46. {
  47. text: catalog.i18nc("@action:button", "Rename");
  48. iconName: "edit-rename";
  49. enabled: base.currentItem != null && base.currentItem.metadata.connect_group_name == null
  50. onClicked: renameDialog.open();
  51. }
  52. ]
  53. Item
  54. {
  55. visible: base.currentItem != null
  56. anchors.fill: parent
  57. Label
  58. {
  59. id: machineName
  60. text: base.currentItem && base.currentItem.name ? base.currentItem.name : ""
  61. font: UM.Theme.getFont("large")
  62. width: parent.width
  63. elide: Text.ElideRight
  64. }
  65. Flow
  66. {
  67. id: machineActions
  68. visible: currentItem && currentItem.id == Cura.MachineManager.activeMachineId
  69. anchors.left: parent.left
  70. anchors.right: parent.right
  71. anchors.top: machineName.bottom
  72. anchors.topMargin: UM.Theme.getSize("default_margin").height
  73. Repeater
  74. {
  75. id: machineActionRepeater
  76. model: base.currentItem ? Cura.MachineActionManager.getSupportedActions(Cura.MachineManager.getDefinitionByMachineId(base.currentItem.id)) : null
  77. Item
  78. {
  79. width: childrenRect.width + 2 * screenScaleFactor
  80. height: childrenRect.height
  81. Button
  82. {
  83. text: machineActionRepeater.model[index].label
  84. onClicked:
  85. {
  86. actionDialog.content = machineActionRepeater.model[index].displayItem;
  87. machineActionRepeater.model[index].displayItem.reset();
  88. actionDialog.title = machineActionRepeater.model[index].label;
  89. actionDialog.show();
  90. }
  91. }
  92. }
  93. }
  94. }
  95. UM.Dialog
  96. {
  97. id: actionDialog
  98. property var content
  99. onContentChanged:
  100. {
  101. contents = content;
  102. content.onCompleted.connect(hide)
  103. content.dialog = actionDialog
  104. }
  105. rightButtons: Button
  106. {
  107. text: catalog.i18nc("@action:button", "Close")
  108. iconName: "dialog-close"
  109. onClicked: actionDialog.reject()
  110. }
  111. }
  112. Grid
  113. {
  114. id: machineInfo
  115. anchors.top: machineActions.visible ? machineActions.bottom : machineActions.anchors.top
  116. anchors.topMargin: UM.Theme.getSize("default_margin").height
  117. anchors.left: parent.left
  118. anchors.right: parent.right
  119. spacing: UM.Theme.getSize("default_margin").height
  120. rowSpacing: UM.Theme.getSize("default_lining").height
  121. columns: 2
  122. visible: base.currentItem
  123. property bool printerConnected: Cura.MachineManager.printerConnected
  124. property var connectedPrinter: printerConnected ? Cura.MachineManager.printerOutputDevices[0] : null
  125. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  126. property var printJob: connectedPrinter != null ? connectedPrinter.activePrintJob: null
  127. Label
  128. {
  129. text: catalog.i18nc("@label", "Printer type:")
  130. visible: base.currentItem && "definition_name" in base.currentItem.metadata
  131. }
  132. Label
  133. {
  134. text: (base.currentItem && "definition_name" in base.currentItem.metadata) ? base.currentItem.metadata.definition_name : ""
  135. }
  136. Label
  137. {
  138. text: catalog.i18nc("@label", "Connection:")
  139. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  140. }
  141. Label
  142. {
  143. width: (parent.width * 0.7) | 0
  144. text: machineInfo.printerConnected ? machineInfo.connectedPrinter.connectionText : catalog.i18nc("@info:status", "The printer is not connected.")
  145. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  146. wrapMode: Text.WordWrap
  147. }
  148. Label
  149. {
  150. text: catalog.i18nc("@label", "State:")
  151. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId && machineInfo.printerAcceptsCommands
  152. }
  153. Label {
  154. width: (parent.width * 0.7) | 0
  155. text:
  156. {
  157. if(!machineInfo.printerConnected || !machineInfo.printerAcceptsCommands) {
  158. return "";
  159. }
  160. if (machineInfo.printJob == null)
  161. {
  162. return catalog.i18nc("@label:MonitorStatus", "Waiting for a printjob");
  163. }
  164. switch(machineInfo.printJob.state)
  165. {
  166. case "printing":
  167. return catalog.i18nc("@label:MonitorStatus", "Printing...");
  168. case "paused":
  169. return catalog.i18nc("@label:MonitorStatus", "Paused");
  170. case "pre_print":
  171. return catalog.i18nc("@label:MonitorStatus", "Preparing...");
  172. case "wait_cleanup":
  173. return catalog.i18nc("@label:MonitorStatus", "Waiting for someone to clear the build plate");
  174. case "error":
  175. return printerOutputDevice.errorText;
  176. case "maintenance":
  177. return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer");
  178. case "abort": // note sure if this jobState actually occurs in the wild
  179. return catalog.i18nc("@label:MonitorStatus", "Aborting print...");
  180. }
  181. return ""
  182. }
  183. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId && machineInfo.printerAcceptsCommands
  184. wrapMode: Text.WordWrap
  185. }
  186. }
  187. Column {
  188. id: additionalComponentsColumn
  189. anchors.left: parent.left
  190. anchors.right: parent.right
  191. anchors.top: machineInfo.visible ? machineInfo.bottom : machineInfo.anchors.top
  192. anchors.topMargin: UM.Theme.getSize("default_margin").width
  193. spacing: UM.Theme.getSize("default_margin").width
  194. visible: base.currentItem && base.currentItem.id == Cura.MachineManager.activeMachineId
  195. Component.onCompleted:
  196. {
  197. for (var component in CuraApplication.additionalComponents["machinesDetailPane"]) {
  198. CuraApplication.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  199. }
  200. }
  201. }
  202. Component.onCompleted: {
  203. addAdditionalComponents("machinesDetailPane")
  204. }
  205. Connections {
  206. target: CuraApplication
  207. onAdditionalComponentsChanged: addAdditionalComponents
  208. }
  209. function addAdditionalComponents (areaId) {
  210. if(areaId == "machinesDetailPane") {
  211. for (var component in CuraApplication.additionalComponents["machinesDetailPane"]) {
  212. CuraApplication.additionalComponents["machinesDetailPane"][component].parent = additionalComponentsColumn
  213. }
  214. }
  215. }
  216. UM.I18nCatalog { id: catalog; name: "cura"; }
  217. UM.ConfirmRemoveDialog
  218. {
  219. id: confirmDialog;
  220. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  221. onYes:
  222. {
  223. Cura.MachineManager.removeMachine(base.currentItem.id);
  224. if(!base.currentItem)
  225. {
  226. objectList.currentIndex = activeMachineIndex()
  227. }
  228. //Force updating currentItem and the details panel
  229. objectList.onCurrentIndexChanged()
  230. }
  231. }
  232. UM.RenameDialog
  233. {
  234. id: renameDialog;
  235. width: 300 * screenScaleFactor
  236. height: 150 * screenScaleFactor
  237. object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
  238. property var machine_name_validator: Cura.MachineNameValidator { }
  239. validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null;
  240. onAccepted:
  241. {
  242. Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
  243. //Force updating currentItem and the details panel
  244. objectList.onCurrentIndexChanged()
  245. }
  246. }
  247. Connections
  248. {
  249. target: Cura.MachineManager
  250. onGlobalContainerChanged:
  251. {
  252. objectList.currentIndex = activeMachineIndex()
  253. objectList.onCurrentIndexChanged()
  254. }
  255. }
  256. }
  257. }