Packages.qml 7.6 KB

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