SliceProcessWidget.qml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. Column
  10. {
  11. id: widget
  12. width: UM.Theme.getSize("action_panel_button").width
  13. spacing: UM.Theme.getSize("thin_margin").height
  14. UM.I18nCatalog
  15. {
  16. id: catalog
  17. name: "cura"
  18. }
  19. property real progress: UM.Backend.progress
  20. property int backendState: UM.Backend.state
  21. function sliceOrStopSlicing()
  22. {
  23. if (widget.backendState == UM.Backend.NotStarted)
  24. {
  25. CuraApplication.backend.forceSlice()
  26. }
  27. else
  28. {
  29. CuraApplication.backend.stopSlicing()
  30. }
  31. }
  32. Cura.IconLabel
  33. {
  34. id: message
  35. width: parent.width
  36. visible: widget.backendState == UM.Backend.Error
  37. text: catalog.i18nc("@label:PrintjobStatus", "Unable to Slice")
  38. source: UM.Theme.getIcon("warning")
  39. color: UM.Theme.getColor("warning")
  40. font: UM.Theme.getFont("very_small")
  41. }
  42. // Progress bar, only visible when the backend is in the process of slice the printjob
  43. ProgressBar
  44. {
  45. id: progressBar
  46. width: parent.width
  47. height: UM.Theme.getSize("progressbar").height
  48. value: progress
  49. visible: widget.backendState == UM.Backend.Processing
  50. background: Rectangle
  51. {
  52. anchors.fill: parent
  53. radius: UM.Theme.getSize("progressbar_radius").width
  54. color: UM.Theme.getColor("progressbar_background")
  55. }
  56. contentItem: Item
  57. {
  58. anchors.fill: parent
  59. Rectangle
  60. {
  61. width: progressBar.visualPosition * parent.width
  62. height: parent.height
  63. radius: UM.Theme.getSize("progressbar_radius").width
  64. color: UM.Theme.getColor("progressbar_control")
  65. }
  66. }
  67. }
  68. Cura.ActionButton
  69. {
  70. id: prepareButton
  71. width: parent.width
  72. height: UM.Theme.getSize("action_panel_button").height
  73. text:
  74. {
  75. if ([UM.Backend.NotStarted, UM.Backend.Error].indexOf(widget.backendState) != -1)
  76. {
  77. return catalog.i18nc("@button", "Slice")
  78. }
  79. if (autoSlice)
  80. {
  81. return catalog.i18nc("@button", "Auto slicing...")
  82. }
  83. return catalog.i18nc("@button", "Cancel")
  84. }
  85. enabled: !autoSlice && !disabledSlice
  86. // Get the current value from the preferences
  87. property bool autoSlice: UM.Preferences.getValue("general/auto_slice")
  88. // Disable the slice process when
  89. property bool disabledSlice: [UM.Backend.Done, UM.Backend.Error].indexOf(widget.backendState) != -1
  90. disabledColor: disabledSlice ? UM.Theme.getColor("action_button_disabled") : "transparent"
  91. textDisabledColor: disabledSlice ? UM.Theme.getColor("action_button_disabled_text") : UM.Theme.getColor("primary")
  92. outlineDisabledColor: disabledSlice ? UM.Theme.getColor("action_button_disabled_border") : "transparent"
  93. onClicked: sliceOrStopSlicing()
  94. }
  95. // React when the user changes the preference of having the auto slice enabled
  96. Connections
  97. {
  98. target: UM.Preferences
  99. onPreferenceChanged:
  100. {
  101. var autoSlice = UM.Preferences.getValue("general/auto_slice")
  102. prepareButton.autoSlice = autoSlice
  103. }
  104. }
  105. // Shortcut for "slice/stop"
  106. Controls1.Action
  107. {
  108. shortcut: "Ctrl+P"
  109. onTriggered:
  110. {
  111. if (prepareButton.enabled)
  112. {
  113. sliceOrStopSlicing()
  114. }
  115. }
  116. }
  117. }