Packages.qml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. delegate: Rectangle
  21. {
  22. width: packagesListview.width
  23. height: UM.Theme.getSize("card").height
  24. color: UM.Theme.getColor("main_background")
  25. radius: UM.Theme.getSize("default_radius").width
  26. Label
  27. {
  28. anchors.verticalCenter: parent.verticalCenter
  29. anchors.left: parent.left
  30. anchors.leftMargin: Math.round((parent.height - height) / 2)
  31. text: model.package.displayName
  32. font: UM.Theme.getFont("medium_bold")
  33. color: UM.Theme.getColor("text")
  34. }
  35. }
  36. //Wrapper item to add spacing between content and footer.
  37. footer: Item
  38. {
  39. width: parent.width
  40. height: UM.Theme.getSize("card").height + packagesListview.spacing
  41. Button
  42. {
  43. id: loadMoreButton
  44. width: parent.width
  45. height: UM.Theme.getSize("card").height
  46. anchors.bottom: parent.bottom
  47. enabled: packages.model.hasMore && !packages.model.isLoading || packages.model.errorMessage != ""
  48. onClicked: packages.model.updatePackages() //Load next page in plug-in list.
  49. background: Rectangle
  50. {
  51. anchors.fill: parent
  52. radius: UM.Theme.getSize("default_radius").width
  53. color: UM.Theme.getColor("main_background")
  54. }
  55. Row
  56. {
  57. anchors.centerIn: parent
  58. spacing: UM.Theme.getSize("thin_margin").width
  59. states:
  60. [
  61. State
  62. {
  63. name: "Error"
  64. when: packages.model.errorMessage != ""
  65. PropertyChanges
  66. {
  67. target: errorIcon
  68. visible: true
  69. }
  70. PropertyChanges
  71. {
  72. target: loadMoreIcon
  73. visible: false
  74. }
  75. PropertyChanges
  76. {
  77. target: loadMoreLabel
  78. text: catalog.i18nc("@button", "Failed to load packages:") + " " + packages.model.errorMessage + "\n" + catalog.i18nc("@button", "Retry?")
  79. }
  80. },
  81. State
  82. {
  83. name: "Loading"
  84. when: packages.model.isLoading
  85. PropertyChanges
  86. {
  87. target: loadMoreIcon
  88. source: UM.Theme.getIcon("ArrowDoubleCircleRight")
  89. color: UM.Theme.getColor("action_button_disabled_text")
  90. }
  91. PropertyChanges
  92. {
  93. target: loadMoreLabel
  94. text: catalog.i18nc("@button", "Loading")
  95. color: UM.Theme.getColor("action_button_disabled_text")
  96. }
  97. },
  98. State
  99. {
  100. name: "LastPage"
  101. when: !packages.model.hasMore
  102. PropertyChanges
  103. {
  104. target: loadMoreIcon
  105. visible: false
  106. }
  107. PropertyChanges
  108. {
  109. target: loadMoreLabel
  110. text: catalog.i18nc("@button", "No more results to load")
  111. color: UM.Theme.getColor("action_button_disabled_text")
  112. }
  113. }
  114. ]
  115. Item
  116. {
  117. width: (errorIcon.visible || loadMoreIcon.visible) ? UM.Theme.getSize("small_button_icon").width : 0
  118. height: UM.Theme.getSize("small_button_icon").height
  119. anchors.verticalCenter: loadMoreLabel.verticalCenter
  120. UM.StatusIcon
  121. {
  122. id: errorIcon
  123. anchors.fill: parent
  124. status: UM.StatusIcon.Status.ERROR
  125. visible: false
  126. }
  127. UM.RecolorImage
  128. {
  129. id: loadMoreIcon
  130. anchors.fill: parent
  131. source: UM.Theme.getIcon("ArrowDown")
  132. color: UM.Theme.getColor("secondary_button_text")
  133. RotationAnimator
  134. {
  135. target: loadMoreIcon
  136. from: 0
  137. to: 360
  138. duration: 1000
  139. loops: Animation.Infinite
  140. running: packages.model.isLoading
  141. alwaysRunToEnd: true
  142. }
  143. }
  144. }
  145. Label
  146. {
  147. id: loadMoreLabel
  148. text: catalog.i18nc("@button", "Load more")
  149. font: UM.Theme.getFont("medium_bold")
  150. color: UM.Theme.getColor("secondary_button_text")
  151. }
  152. }
  153. }
  154. }
  155. }
  156. }