Packages.qml 7.2 KB

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