Packages.qml 7.7 KB

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