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