Packages.qml 7.4 KB

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