MachinesPage.qml 5.2 KB

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