PrintSetupSelector.qml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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.0
  5. import QtQuick.Layouts 1.3
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. import "Menus"
  9. import "Menus/ConfigurationMenu"
  10. Rectangle
  11. {
  12. id: base
  13. height: childrenRect.height
  14. property int currentModeIndex: -1
  15. property bool hideSettings: PrintInformation.preSliced
  16. property variant printDuration: PrintInformation.currentPrintTime
  17. property variant printMaterialLengths: PrintInformation.materialLengths
  18. property variant printMaterialWeights: PrintInformation.materialWeights
  19. property variant printMaterialCosts: PrintInformation.materialCosts
  20. property variant printMaterialNames: PrintInformation.materialNames
  21. color: UM.Theme.getColor("main_background")
  22. UM.I18nCatalog { id: catalog; name: "cura"}
  23. // This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it.
  24. signal showTooltip(Item item, point location, string text)
  25. signal hideTooltip()
  26. Timer
  27. {
  28. id: tooltipDelayTimer
  29. interval: 500
  30. repeat: false
  31. property var item
  32. property string text
  33. onTriggered:
  34. {
  35. base.showTooltip(base, {x: 0, y: item.y}, text);
  36. }
  37. }
  38. function strPadLeft(string, pad, length)
  39. {
  40. return (new Array(length + 1).join(pad) + string).slice(-length);
  41. }
  42. function getPrettyTime(time)
  43. {
  44. var hours = Math.floor(time / 3600)
  45. time -= hours * 3600
  46. var minutes = Math.floor(time / 60);
  47. time -= minutes * 60
  48. var seconds = Math.floor(time);
  49. var finalTime = strPadLeft(hours, "0", 2) + ":" + strPadLeft(minutes, "0", 2) + ":" + strPadLeft(seconds, "0", 2);
  50. return finalTime;
  51. }
  52. MouseArea
  53. {
  54. anchors.fill: parent
  55. acceptedButtons: Qt.AllButtons
  56. onWheel:
  57. {
  58. wheel.accepted = true;
  59. }
  60. }
  61. onCurrentModeIndexChanged:
  62. {
  63. UM.Preferences.setValue("cura/active_mode", currentModeIndex);
  64. }
  65. Label
  66. {
  67. id: settingsModeLabel
  68. text: !hideSettings ? catalog.i18nc("@label:listbox", "Print Setup") : catalog.i18nc("@label:listbox", "Print Setup disabled\nG-code files cannot be modified")
  69. renderType: Text.NativeRendering
  70. anchors
  71. {
  72. left: parent.left
  73. top: parent.top
  74. margins: UM.Theme.getSize("thick_margin").width
  75. }
  76. width: Math.round(parent.width * 0.45)
  77. height: contentHeight
  78. font: UM.Theme.getFont("large")
  79. color: UM.Theme.getColor("text")
  80. }
  81. ListView
  82. {
  83. // Settings mode selection toggle
  84. id: settingsModeSelection
  85. model: modesListModel
  86. width: Math.round(parent.width * 0.55)
  87. height: UM.Theme.getSize("print_setup_mode_toggle").height
  88. visible: !hideSettings
  89. anchors.right: parent.right
  90. anchors.rightMargin: UM.Theme.getSize("thick_margin").width
  91. anchors.top: settingsModeLabel.top
  92. ButtonGroup
  93. {
  94. id: modeMenuGroup
  95. }
  96. delegate: Button
  97. {
  98. id: control
  99. height: settingsModeSelection.height
  100. width: Math.round(parent.width / 2)
  101. anchors.left: parent.left
  102. anchors.leftMargin: model.index * Math.round(settingsModeSelection.width / 2)
  103. anchors.verticalCenter: parent.verticalCenter
  104. ButtonGroup.group: modeMenuGroup
  105. checkable: true
  106. checked: base.currentModeIndex == index
  107. onClicked: base.currentModeIndex = index
  108. onHoveredChanged:
  109. {
  110. if (hovered)
  111. {
  112. tooltipDelayTimer.item = settingsModeSelection
  113. tooltipDelayTimer.text = model.tooltipText
  114. tooltipDelayTimer.start()
  115. }
  116. else
  117. {
  118. tooltipDelayTimer.stop()
  119. base.hideTooltip()
  120. }
  121. }
  122. background: Rectangle
  123. {
  124. border.width: control.checked ? UM.Theme.getSize("default_lining").width * 2 : UM.Theme.getSize("default_lining").width
  125. border.color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_border") : control.hovered ? UM.Theme.getColor("action_button_hovered_border") : UM.Theme.getColor("action_button_border")
  126. // for some reason, QtQuick decided to use the color of the background property as text color for the contentItem, so here it is
  127. color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active") : control.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  128. }
  129. contentItem: Label
  130. {
  131. text: model.text
  132. font: UM.Theme.getFont("default")
  133. horizontalAlignment: Text.AlignHCenter
  134. verticalAlignment: Text.AlignVCenter
  135. renderType: Text.NativeRendering
  136. elide: Text.ElideRight
  137. color:
  138. {
  139. if(control.pressed)
  140. {
  141. return UM.Theme.getColor("action_button_active_text");
  142. }
  143. else if(control.hovered)
  144. {
  145. return UM.Theme.getColor("action_button_hovered_text");
  146. }
  147. return UM.Theme.getColor("action_button_text");
  148. }
  149. }
  150. }
  151. }
  152. Item
  153. {
  154. id: sidebarContents
  155. anchors.top: settingsModeSelection.bottom
  156. anchors.topMargin: UM.Theme.getSize("thick_margin").height
  157. anchors.left: parent.left
  158. anchors.right: parent.right
  159. height: UM.Theme.getSize("print_setup_widget").height
  160. visible: !hideSettings
  161. // We load both of them at once (instead of using a loader) because the advanced sidebar can take
  162. // quite some time to load. So in this case we sacrifice memory for speed.
  163. SidebarAdvanced
  164. {
  165. anchors.fill: parent
  166. visible: currentModeIndex == 1
  167. onShowTooltip: base.showTooltip(item, location, text)
  168. onHideTooltip: base.hideTooltip()
  169. }
  170. SidebarSimple
  171. {
  172. anchors.fill: parent
  173. visible: currentModeIndex != 1
  174. onShowTooltip: base.showTooltip(item, location, text)
  175. onHideTooltip: base.hideTooltip()
  176. }
  177. }
  178. // Setting mode: Recommended or Custom
  179. ListModel
  180. {
  181. id: modesListModel
  182. }
  183. Component.onCompleted:
  184. {
  185. modesListModel.append({
  186. text: catalog.i18nc("@title:tab", "Recommended"),
  187. tooltipText: "<b>%1</b><br/><br/>%2".arg(catalog.i18nc("@tooltip:title", "Recommended Print Setup")).arg(catalog.i18nc("@tooltip", "Print with the recommended settings for the selected printer, material and quality."))
  188. })
  189. modesListModel.append({
  190. text: catalog.i18nc("@title:tab", "Custom"),
  191. tooltipText: "<b>%1</b><br/><br/>%2".arg(catalog.i18nc("@tooltip:title", "Custom Print Setup")).arg(catalog.i18nc("@tooltip", "Print with finegrained control over every last bit of the slicing process."))
  192. })
  193. var index = Math.round(UM.Preferences.getValue("cura/active_mode"))
  194. if(index != null && !isNaN(index))
  195. {
  196. currentModeIndex = index;
  197. }
  198. else
  199. {
  200. currentModeIndex = 0;
  201. }
  202. }
  203. }