SliceProcessWidget.qml 5.4 KB

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