SaveProjectFilesPage.qml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. //Copyright (C) 2022 Ultimaker B.V.
  2. //Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.15
  4. import QtQuick.Window 2.2
  5. import QtQuick.Controls 2.3
  6. import UM 1.6 as UM
  7. import Cura 1.6 as Cura
  8. import DigitalFactory 1.0 as DF
  9. Item
  10. {
  11. id: base
  12. width: parent.width
  13. height: parent.height
  14. property var fileModel: manager.digitalFactoryFileModel
  15. property var modelRows: manager.digitalFactoryFileModel.items
  16. signal savePressed()
  17. signal selectDifferentProjectPressed()
  18. anchors
  19. {
  20. fill: parent
  21. margins: UM.Theme.getSize("default_margin").width
  22. }
  23. ProjectSummaryCard
  24. {
  25. id: projectSummaryCard
  26. anchors.top: parent.top
  27. property var selectedItem: manager.digitalFactoryProjectModel.getItem(manager.selectedProjectIndex)
  28. imageSource: selectedItem.thumbnailUrl || "../images/placeholder.svg"
  29. projectNameText: selectedItem.displayName || ""
  30. projectUsernameText: selectedItem.username || ""
  31. projectLastUpdatedText: "Last updated: " + selectedItem.lastUpdated
  32. cardMouseAreaEnabled: false
  33. }
  34. Label
  35. {
  36. id: fileNameLabel
  37. anchors.top: projectSummaryCard.bottom
  38. anchors.topMargin: UM.Theme.getSize("default_margin").height
  39. text: "Cura project name"
  40. font: UM.Theme.getFont("medium")
  41. color: UM.Theme.getColor("text")
  42. }
  43. Cura.TextField
  44. {
  45. id: dfFilenameTextfield
  46. width: parent.width
  47. anchors.left: parent.left
  48. anchors.top: fileNameLabel.bottom
  49. anchors.topMargin: UM.Theme.getSize("thin_margin").height
  50. validator: RegularExpressionValidator
  51. {
  52. regularExpression: /^[\w\-\. ()]{0,255}$/
  53. }
  54. text: PrintInformation.jobName
  55. font: fontMetrics.font
  56. height: fontMetrics.height + 2 * UM.Theme.getSize("thin_margin").height
  57. placeholderText: "Enter the name of the file."
  58. onAccepted: { if (saveButton.enabled) {saveButton.clicked()}}
  59. }
  60. FontMetrics
  61. {
  62. id: fontMetrics
  63. font: UM.Theme.getFont("medium")
  64. }
  65. Rectangle
  66. {
  67. id: projectFilesContent
  68. width: parent.width
  69. anchors.top: dfFilenameTextfield.bottom
  70. anchors.topMargin: UM.Theme.getSize("wide_margin").height
  71. anchors.bottom: selectDifferentProjectButton.top
  72. anchors.bottomMargin: UM.Theme.getSize("default_margin").width
  73. color: UM.Theme.getColor("main_background")
  74. border.width: UM.Theme.getSize("default_lining").width
  75. border.color: UM.Theme.getColor("lining")
  76. // This is not backwards compatible with Cura < 5.0 due to QT.labs being removed in PyQt6
  77. Cura.TableView
  78. {
  79. id: filesTableView
  80. anchors.fill: parent
  81. anchors.margins: parent.border.width
  82. allowSelection: false
  83. columnHeaders: ["Name", "Uploaded by", "Uploaded at"]
  84. model: UM.TableModel
  85. {
  86. id: tableModel
  87. headers: ["fileName", "username", "uploadedAt"]
  88. rows: manager.digitalFactoryFileModel.items
  89. }
  90. }
  91. Label
  92. {
  93. id: emptyProjectLabel
  94. anchors.horizontalCenter: parent.horizontalCenter
  95. anchors.verticalCenter: parent.verticalCenter
  96. text: "Select a project to view its files."
  97. font: UM.Theme.getFont("default")
  98. color: UM.Theme.getColor("setting_category_text")
  99. Connections
  100. {
  101. target: manager
  102. function onSelectedProjectIndexChanged()
  103. {
  104. emptyProjectLabel.visible = (manager.newProjectIndex == -1)
  105. }
  106. }
  107. }
  108. Label
  109. {
  110. id: noFilesInProjectLabel
  111. anchors.horizontalCenter: parent.horizontalCenter
  112. anchors.verticalCenter: parent.verticalCenter
  113. visible: (manager.digitalFactoryFileModel.count == 0 && !emptyProjectLabel.visible && !retrievingFilesBusyIndicator.visible)
  114. text: "No supported files in this project."
  115. font: UM.Theme.getFont("default")
  116. color: UM.Theme.getColor("setting_category_text")
  117. }
  118. BusyIndicator
  119. {
  120. // Shows up while Cura is waiting to receive the files of a project from the digital factory library
  121. id: retrievingFilesBusyIndicator
  122. anchors
  123. {
  124. verticalCenter: parent.verticalCenter
  125. horizontalCenter: parent.horizontalCenter
  126. }
  127. width: parent.width / 4
  128. height: width
  129. visible: manager.retrievingFilesStatus == DF.RetrievalStatus.InProgress
  130. running: visible
  131. palette.dark: UM.Theme.getColor("text")
  132. }
  133. Connections
  134. {
  135. target: manager.digitalFactoryFileModel
  136. function onItemsChanged()
  137. {
  138. // Make sure no files are selected when the file model changes
  139. filesTableView.currentRow = -1;
  140. }
  141. }
  142. }
  143. Cura.SecondaryButton
  144. {
  145. id: selectDifferentProjectButton
  146. anchors.bottom: parent.bottom
  147. anchors.left: parent.left
  148. text: "Change Library project"
  149. onClicked:
  150. {
  151. manager.selectedProjectIndex = -1
  152. }
  153. busy: false
  154. }
  155. Cura.PrimaryButton
  156. {
  157. id: saveButton
  158. anchors.bottom: parent.bottom
  159. anchors.right: parent.right
  160. text: "Save"
  161. enabled: (asProjectCheckbox.checked || asSlicedCheckbox.checked) && dfFilenameTextfield.text.length >= 1 && dfFilenameTextfield.state !== 'invalid'
  162. onClicked:
  163. {
  164. let saveAsFormats = [];
  165. if (asProjectCheckbox.checked)
  166. {
  167. saveAsFormats.push("3mf");
  168. }
  169. if (asSlicedCheckbox.checked)
  170. {
  171. saveAsFormats.push("ufp");
  172. }
  173. manager.saveFileToSelectedProject(dfFilenameTextfield.text, saveAsFormats);
  174. }
  175. busy: false
  176. }
  177. Row
  178. {
  179. id: saveAsFormatRow
  180. anchors.verticalCenter: saveButton.verticalCenter
  181. anchors.right: saveButton.left
  182. anchors.rightMargin: UM.Theme.getSize("thin_margin").height
  183. width: childrenRect.width
  184. spacing: UM.Theme.getSize("default_margin").width
  185. UM.CheckBox
  186. {
  187. id: asProjectCheckbox
  188. height: UM.Theme.getSize("checkbox").height
  189. anchors.verticalCenter: parent.verticalCenter
  190. checked: true
  191. text: "Save Cura project"
  192. font: UM.Theme.getFont("medium")
  193. }
  194. UM.CheckBox
  195. {
  196. id: asSlicedCheckbox
  197. height: UM.Theme.getSize("checkbox").height
  198. anchors.verticalCenter: parent.verticalCenter
  199. enabled: UM.Backend.state == UM.Backend.Done
  200. checked: UM.Backend.state == UM.Backend.Done
  201. text: "Save print file"
  202. font: UM.Theme.getFont("medium")
  203. }
  204. }
  205. Component.onCompleted:
  206. {
  207. saveButton.clicked.connect(base.savePressed)
  208. selectDifferentProjectButton.clicked.connect(base.selectDifferentProjectPressed)
  209. }
  210. onModelRowsChanged:
  211. {
  212. tableModel.clear()
  213. tableModel.rows = modelRows
  214. }
  215. }