OpenProjectFilesPage.qml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // Copyright (C) 2021 Ultimaker B.V.
  2. import QtQuick 2.10
  3. import QtQuick.Window 2.2
  4. import QtQuick.Controls 1.4 as OldControls // TableView doesn't exist in the QtQuick Controls 2.x in 5.10, so use the old one
  5. import QtQuick.Controls 2.3
  6. import QtQuick.Controls.Styles 1.4
  7. import UM 1.2 as UM
  8. import Cura 1.6 as Cura
  9. import DigitalFactory 1.0 as DF
  10. Item
  11. {
  12. id: base
  13. width: parent.width
  14. height: parent.height
  15. property var fileModel: manager.digitalFactoryFileModel
  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. Cura.TableView
  46. {
  47. id: filesTableView
  48. anchors.fill: parent
  49. model: manager.digitalFactoryFileModel
  50. visible: model.count != 0 && manager.retrievingFileStatus != DF.RetrievalStatus.InProgress
  51. selectionMode: OldControls.SelectionMode.SingleSelection
  52. onDoubleClicked:
  53. {
  54. manager.setSelectedFileIndices([row]);
  55. openFilesButton.clicked();
  56. }
  57. OldControls.TableViewColumn
  58. {
  59. id: fileNameColumn
  60. role: "fileName"
  61. title: "Name"
  62. width: Math.round(filesTableView.width / 3)
  63. }
  64. OldControls.TableViewColumn
  65. {
  66. id: usernameColumn
  67. role: "username"
  68. title: "Uploaded by"
  69. width: Math.round(filesTableView.width / 3)
  70. }
  71. OldControls.TableViewColumn
  72. {
  73. role: "uploadedAt"
  74. title: "Uploaded at"
  75. }
  76. Connections
  77. {
  78. target: filesTableView.selection
  79. function onSelectionChanged()
  80. {
  81. let newSelection = [];
  82. filesTableView.selection.forEach(function(rowIndex) { newSelection.push(rowIndex); });
  83. manager.setSelectedFileIndices(newSelection);
  84. }
  85. }
  86. }
  87. Label
  88. {
  89. id: emptyProjectLabel
  90. anchors.horizontalCenter: parent.horizontalCenter
  91. anchors.verticalCenter: parent.verticalCenter
  92. text: "Select a project to view its files."
  93. font: UM.Theme.getFont("default")
  94. color: UM.Theme.getColor("setting_category_text")
  95. Connections
  96. {
  97. target: manager
  98. function onSelectedProjectIndexChanged(newProjectIndex)
  99. {
  100. emptyProjectLabel.visible = (newProjectIndex == -1)
  101. }
  102. }
  103. }
  104. Label
  105. {
  106. id: noFilesInProjectLabel
  107. anchors.horizontalCenter: parent.horizontalCenter
  108. anchors.verticalCenter: parent.verticalCenter
  109. visible: (manager.digitalFactoryFileModel.count == 0 && !emptyProjectLabel.visible && !retrievingFilesBusyIndicator.visible)
  110. text: "No supported files in this project."
  111. font: UM.Theme.getFont("default")
  112. color: UM.Theme.getColor("setting_category_text")
  113. }
  114. BusyIndicator
  115. {
  116. // Shows up while Cura is waiting to receive the files of a project from the digital factory library
  117. id: retrievingFilesBusyIndicator
  118. anchors
  119. {
  120. verticalCenter: parent.verticalCenter
  121. horizontalCenter: parent.horizontalCenter
  122. }
  123. width: parent.width / 4
  124. height: width
  125. visible: manager.retrievingFilesStatus == DF.RetrievalStatus.InProgress
  126. running: visible
  127. palette.dark: UM.Theme.getColor("text")
  128. }
  129. Connections
  130. {
  131. target: manager.digitalFactoryFileModel
  132. function onItemsChanged()
  133. {
  134. // Make sure no files are selected when the file model changes
  135. filesTableView.currentRow = -1
  136. filesTableView.selection.clear()
  137. }
  138. }
  139. }
  140. Cura.SecondaryButton
  141. {
  142. id: selectDifferentProjectButton
  143. anchors.bottom: parent.bottom
  144. anchors.left: parent.left
  145. text: "Change Library project"
  146. onClicked:
  147. {
  148. manager.clearProjectSelection()
  149. }
  150. busy: false
  151. }
  152. Cura.PrimaryButton
  153. {
  154. id: openFilesButton
  155. anchors.bottom: parent.bottom
  156. anchors.right: parent.right
  157. text: "Open"
  158. enabled: filesTableView.selection.count > 0
  159. onClicked:
  160. {
  161. manager.openSelectedFiles()
  162. }
  163. busy: false
  164. }
  165. Component.onCompleted:
  166. {
  167. openFilesButton.clicked.connect(base.openFilePressed)
  168. selectDifferentProjectButton.clicked.connect(base.selectDifferentProjectPressed)
  169. }
  170. }