Packages.qml 7.6 KB

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