SliceProcessWidget.qml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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.5 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. UM.Label
  40. {
  41. id: autoSlicingLabel
  42. width: parent.width
  43. visible: progressBar.visible
  44. text: catalog.i18nc("@label:PrintjobStatus", "Slicing...")
  45. }
  46. Item
  47. {
  48. id: unableToSliceMessage
  49. width: parent.width
  50. visible: widget.backendState == UM.Backend.Error
  51. height: warningIcon.height
  52. UM.StatusIcon
  53. {
  54. id: warningIcon
  55. anchors.verticalCenter: parent.verticalCenter
  56. width: visible ? UM.Theme.getSize("section_icon").width : 0
  57. height: width
  58. status: UM.StatusIcon.Status.WARNING
  59. }
  60. UM.Label
  61. {
  62. id: label
  63. anchors.left: warningIcon.right
  64. anchors.right: parent.right
  65. anchors.verticalCenter: parent.verticalCenter
  66. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  67. text: catalog.i18nc("@label:PrintjobStatus", "Unable to slice")
  68. wrapMode: Text.WordWrap
  69. }
  70. }
  71. // Progress bar, only visible when the backend is in the process of slice the printjob
  72. UM.ProgressBar
  73. {
  74. id: progressBar
  75. width: parent.width
  76. height: UM.Theme.getSize("progressbar").height
  77. value: progress
  78. indeterminate: widget.backendState == UM.Backend.NotStarted
  79. visible: (widget.backendState == UM.Backend.Processing || (prepareButtons.autoSlice && widget.backendState == UM.Backend.NotStarted))
  80. }
  81. Item
  82. {
  83. id: prepareButtons
  84. // Get the current value from the preferences
  85. property bool autoSlice: UM.Preferences.getValue("general/auto_slice")
  86. // Disable the slice process when
  87. width: parent.width
  88. height: UM.Theme.getSize("action_button").height
  89. visible: !autoSlice
  90. Cura.PrimaryButton
  91. {
  92. id: sliceButton
  93. fixedWidthMode: true
  94. height: parent.height
  95. anchors.right: parent.right
  96. anchors.left: parent.left
  97. text: widget.waitingForSliceToStart ? catalog.i18nc("@button", "Processing"): catalog.i18nc("@button", "Slice")
  98. tooltip: catalog.i18nc("@label", "Start the slicing process")
  99. hoverEnabled: !widget.waitingForSliceToStart
  100. enabled: widget.backendState != UM.Backend.Error && !widget.waitingForSliceToStart
  101. visible: widget.backendState == UM.Backend.NotStarted || widget.backendState == UM.Backend.Error
  102. onClicked: {
  103. sliceOrStopSlicing()
  104. }
  105. }
  106. Cura.SecondaryButton
  107. {
  108. id: cancelButton
  109. fixedWidthMode: true
  110. height: parent.height
  111. anchors.left: parent.left
  112. anchors.right: parent.right
  113. text: catalog.i18nc("@button", "Cancel")
  114. enabled: sliceButton.enabled
  115. visible: !sliceButton.visible
  116. onClicked: {
  117. sliceOrStopSlicing()
  118. }
  119. }
  120. }
  121. // React when the user changes the preference of having the auto slice enabled
  122. Connections
  123. {
  124. target: UM.Preferences
  125. function onPreferenceChanged(preference)
  126. {
  127. if (preference !== "general/auto_slice")
  128. {
  129. return;
  130. }
  131. var autoSlice = UM.Preferences.getValue("general/auto_slice")
  132. if(prepareButtons.autoSlice != autoSlice)
  133. {
  134. prepareButtons.autoSlice = autoSlice
  135. if(autoSlice)
  136. {
  137. CuraApplication.backend.forceSlice()
  138. }
  139. }
  140. }
  141. }
  142. // Shortcut for "slice/stop"
  143. Action
  144. {
  145. shortcut: "Ctrl+P"
  146. onTriggered:
  147. {
  148. if (sliceButton.enabled)
  149. {
  150. sliceOrStopSlicing()
  151. }
  152. }
  153. }
  154. }