Topbar.qml 9.5 KB

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