SliceProcessWidget.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.3 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. Cura.IconWithText
  51. {
  52. id: unableToSliceMessage
  53. width: parent.width
  54. visible: widget.backendState == UM.Backend.Error
  55. text: catalog.i18nc("@label:PrintjobStatus", "Unable to slice")
  56. source: UM.Theme.getIcon("warning")
  57. iconColor: UM.Theme.getColor("warning")
  58. }
  59. // Progress bar, only visible when the backend is in the process of slice the printjob
  60. UM.ProgressBar
  61. {
  62. id: progressBar
  63. width: parent.width
  64. height: UM.Theme.getSize("progressbar").height
  65. value: progress
  66. indeterminate: widget.backendState == UM.Backend.NotStarted
  67. visible: (widget.backendState == UM.Backend.Processing || (prepareButtons.autoSlice && widget.backendState == UM.Backend.NotStarted))
  68. }
  69. Item
  70. {
  71. id: prepareButtons
  72. // Get the current value from the preferences
  73. property bool autoSlice: UM.Preferences.getValue("general/auto_slice")
  74. // Disable the slice process when
  75. width: parent.width
  76. height: UM.Theme.getSize("action_button").height
  77. visible: !autoSlice
  78. Cura.PrimaryButton
  79. {
  80. id: sliceButton
  81. fixedWidthMode: true
  82. height: parent.height
  83. anchors.right: parent.right
  84. anchors.left: parent.left
  85. text: widget.waitingForSliceToStart ? catalog.i18nc("@button", "Processing"): catalog.i18nc("@button", "Slice")
  86. tooltip: catalog.i18nc("@label", "Start the slicing process")
  87. enabled: widget.backendState != UM.Backend.Error && !widget.waitingForSliceToStart
  88. visible: widget.backendState == UM.Backend.NotStarted || widget.backendState == UM.Backend.Error
  89. onClicked: sliceOrStopSlicing()
  90. }
  91. Cura.SecondaryButton
  92. {
  93. id: cancelButton
  94. fixedWidthMode: true
  95. height: parent.height
  96. anchors.left: parent.left
  97. anchors.right: parent.right
  98. text: catalog.i18nc("@button", "Cancel")
  99. enabled: sliceButton.enabled
  100. visible: !sliceButton.visible
  101. onClicked: sliceOrStopSlicing()
  102. }
  103. }
  104. // React when the user changes the preference of having the auto slice enabled
  105. Connections
  106. {
  107. target: UM.Preferences
  108. onPreferenceChanged:
  109. {
  110. if (preference !== "general/auto_slice")
  111. {
  112. return;
  113. }
  114. var autoSlice = UM.Preferences.getValue("general/auto_slice")
  115. if(prepareButtons.autoSlice != autoSlice)
  116. {
  117. prepareButtons.autoSlice = autoSlice
  118. if(autoSlice)
  119. {
  120. CuraApplication.backend.forceSlice()
  121. }
  122. }
  123. }
  124. }
  125. // Shortcut for "slice/stop"
  126. Controls1.Action
  127. {
  128. shortcut: "Ctrl+P"
  129. onTriggered:
  130. {
  131. if (sliceButton.enabled)
  132. {
  133. sliceOrStopSlicing()
  134. }
  135. }
  136. }
  137. }