SaveProjectFilesPage.qml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. property variant catalog: UM.I18nCatalog { name: "cura" }
  13. width: parent.width
  14. height: parent.height
  15. property var fileModel: manager.digitalFactoryFileModel
  16. property var modelRows: manager.digitalFactoryFileModel.items
  17. signal savePressed()
  18. signal selectDifferentProjectPressed()
  19. anchors
  20. {
  21. fill: parent
  22. margins: UM.Theme.getSize("default_margin").width
  23. }
  24. ProjectSummaryCard
  25. {
  26. id: projectSummaryCard
  27. anchors.top: parent.top
  28. property var selectedItem: manager.digitalFactoryProjectModel.getItem(manager.selectedProjectIndex)
  29. imageSource: selectedItem.thumbnailUrl || "../images/placeholder.svg"
  30. projectNameText: selectedItem.displayName || ""
  31. projectUsernameText: selectedItem.username || ""
  32. projectLastUpdatedText: "Last updated: " + selectedItem.lastUpdated
  33. cardMouseAreaEnabled: false
  34. }
  35. UM.Label
  36. {
  37. id: fileNameLabel
  38. anchors.top: projectSummaryCard.bottom
  39. anchors.topMargin: UM.Theme.getSize("default_margin").height
  40. text: "Cura project name"
  41. font: UM.Theme.getFont("medium")
  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. UM.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. color: UM.Theme.getColor("setting_category_text")
  98. Connections
  99. {
  100. target: manager
  101. function onSelectedProjectIndexChanged()
  102. {
  103. emptyProjectLabel.visible = (manager.newProjectIndex == -1)
  104. }
  105. }
  106. }
  107. UM.Label
  108. {
  109. id: noFilesInProjectLabel
  110. anchors.horizontalCenter: parent.horizontalCenter
  111. anchors.verticalCenter: parent.verticalCenter
  112. visible: (manager.digitalFactoryFileModel.count == 0 && !emptyProjectLabel.visible && !retrievingFilesBusyIndicator.visible)
  113. text: "No supported files in this project."
  114. color: UM.Theme.getColor("setting_category_text")
  115. }
  116. BusyIndicator
  117. {
  118. // Shows up while Cura is waiting to receive the files of a project from the digital factory library
  119. id: retrievingFilesBusyIndicator
  120. anchors
  121. {
  122. verticalCenter: parent.verticalCenter
  123. horizontalCenter: parent.horizontalCenter
  124. }
  125. width: parent.width / 4
  126. height: width
  127. visible: manager.retrievingFilesStatus == DF.RetrievalStatus.InProgress
  128. running: visible
  129. palette.dark: UM.Theme.getColor("text")
  130. }
  131. Connections
  132. {
  133. target: manager.digitalFactoryFileModel
  134. function onItemsChanged()
  135. {
  136. // Make sure no files are selected when the file model changes
  137. filesTableView.currentRow = -1;
  138. }
  139. }
  140. }
  141. Cura.SecondaryButton
  142. {
  143. id: selectDifferentProjectButton
  144. anchors.bottom: parent.bottom
  145. anchors.left: parent.left
  146. text: "Change Library project"
  147. onClicked:
  148. {
  149. manager.selectedProjectIndex = -1
  150. }
  151. busy: false
  152. }
  153. Cura.PrimaryButton
  154. {
  155. id: saveButton
  156. anchors.bottom: parent.bottom
  157. anchors.right: parent.right
  158. text: "Save"
  159. enabled: (asProjectCheckbox.checked || asSlicedCheckbox.checked) && dfFilenameTextfield.text.length >= 1 && dfFilenameTextfield.state !== 'invalid'
  160. onClicked: manager.saveFileToSelectedProject(dfFilenameTextfield.text, asProjectComboBox.currentValue)
  161. busy: false
  162. }
  163. Cura.ComboBox
  164. {
  165. id: asProjectComboBox
  166. width: UM.Theme.getSize("combobox_wide").width
  167. height: saveButton.height
  168. anchors.verticalCenter: saveButton.verticalCenter
  169. anchors.right: saveButton.left
  170. anchors.rightMargin: UM.Theme.getSize("thin_margin").height
  171. enabled: UM.Backend.state == UM.Backend.Done
  172. currentIndex: UM.Backend.state == UM.Backend.Done ? dfFilenameTextfield.text.startsWith("MM")? 1 : 0 : 2
  173. textRole: "text"
  174. valueRole: "value"
  175. model: [
  176. { text: catalog.i18nc("@option", "Save Cura project and .ufp print file"), key: "3mf_ufp", value: ["3mf", "ufp"] },
  177. { text: catalog.i18nc("@option", "Save Cura project and .makerbot print file"), key: "3mf_makerbot", value: ["3mf", "makerbot"] },
  178. { text: catalog.i18nc("@option", "Save Cura project"), key: "3mf", value: ["3mf"] },
  179. ]
  180. }
  181. Component.onCompleted:
  182. {
  183. saveButton.clicked.connect(base.savePressed)
  184. selectDifferentProjectButton.clicked.connect(base.selectDifferentProjectPressed)
  185. }
  186. onModelRowsChanged:
  187. {
  188. tableModel.clear()
  189. tableModel.rows = modelRows
  190. }
  191. }