StepPanel.qml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.3 as UM
  6. import Cura 1.1 as Cura
  7. import "../Widgets"
  8. Item
  9. {
  10. id: base
  11. clip: true
  12. property int currentStep: 0
  13. property int totalStepCount: (model == null) ? 0 : model.count
  14. property real progressValue: (totalStepCount == 0) ? 0 : (currentStep / totalStepCount)
  15. property var currentItem: (model == null) ? null : model.getItem(currentStep)
  16. property var model: null
  17. signal showNextPage()
  18. signal showPreviousPage()
  19. signal passLastPage() // Emitted when there is no more page to show
  20. signal goToPage(string page_id) // Go to a specific page by the given page_id.
  21. onShowNextPage:
  22. {
  23. if (currentStep < totalStepCount - 1)
  24. {
  25. currentStep++
  26. }
  27. else
  28. {
  29. passLastPage()
  30. }
  31. }
  32. onShowPreviousPage:
  33. {
  34. if (currentStep > 0)
  35. {
  36. currentStep--
  37. }
  38. }
  39. onGoToPage:
  40. {
  41. // find the page index
  42. var page_index = -1
  43. for (var i = 0; i < base.model.count; i++)
  44. {
  45. const item = base.model.getItem(i)
  46. if (item.id == page_id)
  47. {
  48. page_index = i
  49. break
  50. }
  51. }
  52. if (page_index > 0)
  53. {
  54. currentStep = page_index
  55. }
  56. }
  57. onVisibleChanged:
  58. {
  59. if (visible)
  60. {
  61. base.currentStep = 0
  62. base.currentItem = base.model.getItem(base.currentStep)
  63. }
  64. }
  65. onModelChanged:
  66. {
  67. base.currentStep = 0
  68. }
  69. Rectangle // Panel background
  70. {
  71. id: panelBackground
  72. anchors.fill: parent
  73. radius: UM.Theme.getSize("default_radius").width
  74. CuraProgressBar
  75. {
  76. id: progressBar
  77. anchors.top: parent.top
  78. anchors.left: parent.left
  79. anchors.right: parent.right
  80. height: UM.Theme.getSize("progressbar").height
  81. value: base.progressValue
  82. }
  83. Loader
  84. {
  85. id: contentLoader
  86. anchors
  87. {
  88. margins: base.contentMargins
  89. top: progressBar.bottom
  90. bottom: parent.bottom
  91. left: parent.left
  92. right: parent.right
  93. }
  94. source: base.currentItem.page_url
  95. }
  96. }
  97. }