SliceProcessWidget.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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: prepareButtons.autoSlice && (widget.backendState == UM.Backend.Processing || widget.backendState == UM.Backend.NotStarted)
  39. text: catalog.i18nc("@label:PrintjobStatus", "Auto 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. anchors.fill: parent
  94. text: catalog.i18nc("@button", "Slice")
  95. enabled: widget.backendState != UM.Backend.Error
  96. visible: widget.backendState == UM.Backend.NotStarted || widget.backendState == UM.Backend.Error
  97. onClicked: sliceOrStopSlicing()
  98. }
  99. Cura.SecondaryButton
  100. {
  101. id: cancelButton
  102. fixedWidthMode: true
  103. anchors.fill: parent
  104. text: catalog.i18nc("@button", "Cancel")
  105. enabled: sliceButton.enabled
  106. visible: !sliceButton.visible
  107. onClicked: sliceOrStopSlicing()
  108. }
  109. }
  110. // React when the user changes the preference of having the auto slice enabled
  111. Connections
  112. {
  113. target: UM.Preferences
  114. onPreferenceChanged:
  115. {
  116. var autoSlice = UM.Preferences.getValue("general/auto_slice")
  117. prepareButtons.autoSlice = autoSlice
  118. if(autoSlice)
  119. {
  120. CuraApplication.backend.forceSlice()
  121. }
  122. }
  123. }
  124. // Shortcut for "slice/stop"
  125. Controls1.Action
  126. {
  127. shortcut: "Ctrl+P"
  128. onTriggered:
  129. {
  130. if (prepareButton.enabled)
  131. {
  132. sliceOrStopSlicing()
  133. }
  134. }
  135. }
  136. }