SliceProcessWidget.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.1 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. function sliceOrStopSlicing()
  24. {
  25. if (widget.backendState == UM.Backend.NotStarted)
  26. {
  27. CuraApplication.backend.forceSlice()
  28. }
  29. else
  30. {
  31. CuraApplication.backend.stopSlicing()
  32. }
  33. }
  34. Label
  35. {
  36. id: autoSlicingLabel
  37. width: parent.width
  38. visible: progressBar.visible
  39. text: catalog.i18nc("@label:PrintjobStatus", "Slicing...")
  40. color: UM.Theme.getColor("text")
  41. font: UM.Theme.getFont("default")
  42. renderType: Text.NativeRendering
  43. }
  44. Cura.IconWithText
  45. {
  46. id: unableToSliceMessage
  47. width: parent.width
  48. visible: widget.backendState == UM.Backend.Error
  49. text: catalog.i18nc("@label:PrintjobStatus", "Unable to Slice")
  50. source: UM.Theme.getIcon("warning")
  51. iconColor: UM.Theme.getColor("warning")
  52. }
  53. // Progress bar, only visible when the backend is in the process of slice the printjob
  54. ProgressBar
  55. {
  56. id: progressBar
  57. width: parent.width
  58. height: UM.Theme.getSize("progressbar").height
  59. value: progress
  60. indeterminate: widget.backendState == UM.Backend.NotStarted
  61. visible: (widget.backendState == UM.Backend.Processing || (prepareButtons.autoSlice && widget.backendState == UM.Backend.NotStarted))
  62. background: Rectangle
  63. {
  64. anchors.fill: parent
  65. radius: UM.Theme.getSize("progressbar_radius").width
  66. color: UM.Theme.getColor("progressbar_background")
  67. }
  68. contentItem: Item
  69. {
  70. anchors.fill: parent
  71. Rectangle
  72. {
  73. width: progressBar.visualPosition * parent.width
  74. height: parent.height
  75. radius: UM.Theme.getSize("progressbar_radius").width
  76. color: UM.Theme.getColor("progressbar_control")
  77. }
  78. }
  79. }
  80. Item
  81. {
  82. id: prepareButtons
  83. // Get the current value from the preferences
  84. property bool autoSlice: UM.Preferences.getValue("general/auto_slice")
  85. // Disable the slice process when
  86. width: parent.width
  87. height: UM.Theme.getSize("action_button").height
  88. visible: !autoSlice
  89. Cura.PrimaryButton
  90. {
  91. id: sliceButton
  92. fixedWidthMode: true
  93. height: parent.height
  94. anchors.right: parent.right
  95. anchors.left: parent.left
  96. text: catalog.i18nc("@button", "Slice")
  97. tooltip: catalog.i18nc("@label", "Start the slicing process")
  98. enabled: widget.backendState != UM.Backend.Error
  99. visible: widget.backendState == UM.Backend.NotStarted || widget.backendState == UM.Backend.Error
  100. onClicked: sliceOrStopSlicing()
  101. }
  102. Cura.SecondaryButton
  103. {
  104. id: cancelButton
  105. fixedWidthMode: true
  106. height: parent.height
  107. anchors.left: parent.left
  108. anchors.right: parent.right
  109. text: catalog.i18nc("@button", "Cancel")
  110. enabled: sliceButton.enabled
  111. visible: !sliceButton.visible
  112. onClicked: sliceOrStopSlicing()
  113. }
  114. }
  115. // React when the user changes the preference of having the auto slice enabled
  116. Connections
  117. {
  118. target: UM.Preferences
  119. onPreferenceChanged:
  120. {
  121. if (preference !== "general/auto_slice")
  122. {
  123. return;
  124. }
  125. var autoSlice = UM.Preferences.getValue("general/auto_slice")
  126. if(prepareButtons.autoSlice != autoSlice)
  127. {
  128. prepareButtons.autoSlice = autoSlice
  129. if(autoSlice)
  130. {
  131. CuraApplication.backend.forceSlice()
  132. }
  133. }
  134. }
  135. }
  136. // Shortcut for "slice/stop"
  137. Controls1.Action
  138. {
  139. shortcut: "Ctrl+P"
  140. onTriggered:
  141. {
  142. if (sliceButton.enabled)
  143. {
  144. sliceOrStopSlicing()
  145. }
  146. }
  147. }
  148. }