Topbar.qml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // Copyright (c) 2017 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. import "Menus"
  10. Rectangle
  11. {
  12. id: base
  13. anchors.left: parent.left
  14. anchors.right: parent.right
  15. height: UM.Theme.getSize("sidebar_header").height
  16. color: base.monitoringPrint ? UM.Theme.getColor("topbar_background_color_monitoring") : UM.Theme.getColor("topbar_background_color")
  17. Behavior on color { ColorAnimation { duration: 100; } }
  18. property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
  19. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  20. property bool monitoringPrint: false
  21. // outgoing signal
  22. signal startMonitoringPrint()
  23. signal stopMonitoringPrint()
  24. // update monitoring status when event was triggered outside topbar
  25. Component.onCompleted: {
  26. startMonitoringPrint.connect(function () {
  27. base.monitoringPrint = true
  28. })
  29. stopMonitoringPrint.connect(function () {
  30. base.monitoringPrint = false
  31. })
  32. }
  33. UM.I18nCatalog
  34. {
  35. id: catalog
  36. name:"cura"
  37. }
  38. Image
  39. {
  40. id: logo
  41. anchors.left: parent.left
  42. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  43. anchors.verticalCenter: parent.verticalCenter
  44. source: UM.Theme.getImage("logo");
  45. width: UM.Theme.getSize("logo").width;
  46. height: UM.Theme.getSize("logo").height;
  47. sourceSize.width: width;
  48. sourceSize.height: height;
  49. }
  50. Row
  51. {
  52. anchors.left: logo.right
  53. anchors.leftMargin: UM.Theme.getSize("topbar_logo_right_margin").width
  54. anchors.right: machineSelection.left
  55. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  56. spacing: UM.Theme.getSize("default_margin").width
  57. Button
  58. {
  59. id: showSettings
  60. height: UM.Theme.getSize("sidebar_header").height
  61. text: catalog.i18nc("@title:tab", "Prepare")
  62. checkable: true
  63. checked: isChecked()
  64. exclusiveGroup: sidebarHeaderBarGroup
  65. style: UM.Theme.styles.topbar_header_tab
  66. // We use a Qt.binding to re-bind the checkbox state after manually setting it
  67. // https://stackoverflow.com/questions/38798450/qt-5-7-qml-why-are-my-checkbox-property-bindings-disappearing
  68. onClicked: {
  69. base.stopMonitoringPrint()
  70. checked = Qt.binding(isChecked)
  71. }
  72. function isChecked () {
  73. return !base.monitoringPrint
  74. }
  75. property color overlayColor: "transparent"
  76. property string overlayIconSource: ""
  77. }
  78. Button
  79. {
  80. id: showMonitor
  81. width: UM.Theme.getSize("topbar_button").width
  82. height: UM.Theme.getSize("sidebar_header").height
  83. text: catalog.i18nc("@title:tab", "Monitor")
  84. checkable: true
  85. checked: isChecked()
  86. exclusiveGroup: sidebarHeaderBarGroup
  87. style: UM.Theme.styles.topbar_header_tab_no_overlay
  88. // We use a Qt.binding to re-bind the checkbox state after manually setting it
  89. // https://stackoverflow.com/questions/38798450/qt-5-7-qml-why-are-my-checkbox-property-bindings-disappearing
  90. onClicked: {
  91. base.startMonitoringPrint()
  92. checked = Qt.binding(isChecked)
  93. }
  94. function isChecked () {
  95. return base.monitoringPrint
  96. }
  97. property string iconSource:
  98. {
  99. if (!printerConnected)
  100. {
  101. return UM.Theme.getIcon("tab_status_unknown");
  102. }
  103. else if (!printerAcceptsCommands)
  104. {
  105. return UM.Theme.getIcon("tab_status_unknown");
  106. }
  107. if (Cura.MachineManager.printerOutputDevices[0].printerState == "maintenance")
  108. {
  109. return UM.Theme.getIcon("tab_status_busy");
  110. }
  111. switch (Cura.MachineManager.printerOutputDevices[0].jobState)
  112. {
  113. case "printing":
  114. case "pre_print":
  115. case "pausing":
  116. case "resuming":
  117. return UM.Theme.getIcon("tab_status_busy");
  118. case "wait_cleanup":
  119. return UM.Theme.getIcon("tab_status_finished");
  120. case "ready":
  121. case "":
  122. return UM.Theme.getIcon("tab_status_connected")
  123. case "paused":
  124. return UM.Theme.getIcon("tab_status_paused")
  125. case "error":
  126. return UM.Theme.getIcon("tab_status_stopped")
  127. default:
  128. return UM.Theme.getIcon("tab_status_unknown")
  129. }
  130. }
  131. }
  132. ExclusiveGroup { id: sidebarHeaderBarGroup }
  133. }
  134. ToolButton
  135. {
  136. id: machineSelection
  137. text: Cura.MachineManager.activeMachineName
  138. width: UM.Theme.getSize("sidebar").width
  139. height: UM.Theme.getSize("sidebar_header").height
  140. tooltip: Cura.MachineManager.activeMachineName
  141. anchors.verticalCenter: parent.verticalCenter
  142. anchors.right: parent.right
  143. style: ButtonStyle
  144. {
  145. background: Rectangle
  146. {
  147. color:
  148. {
  149. if(control.pressed)
  150. {
  151. return UM.Theme.getColor("sidebar_header_active");
  152. }
  153. else if(control.hovered)
  154. {
  155. return UM.Theme.getColor("sidebar_header_hover");
  156. }
  157. else
  158. {
  159. return UM.Theme.getColor("sidebar_header_bar");
  160. }
  161. }
  162. Behavior on color { ColorAnimation { duration: 50; } }
  163. UM.RecolorImage
  164. {
  165. id: downArrow
  166. anchors.verticalCenter: parent.verticalCenter
  167. anchors.right: parent.right
  168. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  169. width: UM.Theme.getSize("standard_arrow").width
  170. height: UM.Theme.getSize("standard_arrow").height
  171. sourceSize.width: width
  172. sourceSize.height: width
  173. color: UM.Theme.getColor("text_emphasis")
  174. source: UM.Theme.getIcon("arrow_bottom")
  175. }
  176. Label
  177. {
  178. id: sidebarComboBoxLabel
  179. color: UM.Theme.getColor("sidebar_header_text_active")
  180. text: control.text;
  181. elide: Text.ElideRight;
  182. anchors.left: parent.left;
  183. anchors.leftMargin: UM.Theme.getSize("default_margin").width * 2
  184. anchors.right: downArrow.left;
  185. anchors.rightMargin: control.rightMargin;
  186. anchors.verticalCenter: parent.verticalCenter;
  187. font: UM.Theme.getFont("large")
  188. }
  189. }
  190. label: Label {}
  191. }
  192. menu: PrinterMenu { }
  193. }
  194. ComboBox
  195. {
  196. id: viewModeButton
  197. anchors
  198. {
  199. verticalCenter: parent.verticalCenter
  200. right: parent.right
  201. rightMargin: UM.Theme.getSize("sidebar").width + UM.Theme.getSize("default_margin").width
  202. }
  203. style: UM.Theme.styles.combobox
  204. visible: !base.monitoringPrint
  205. model: UM.ViewModel { }
  206. textRole: "name"
  207. onCurrentIndexChanged:
  208. {
  209. UM.Controller.setActiveView(model.getItem(currentIndex).id);
  210. // Update the active flag
  211. for (var i = 0; i < model.rowCount; ++i)
  212. {
  213. const is_active = i == currentIndex;
  214. model.getItem(i).active = is_active;
  215. }
  216. }
  217. currentIndex:
  218. {
  219. for (var i = 0; i < model.rowCount; ++i)
  220. {
  221. if (model.getItem(i).active)
  222. {
  223. return i;
  224. }
  225. }
  226. return 0;
  227. }
  228. }
  229. Loader
  230. {
  231. id: view_panel
  232. anchors.top: viewModeButton.bottom
  233. anchors.topMargin: UM.Theme.getSize("default_margin").height
  234. anchors.right: viewModeButton.right
  235. property var buttonTarget: Qt.point(viewModeButton.x + viewModeButton.width / 2, viewModeButton.y + viewModeButton.height / 2)
  236. height: childrenRect.height;
  237. source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : "";
  238. }
  239. }