Packages.qml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // Copyright (c) 2021 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.15
  4. import QtQuick.Controls 2.15
  5. import UM 1.4 as UM
  6. ListView
  7. {
  8. id: packages
  9. width: parent.width
  10. property string pageTitle
  11. property var selectedPackage
  12. property string searchInBrowserUrl
  13. property bool bannerVisible
  14. property var bannerIcon
  15. property string bannerText
  16. property string bannerReadMoreUrl
  17. property var onRemoveBanner
  18. property bool packagesManageableInListView
  19. clip: true
  20. Component.onCompleted: model.updatePackages()
  21. Component.onDestruction: model.cleanUpAPIRequest()
  22. spacing: UM.Theme.getSize("default_margin").height
  23. section.property: "package.sectionTitle"
  24. section.delegate: Rectangle
  25. {
  26. width: packages.width
  27. height: sectionHeaderText.height + UM.Theme.getSize("default_margin").height
  28. color: UM.Theme.getColor("detail_background")
  29. Label
  30. {
  31. id: sectionHeaderText
  32. anchors.verticalCenter: parent.verticalCenter
  33. anchors.left: parent.left
  34. text: section
  35. font: UM.Theme.getFont("large")
  36. color: UM.Theme.getColor("text")
  37. }
  38. }
  39. ScrollBar.vertical: ScrollBar
  40. {
  41. // Vertical ScrollBar, styled similarly to the scrollBar in the settings panel
  42. id: verticalScrollBar
  43. visible: packages.contentHeight > packages.height
  44. background: Item{}
  45. contentItem: Rectangle
  46. {
  47. id: scrollViewHandle
  48. implicitWidth: UM.Theme.getSize("scrollbar").width
  49. radius: Math.round(implicitWidth / 2)
  50. color: verticalScrollBar.pressed ? UM.Theme.getColor("scrollbar_handle_down") : verticalScrollBar.hovered ? UM.Theme.getColor("scrollbar_handle_hover") : UM.Theme.getColor("scrollbar_handle")
  51. Behavior on color { ColorAnimation { duration: 50; } }
  52. }
  53. }
  54. delegate: MouseArea
  55. {
  56. id: cardMouseArea
  57. width: parent ? parent.width : 0
  58. height: childrenRect.height
  59. hoverEnabled: true
  60. onClicked:
  61. {
  62. packages.selectedPackage = model.package;
  63. contextStack.push(packageDetailsComponent);
  64. }
  65. PackageCard
  66. {
  67. manageableInListView: packages.packagesManageableInListView
  68. packageData: model.package
  69. width: parent.width - UM.Theme.getSize("default_margin").width - UM.Theme.getSize("narrow_margin").width
  70. color: cardMouseArea.containsMouse ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("main_background")
  71. }
  72. }
  73. Component
  74. {
  75. id: packageDetailsComponent
  76. PackageDetails
  77. {
  78. packageData: packages.selectedPackage
  79. title: packages.pageTitle
  80. }
  81. }
  82. //Wrapper item to add spacing between content and footer.
  83. footer: Item
  84. {
  85. width: parent.width - UM.Theme.getSize("default_margin").width - UM.Theme.getSize("narrow_margin").width
  86. height: model.hasFooter || packages.model.errorMessage != "" ? UM.Theme.getSize("card").height + packages.spacing : 0
  87. visible: model.hasFooter || packages.model.errorMessage != ""
  88. Button
  89. {
  90. id: loadMoreButton
  91. width: parent.width
  92. height: UM.Theme.getSize("card").height
  93. anchors.bottom: parent.bottom
  94. enabled: packages.model.hasMore && !packages.model.isLoading || packages.model.errorMessage != ""
  95. onClicked: packages.model.updatePackages() //Load next page in plug-in list.
  96. background: Rectangle
  97. {
  98. anchors.fill: parent
  99. radius: UM.Theme.getSize("default_radius").width
  100. color: UM.Theme.getColor("main_background")
  101. }
  102. Row
  103. {
  104. anchors.centerIn: parent
  105. spacing: UM.Theme.getSize("thin_margin").width
  106. states:
  107. [
  108. State
  109. {
  110. name: "Error"
  111. when: packages.model.errorMessage != ""
  112. PropertyChanges
  113. {
  114. target: errorIcon
  115. visible: true
  116. }
  117. PropertyChanges
  118. {
  119. target: loadMoreIcon
  120. visible: false
  121. }
  122. PropertyChanges
  123. {
  124. target: loadMoreLabel
  125. text: catalog.i18nc("@button", "Failed to load packages:") + " " + packages.model.errorMessage + "\n" + catalog.i18nc("@button", "Retry?")
  126. }
  127. },
  128. State
  129. {
  130. name: "Loading"
  131. when: packages.model.isLoading
  132. PropertyChanges
  133. {
  134. target: loadMoreIcon
  135. source: UM.Theme.getIcon("ArrowDoubleCircleRight")
  136. color: UM.Theme.getColor("action_button_disabled_text")
  137. }
  138. PropertyChanges
  139. {
  140. target: loadMoreLabel
  141. text: catalog.i18nc("@button", "Loading")
  142. color: UM.Theme.getColor("action_button_disabled_text")
  143. }
  144. },
  145. State
  146. {
  147. name: "LastPage"
  148. when: !packages.model.hasMore
  149. PropertyChanges
  150. {
  151. target: loadMoreIcon
  152. visible: false
  153. }
  154. PropertyChanges
  155. {
  156. target: loadMoreLabel
  157. text: packages.model.count > 0 ? catalog.i18nc("@message", "No more results to load") : catalog.i18nc("@message", "No results found with current filter")
  158. color: UM.Theme.getColor("action_button_disabled_text")
  159. }
  160. }
  161. ]
  162. Item
  163. {
  164. width: (errorIcon.visible || loadMoreIcon.visible) ? UM.Theme.getSize("small_button_icon").width : 0
  165. height: UM.Theme.getSize("small_button_icon").height
  166. anchors.verticalCenter: loadMoreLabel.verticalCenter
  167. UM.StatusIcon
  168. {
  169. id: errorIcon
  170. anchors.fill: parent
  171. status: UM.StatusIcon.Status.ERROR
  172. visible: false
  173. }
  174. UM.RecolorImage
  175. {
  176. id: loadMoreIcon
  177. anchors.fill: parent
  178. source: UM.Theme.getIcon("ArrowDown")
  179. color: UM.Theme.getColor("secondary_button_text")
  180. RotationAnimator
  181. {
  182. target: loadMoreIcon
  183. from: 0
  184. to: 360
  185. duration: 1000
  186. loops: Animation.Infinite
  187. running: packages.model.isLoading
  188. alwaysRunToEnd: true
  189. }
  190. }
  191. }
  192. Label
  193. {
  194. id: loadMoreLabel
  195. text: catalog.i18nc("@button", "Load more")
  196. font: UM.Theme.getFont("medium_bold")
  197. color: UM.Theme.getColor("secondary_button_text")
  198. }
  199. }
  200. }
  201. }
  202. }