SliceProcessWidget.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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("very_small")
  42. renderType: Text.NativeRendering
  43. }
  44. Cura.IconLabel
  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. color: UM.Theme.getColor("warning")
  52. font: UM.Theme.getFont("very_small")
  53. }
  54. // Progress bar, only visible when the backend is in the process of slice the printjob
  55. ProgressBar
  56. {
  57. id: progressBar
  58. width: parent.width
  59. height: UM.Theme.getSize("progressbar").height
  60. value: progress
  61. indeterminate: widget.backendState == UM.Backend.NotStarted
  62. visible: (widget.backendState == UM.Backend.Processing || (prepareButtons.autoSlice && widget.backendState == UM.Backend.NotStarted))
  63. background: Rectangle
  64. {
  65. anchors.fill: parent
  66. radius: UM.Theme.getSize("progressbar_radius").width
  67. color: UM.Theme.getColor("progressbar_background")
  68. }
  69. contentItem: Item
  70. {
  71. anchors.fill: parent
  72. Rectangle
  73. {
  74. width: progressBar.visualPosition * parent.width
  75. height: parent.height
  76. radius: UM.Theme.getSize("progressbar_radius").width
  77. color: UM.Theme.getColor("progressbar_control")
  78. }
  79. }
  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_panel_button").height
  89. visible: !autoSlice
  90. Cura.PrimaryButton
  91. {
  92. id: sliceButton
  93. fixedWidthMode: true
  94. anchors.fill: parent
  95. text: catalog.i18nc("@button", "Slice")
  96. enabled: widget.backendState != UM.Backend.Error
  97. visible: widget.backendState == UM.Backend.NotStarted || widget.backendState == UM.Backend.Error
  98. onClicked: sliceOrStopSlicing()
  99. }
  100. Cura.SecondaryButton
  101. {
  102. id: cancelButton
  103. fixedWidthMode: true
  104. anchors.fill: parent
  105. text: catalog.i18nc("@button", "Cancel")
  106. enabled: sliceButton.enabled
  107. visible: !sliceButton.visible
  108. onClicked: sliceOrStopSlicing()
  109. }
  110. }
  111. // React when the user changes the preference of having the auto slice enabled
  112. Connections
  113. {
  114. target: UM.Preferences
  115. onPreferenceChanged:
  116. {
  117. var autoSlice = UM.Preferences.getValue("general/auto_slice")
  118. prepareButtons.autoSlice = autoSlice
  119. }
  120. }
  121. // Shortcut for "slice/stop"
  122. Controls1.Action
  123. {
  124. shortcut: "Ctrl+P"
  125. onTriggered:
  126. {
  127. if (prepareButton.enabled)
  128. {
  129. sliceOrStopSlicing()
  130. }
  131. }
  132. }
  133. }