Packages.qml 7.7 KB

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