Packages.qml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. property string pageTitle
  10. property string searchInBrowserUrl
  11. property bool bannerVisible
  12. property var bannerIcon
  13. property string bannerText
  14. property string bannerReadMoreUrl
  15. property var onRemoveBanner
  16. width: parent.width
  17. clip: true
  18. Component.onCompleted: model.updatePackages()
  19. Component.onDestruction: model.abortUpdating()
  20. //ScrollBar.vertical.policy: ScrollBar.AlwaysOff
  21. spacing: UM.Theme.getSize("default_margin").height
  22. section.property: "package.sectionTitle"
  23. section.delegate: Rectangle
  24. {
  25. width: packages.width
  26. height: sectionHeaderText.height + UM.Theme.getSize("default_margin").height
  27. color: UM.Theme.getColor("detail_background")
  28. required property string section
  29. Label
  30. {
  31. id: sectionHeaderText
  32. anchors.verticalCenter: parent.verticalCenter
  33. anchors.left: parent.left
  34. text: parent.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: PackageCard
  55. {
  56. packageData: model.package
  57. }
  58. //Wrapper item to add spacing between content and footer.
  59. footer: Item
  60. {
  61. width: parent.width - UM.Theme.getSize("default_margin").width - UM.Theme.getSize("narrow_margin").width
  62. height: model.hasFooter || packages.model.errorMessage != "" ? UM.Theme.getSize("card").height + packages.spacing : 0
  63. visible: model.hasFooter || packages.model.errorMessage != ""
  64. Button
  65. {
  66. id: loadMoreButton
  67. width: parent.width
  68. height: UM.Theme.getSize("card").height
  69. anchors.bottom: parent.bottom
  70. enabled: packages.model.hasMore && !packages.model.isLoading || packages.model.errorMessage != ""
  71. onClicked: packages.model.updatePackages() //Load next page in plug-in list.
  72. background: Rectangle
  73. {
  74. anchors.fill: parent
  75. radius: UM.Theme.getSize("default_radius").width
  76. color: UM.Theme.getColor("main_background")
  77. }
  78. Row
  79. {
  80. anchors.centerIn: parent
  81. spacing: UM.Theme.getSize("thin_margin").width
  82. states:
  83. [
  84. State
  85. {
  86. name: "Error"
  87. when: packages.model.errorMessage != ""
  88. PropertyChanges
  89. {
  90. target: errorIcon
  91. visible: true
  92. }
  93. PropertyChanges
  94. {
  95. target: loadMoreIcon
  96. visible: false
  97. }
  98. PropertyChanges
  99. {
  100. target: loadMoreLabel
  101. text: catalog.i18nc("@button", "Failed to load packages:") + " " + packages.model.errorMessage + "\n" + catalog.i18nc("@button", "Retry?")
  102. }
  103. },
  104. State
  105. {
  106. name: "Loading"
  107. when: packages.model.isLoading
  108. PropertyChanges
  109. {
  110. target: loadMoreIcon
  111. source: UM.Theme.getIcon("ArrowDoubleCircleRight")
  112. color: UM.Theme.getColor("action_button_disabled_text")
  113. }
  114. PropertyChanges
  115. {
  116. target: loadMoreLabel
  117. text: catalog.i18nc("@button", "Loading")
  118. color: UM.Theme.getColor("action_button_disabled_text")
  119. }
  120. },
  121. State
  122. {
  123. name: "LastPage"
  124. when: !packages.model.hasMore
  125. PropertyChanges
  126. {
  127. target: loadMoreIcon
  128. visible: false
  129. }
  130. PropertyChanges
  131. {
  132. target: loadMoreLabel
  133. text: packages.model.count > 0 ? catalog.i18nc("@message", "No more results to load") : catalog.i18nc("@message", "No results found with current filter")
  134. color: UM.Theme.getColor("action_button_disabled_text")
  135. }
  136. }
  137. ]
  138. Item
  139. {
  140. width: (errorIcon.visible || loadMoreIcon.visible) ? UM.Theme.getSize("small_button_icon").width : 0
  141. height: UM.Theme.getSize("small_button_icon").height
  142. anchors.verticalCenter: loadMoreLabel.verticalCenter
  143. UM.StatusIcon
  144. {
  145. id: errorIcon
  146. anchors.fill: parent
  147. status: UM.StatusIcon.Status.ERROR
  148. visible: false
  149. }
  150. UM.RecolorImage
  151. {
  152. id: loadMoreIcon
  153. anchors.fill: parent
  154. source: UM.Theme.getIcon("ArrowDown")
  155. color: UM.Theme.getColor("secondary_button_text")
  156. RotationAnimator
  157. {
  158. target: loadMoreIcon
  159. from: 0
  160. to: 360
  161. duration: 1000
  162. loops: Animation.Infinite
  163. running: packages.model.isLoading
  164. alwaysRunToEnd: true
  165. }
  166. }
  167. }
  168. Label
  169. {
  170. id: loadMoreLabel
  171. text: catalog.i18nc("@button", "Load more")
  172. font: UM.Theme.getFont("medium_bold")
  173. color: UM.Theme.getColor("secondary_button_text")
  174. }
  175. }
  176. }
  177. }
  178. }