OpenProjectFilesPage.qml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. OldControls.TableViewColumn
  53. {
  54. id: fileNameColumn
  55. role: "fileName"
  56. title: "Name"
  57. width: Math.round(filesTableView.width / 3)
  58. }
  59. OldControls.TableViewColumn
  60. {
  61. id: usernameColumn
  62. role: "username"
  63. title: "Uploaded by"
  64. width: Math.round(filesTableView.width / 3)
  65. }
  66. OldControls.TableViewColumn
  67. {
  68. role: "uploadedAt"
  69. title: "Uploaded at"
  70. }
  71. Connections
  72. {
  73. target: filesTableView.selection
  74. function onSelectionChanged()
  75. {
  76. let newSelection = [];
  77. filesTableView.selection.forEach(function(rowIndex) { newSelection.push(rowIndex); });
  78. manager.setSelectedFileIndices(newSelection);
  79. }
  80. }
  81. }
  82. Label
  83. {
  84. id: emptyProjectLabel
  85. anchors.horizontalCenter: parent.horizontalCenter
  86. anchors.verticalCenter: parent.verticalCenter
  87. text: "Select a project to view its files."
  88. font: UM.Theme.getFont("default")
  89. color: UM.Theme.getColor("setting_category_text")
  90. Connections
  91. {
  92. target: manager
  93. function onSelectedProjectIndexChanged(newProjectIndex)
  94. {
  95. emptyProjectLabel.visible = (newProjectIndex == -1)
  96. }
  97. }
  98. }
  99. Label
  100. {
  101. id: noFilesInProjectLabel
  102. anchors.horizontalCenter: parent.horizontalCenter
  103. anchors.verticalCenter: parent.verticalCenter
  104. visible: (manager.digitalFactoryFileModel.count == 0 && !emptyProjectLabel.visible && !retrievingFilesBusyIndicator.visible)
  105. text: "No supported files in this project."
  106. font: UM.Theme.getFont("default")
  107. color: UM.Theme.getColor("setting_category_text")
  108. }
  109. BusyIndicator
  110. {
  111. // Shows up while Cura is waiting to receive the files of a project from the digital factory library
  112. id: retrievingFilesBusyIndicator
  113. anchors
  114. {
  115. verticalCenter: parent.verticalCenter
  116. horizontalCenter: parent.horizontalCenter
  117. }
  118. width: parent.width / 4
  119. height: width
  120. visible: manager.retrievingFilesStatus == DF.RetrievalStatus.InProgress
  121. running: visible
  122. palette.dark: UM.Theme.getColor("text")
  123. }
  124. Connections
  125. {
  126. target: manager.digitalFactoryFileModel
  127. function onItemsChanged()
  128. {
  129. // Make sure no files are selected when the file model changes
  130. filesTableView.currentRow = -1
  131. filesTableView.selection.clear()
  132. }
  133. }
  134. }
  135. Cura.SecondaryButton
  136. {
  137. id: selectDifferentProjectButton
  138. anchors.bottom: parent.bottom
  139. anchors.left: parent.left
  140. text: "Change Library project"
  141. onClicked:
  142. {
  143. manager.clearProjectSelection()
  144. }
  145. busy: false
  146. }
  147. Cura.PrimaryButton
  148. {
  149. id: openFilesButton
  150. anchors.bottom: parent.bottom
  151. anchors.right: parent.right
  152. text: "Open"
  153. enabled: filesTableView.selection.count > 0
  154. onClicked:
  155. {
  156. manager.openSelectedFiles()
  157. }
  158. busy: false
  159. }
  160. Component.onCompleted:
  161. {
  162. openFilesButton.clicked.connect(base.openFilePressed)
  163. selectDifferentProjectButton.clicked.connect(base.selectDifferentProjectPressed)
  164. }
  165. }