Packages.qml 7.1 KB

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