Topbar.qml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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.4 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: UM.Controller.activeStage.stageId == "MonitorStage" ? 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. UM.I18nCatalog
  20. {
  21. id: catalog
  22. name:"cura"
  23. }
  24. Image
  25. {
  26. id: logo
  27. anchors.left: parent.left
  28. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  29. anchors.verticalCenter: parent.verticalCenter
  30. source: UM.Theme.getImage("logo");
  31. width: UM.Theme.getSize("logo").width;
  32. height: UM.Theme.getSize("logo").height;
  33. sourceSize.width: width;
  34. sourceSize.height: height;
  35. }
  36. Row
  37. {
  38. anchors.left: logo.right
  39. anchors.leftMargin: UM.Theme.getSize("topbar_logo_right_margin").width
  40. anchors.right: machineSelection.left
  41. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  42. spacing: UM.Theme.getSize("default_margin").width
  43. // The topbar is dynamically filled with all available stages
  44. Repeater
  45. {
  46. id: stagesMenu
  47. model: UM.StageModel{}
  48. delegate: Button
  49. {
  50. text: model.name
  51. checkable: true
  52. checked: model.active
  53. exclusiveGroup: topbarMenuGroup
  54. style: (model.stage.iconSource != "") ? UM.Theme.styles.topbar_header_tab_no_overlay : UM.Theme.styles.topbar_header_tab
  55. height: UM.Theme.getSize("sidebar_header").height
  56. onClicked: UM.Controller.setActiveStage(model.id)
  57. iconSource: model.stage.iconSource
  58. property color overlayColor: "transparent"
  59. property string overlayIconSource: ""
  60. }
  61. }
  62. ExclusiveGroup { id: topbarMenuGroup }
  63. }
  64. ToolButton
  65. {
  66. id: machineSelection
  67. text: Cura.MachineManager.activeMachineName
  68. width: UM.Theme.getSize("sidebar").width
  69. height: UM.Theme.getSize("sidebar_header").height
  70. tooltip: Cura.MachineManager.activeMachineName
  71. anchors.verticalCenter: parent.verticalCenter
  72. anchors.right: parent.right
  73. style: ButtonStyle
  74. {
  75. background: Rectangle
  76. {
  77. color:
  78. {
  79. if(control.pressed)
  80. {
  81. return UM.Theme.getColor("sidebar_header_active");
  82. }
  83. else if(control.hovered)
  84. {
  85. return UM.Theme.getColor("sidebar_header_hover");
  86. }
  87. else
  88. {
  89. return UM.Theme.getColor("sidebar_header_bar");
  90. }
  91. }
  92. Behavior on color { ColorAnimation { duration: 50; } }
  93. UM.RecolorImage
  94. {
  95. id: downArrow
  96. anchors.verticalCenter: parent.verticalCenter
  97. anchors.right: parent.right
  98. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  99. width: UM.Theme.getSize("standard_arrow").width
  100. height: UM.Theme.getSize("standard_arrow").height
  101. sourceSize.width: width
  102. sourceSize.height: width
  103. color: UM.Theme.getColor("text_emphasis")
  104. source: UM.Theme.getIcon("arrow_bottom")
  105. }
  106. Label
  107. {
  108. id: sidebarComboBoxLabel
  109. color: UM.Theme.getColor("sidebar_header_text_active")
  110. text: control.text;
  111. elide: Text.ElideRight;
  112. anchors.left: parent.left;
  113. anchors.leftMargin: UM.Theme.getSize("default_margin").width * 2
  114. anchors.right: downArrow.left;
  115. anchors.rightMargin: control.rightMargin;
  116. anchors.verticalCenter: parent.verticalCenter;
  117. font: UM.Theme.getFont("large")
  118. }
  119. }
  120. label: Label {}
  121. }
  122. menu: PrinterMenu { }
  123. }
  124. // View orientation Item
  125. Row
  126. {
  127. id: viewOrientationControl
  128. height: 30
  129. spacing: 2
  130. visible: UM.Controller.activeStage.stageId != "MonitorStage"
  131. anchors
  132. {
  133. verticalCenter: base.verticalCenter
  134. right: viewModeButton.right
  135. rightMargin: UM.Theme.getSize("default_margin").width + viewModeButton.width
  136. }
  137. // #1 3d view
  138. Button
  139. {
  140. iconSource: UM.Theme.getIcon("view_3d")
  141. style: UM.Theme.styles.small_tool_button
  142. anchors.verticalCenter: viewOrientationControl.verticalCenter
  143. onClicked:{
  144. UM.Controller.rotateView("3d", 0);
  145. }
  146. visible: base.width > 1100
  147. }
  148. // #2 Front view
  149. Button
  150. {
  151. iconSource: UM.Theme.getIcon("view_front")
  152. style: UM.Theme.styles.small_tool_button
  153. anchors.verticalCenter: viewOrientationControl.verticalCenter
  154. onClicked:{
  155. UM.Controller.rotateView("home", 0);
  156. }
  157. visible: base.width > 1130
  158. }
  159. // #3 Top view
  160. Button
  161. {
  162. iconSource: UM.Theme.getIcon("view_top")
  163. style: UM.Theme.styles.small_tool_button
  164. anchors.verticalCenter: viewOrientationControl.verticalCenter
  165. onClicked:{
  166. UM.Controller.rotateView("y", 90);
  167. }
  168. visible: base.width > 1160
  169. }
  170. // #4 Left view
  171. Button
  172. {
  173. iconSource: UM.Theme.getIcon("view_left")
  174. style: UM.Theme.styles.small_tool_button
  175. anchors.verticalCenter: viewOrientationControl.verticalCenter
  176. onClicked:{
  177. UM.Controller.rotateView("x", 90);
  178. }
  179. visible: base.width > 1190
  180. }
  181. // #5 Left view
  182. Button
  183. {
  184. iconSource: UM.Theme.getIcon("view_right")
  185. style: UM.Theme.styles.small_tool_button
  186. anchors.verticalCenter: viewOrientationControl.verticalCenter
  187. onClicked:{
  188. UM.Controller.rotateView("x", -90);
  189. }
  190. visible: base.width > 1210
  191. }
  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: UM.Controller.activeStage.stageId != "MonitorStage"
  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. }