Packages.qml 7.0 KB

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