SliceProcessWidget.qml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.4
  5. import QtQuick.Layouts 1.3
  6. import UM 1.4 as UM
  7. import Cura 1.0 as Cura
  8. // This element contains all the elements the user needs to create a printjob from the
  9. // model(s) that is(are) on the buildplate. Mainly the button to start/stop the slicing
  10. // process and a progress bar to see the progress of the process.
  11. Column
  12. {
  13. id: widget
  14. spacing: UM.Theme.getSize("thin_margin").height
  15. UM.I18nCatalog
  16. {
  17. id: catalog
  18. name: "cura"
  19. }
  20. property real progress: UM.Backend.progress
  21. property int backendState: UM.Backend.state
  22. // As the collection of settings to send to the engine might take some time, we have an extra value to indicate
  23. // That the user pressed the button but it's still waiting for the backend to acknowledge that it got it.
  24. property bool waitingForSliceToStart: false
  25. onBackendStateChanged: waitingForSliceToStart = false
  26. function sliceOrStopSlicing()
  27. {
  28. if (widget.backendState == UM.Backend.NotStarted)
  29. {
  30. widget.waitingForSliceToStart = true
  31. CuraApplication.backend.forceSlice()
  32. }
  33. else
  34. {
  35. widget.waitingForSliceToStart = false
  36. CuraApplication.backend.stopSlicing()
  37. }
  38. }
  39. Label
  40. {
  41. id: autoSlicingLabel
  42. width: parent.width
  43. visible: progressBar.visible
  44. text: catalog.i18nc("@label:PrintjobStatus", "Slicing...")
  45. color: UM.Theme.getColor("text")
  46. font: UM.Theme.getFont("default")
  47. renderType: Text.NativeRendering
  48. }
  49. Item
  50. {
  51. id: unableToSliceMessage
  52. width: parent.width
  53. visible: widget.backendState == UM.Backend.Error
  54. height: warningIcon.height
  55. UM.StatusIcon
  56. {
  57. id: warningIcon
  58. anchors.verticalCenter: parent.verticalCenter
  59. width: visible ? UM.Theme.getSize("section_icon").width : 0
  60. height: width
  61. status: UM.StatusIcon.Status.WARNING
  62. }
  63. Label
  64. {
  65. id: label
  66. anchors.left: warningIcon.right
  67. anchors.right: parent.right
  68. anchors.verticalCenter: parent.verticalCenter
  69. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  70. text: catalog.i18nc("@label:PrintjobStatus", "Unable to slice")
  71. color: UM.Theme.getColor("text")
  72. font: UM.Theme.getFont("default")
  73. renderType: Text.NativeRendering
  74. wrapMode: Text.WordWrap
  75. }
  76. }
  77. // Progress bar, only visible when the backend is in the process of slice the printjob
  78. UM.ProgressBar
  79. {
  80. id: progressBar
  81. width: parent.width
  82. height: UM.Theme.getSize("progressbar").height
  83. value: progress
  84. indeterminate: widget.backendState == UM.Backend.NotStarted
  85. visible: (widget.backendState == UM.Backend.Processing || (prepareButtons.autoSlice && widget.backendState == UM.Backend.NotStarted))
  86. }
  87. Item
  88. {
  89. id: prepareButtons
  90. // Get the current value from the preferences
  91. property bool autoSlice: UM.Preferences.getValue("general/auto_slice")
  92. // Disable the slice process when
  93. width: parent.width
  94. height: UM.Theme.getSize("action_button").height
  95. visible: !autoSlice
  96. Cura.PrimaryButton
  97. {
  98. id: sliceButton
  99. fixedWidthMode: true
  100. height: parent.height
  101. anchors.right: parent.right
  102. anchors.left: parent.left
  103. text: widget.waitingForSliceToStart ? catalog.i18nc("@button", "Processing"): catalog.i18nc("@button", "Slice")
  104. tooltip: catalog.i18nc("@label", "Start the slicing process")
  105. enabled: widget.backendState != UM.Backend.Error && !widget.waitingForSliceToStart
  106. visible: widget.backendState == UM.Backend.NotStarted || widget.backendState == UM.Backend.Error
  107. onClicked: {
  108. sliceOrStopSlicing()
  109. }
  110. }
  111. Cura.SecondaryButton
  112. {
  113. id: cancelButton
  114. fixedWidthMode: true
  115. height: parent.height
  116. anchors.left: parent.left
  117. anchors.right: parent.right
  118. text: catalog.i18nc("@button", "Cancel")
  119. enabled: sliceButton.enabled
  120. visible: !sliceButton.visible
  121. onClicked: {
  122. sliceOrStopSlicing()
  123. }
  124. }
  125. }
  126. // React when the user changes the preference of having the auto slice enabled
  127. Connections
  128. {
  129. target: UM.Preferences
  130. function onPreferenceChanged(preference)
  131. {
  132. if (preference !== "general/auto_slice")
  133. {
  134. return;
  135. }
  136. var autoSlice = UM.Preferences.getValue("general/auto_slice")
  137. if(prepareButtons.autoSlice != autoSlice)
  138. {
  139. prepareButtons.autoSlice = autoSlice
  140. if(autoSlice)
  141. {
  142. CuraApplication.backend.forceSlice()
  143. }
  144. }
  145. }
  146. }
  147. // Shortcut for "slice/stop"
  148. Action
  149. {
  150. shortcut: "Ctrl+P"
  151. onTriggered:
  152. {
  153. if (sliceButton.enabled)
  154. {
  155. sliceOrStopSlicing()
  156. }
  157. }
  158. }
  159. }