Packages.qml 6.7 KB

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