OpenProjectFilesPage.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 openFilePressed()
  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. Rectangle
  35. {
  36. id: projectFilesContent
  37. width: parent.width
  38. anchors.top: projectSummaryCard.bottom
  39. anchors.topMargin: UM.Theme.getSize("default_margin").width
  40. anchors.bottom: selectDifferentProjectButton.top
  41. anchors.bottomMargin: UM.Theme.getSize("default_margin").width
  42. color: UM.Theme.getColor("main_background")
  43. border.width: UM.Theme.getSize("default_lining").width
  44. border.color: UM.Theme.getColor("lining")
  45. // This is not backwards compatible with Cura < 5.0 due to QT.labs being removed in PyQt6
  46. Cura.TableView
  47. {
  48. id: filesTableView
  49. anchors.fill: parent
  50. anchors.margins: parent.border.width
  51. columnHeaders: ["Name", "Uploaded by", "Uploaded at"]
  52. model: UM.TableModel
  53. {
  54. id: tableModel
  55. headers: ["fileName", "username", "uploadedAt"]
  56. rows: modelRows
  57. }
  58. onCurrentRowChanged:
  59. {
  60. manager.setSelectedFileIndices([currentRow]);
  61. }
  62. onDoubleClicked: function(row)
  63. {
  64. manager.setSelectedFileIndices([row]);
  65. openFilesButton.clicked();
  66. }
  67. }
  68. UM.Label
  69. {
  70. id: emptyProjectLabel
  71. anchors.horizontalCenter: parent.horizontalCenter
  72. anchors.verticalCenter: parent.verticalCenter
  73. text: "Select a project to view its files."
  74. color: UM.Theme.getColor("setting_category_text")
  75. Connections
  76. {
  77. target: manager
  78. function onSelectedProjectIndexChanged(newProjectIndex)
  79. {
  80. emptyProjectLabel.visible = (newProjectIndex == -1)
  81. }
  82. }
  83. }
  84. UM.Label
  85. {
  86. id: noFilesInProjectLabel
  87. anchors.horizontalCenter: parent.horizontalCenter
  88. anchors.verticalCenter: parent.verticalCenter
  89. visible: (manager.digitalFactoryFileModel.count == 0 && !emptyProjectLabel.visible && !retrievingFilesBusyIndicator.visible)
  90. text: "No supported files in this project."
  91. color: UM.Theme.getColor("setting_category_text")
  92. }
  93. BusyIndicator
  94. {
  95. // Shows up while Cura is waiting to receive the files of a project from the digital factory library
  96. id: retrievingFilesBusyIndicator
  97. anchors
  98. {
  99. verticalCenter: parent.verticalCenter
  100. horizontalCenter: parent.horizontalCenter
  101. }
  102. width: parent.width / 4
  103. height: width
  104. visible: manager.retrievingFilesStatus == DF.RetrievalStatus.InProgress
  105. running: visible
  106. palette.dark: UM.Theme.getColor("text")
  107. }
  108. Connections
  109. {
  110. target: manager.digitalFactoryFileModel
  111. function onItemsChanged()
  112. {
  113. // Make sure no files are selected when the file model changes
  114. filesTableView.currentRow = -1
  115. }
  116. }
  117. }
  118. Cura.SecondaryButton
  119. {
  120. id: selectDifferentProjectButton
  121. anchors.bottom: parent.bottom
  122. anchors.left: parent.left
  123. text: "Change Library project"
  124. onClicked:
  125. {
  126. manager.clearProjectSelection()
  127. }
  128. busy: false
  129. }
  130. Cura.PrimaryButton
  131. {
  132. id: openFilesButton
  133. anchors.bottom: parent.bottom
  134. anchors.right: parent.right
  135. text: "Open"
  136. enabled: filesTableView.currentRow >= 0
  137. onClicked:
  138. {
  139. manager.openSelectedFiles()
  140. }
  141. busy: false
  142. }
  143. Component.onCompleted:
  144. {
  145. openFilesButton.clicked.connect(base.openFilePressed)
  146. selectDifferentProjectButton.clicked.connect(base.selectDifferentProjectPressed)
  147. }
  148. onModelRowsChanged:
  149. {
  150. tableModel.clear()
  151. tableModel.rows = modelRows
  152. }
  153. }