SliceProcessWidget.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. Cura.IconLabel
  35. {
  36. id: message
  37. width: parent.width
  38. visible: widget.backendState == UM.Backend.Error
  39. text: catalog.i18nc("@label:PrintjobStatus", "Unable to Slice")
  40. source: UM.Theme.getIcon("warning")
  41. color: UM.Theme.getColor("warning")
  42. font: UM.Theme.getFont("very_small")
  43. }
  44. // Progress bar, only visible when the backend is in the process of slice the printjob
  45. ProgressBar
  46. {
  47. id: progressBar
  48. width: parent.width
  49. height: UM.Theme.getSize("progressbar").height
  50. value: progress
  51. visible: widget.backendState == UM.Backend.Processing
  52. background: Rectangle
  53. {
  54. anchors.fill: parent
  55. radius: UM.Theme.getSize("progressbar_radius").width
  56. color: UM.Theme.getColor("progressbar_background")
  57. }
  58. contentItem: Item
  59. {
  60. anchors.fill: parent
  61. Rectangle
  62. {
  63. width: progressBar.visualPosition * parent.width
  64. height: parent.height
  65. radius: UM.Theme.getSize("progressbar_radius").width
  66. color: UM.Theme.getColor("progressbar_control")
  67. }
  68. }
  69. }
  70. Cura.ActionButton
  71. {
  72. id: prepareButton
  73. width: parent.width
  74. height: UM.Theme.getSize("action_panel_button").height
  75. fixedWidthMode: true
  76. // Get the current value from the preferences
  77. property bool autoSlice: UM.Preferences.getValue("general/auto_slice")
  78. // Disable the slice process when
  79. property bool disabledSlice: [UM.Backend.Done, UM.Backend.Error].indexOf(widget.backendState) != -1
  80. property bool isSlicing: [UM.Backend.NotStarted, UM.Backend.Error].indexOf(widget.backendState) == -1
  81. text: isSlicing ? catalog.i18nc("@button", "Cancel") : catalog.i18nc("@button", "Slice")
  82. enabled: !autoSlice && !disabledSlice
  83. visible: !autoSlice
  84. color: isSlicing ? UM.Theme.getColor("secondary"): UM.Theme.getColor("primary")
  85. textColor: isSlicing ? UM.Theme.getColor("primary"): UM.Theme.getColor("button_text")
  86. outlineColor: "transparent"
  87. disabledColor: UM.Theme.getColor("action_button_disabled")
  88. textDisabledColor: UM.Theme.getColor("action_button_disabled_text")
  89. shadowEnabled: true
  90. shadowColor: isSlicing ? UM.Theme.getColor("secondary_shadow") : enabled ? UM.Theme.getColor("action_button_shadow"): UM.Theme.getColor("action_button_disabled_shadow")
  91. onClicked: sliceOrStopSlicing()
  92. }
  93. // React when the user changes the preference of having the auto slice enabled
  94. Connections
  95. {
  96. target: UM.Preferences
  97. onPreferenceChanged:
  98. {
  99. var autoSlice = UM.Preferences.getValue("general/auto_slice")
  100. prepareButton.autoSlice = autoSlice
  101. }
  102. }
  103. // Shortcut for "slice/stop"
  104. Controls1.Action
  105. {
  106. shortcut: "Ctrl+P"
  107. onTriggered:
  108. {
  109. if (prepareButton.enabled)
  110. {
  111. sliceOrStopSlicing()
  112. }
  113. }
  114. }
  115. }