Topbar.qml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.printerConnected
  18. property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands
  19. property int rightMargin: UM.Theme.getSize("sidebar").width + UM.Theme.getSize("default_margin").width;
  20. property int allItemsWidth: 0;
  21. function updateMarginsAndSizes() {
  22. if (UM.Preferences.getValue("cura/sidebar_collapsed"))
  23. {
  24. rightMargin = UM.Theme.getSize("default_margin").width;
  25. }
  26. else
  27. {
  28. rightMargin = UM.Theme.getSize("sidebar").width + UM.Theme.getSize("default_margin").width;
  29. }
  30. allItemsWidth = (
  31. logo.width + UM.Theme.getSize("topbar_logo_right_margin").width +
  32. UM.Theme.getSize("topbar_logo_right_margin").width + stagesMenuContainer.width +
  33. UM.Theme.getSize("default_margin").width + viewModeButton.width +
  34. rightMargin);
  35. }
  36. UM.I18nCatalog
  37. {
  38. id: catalog
  39. name:"cura"
  40. }
  41. Image
  42. {
  43. id: logo
  44. anchors.left: parent.left
  45. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  46. anchors.verticalCenter: parent.verticalCenter
  47. source: UM.Theme.getImage("logo");
  48. width: UM.Theme.getSize("logo").width;
  49. height: UM.Theme.getSize("logo").height;
  50. sourceSize.width: width;
  51. sourceSize.height: height;
  52. }
  53. Row
  54. {
  55. id: stagesMenuContainer
  56. anchors.left: logo.right
  57. anchors.leftMargin: UM.Theme.getSize("topbar_logo_right_margin").width
  58. spacing: UM.Theme.getSize("default_margin").width
  59. // The topbar is dynamically filled with all available stages
  60. Repeater
  61. {
  62. id: stagesMenu
  63. model: UM.StageModel{}
  64. delegate: Button
  65. {
  66. text: model.name
  67. checkable: true
  68. checked: model.active
  69. exclusiveGroup: topbarMenuGroup
  70. style: (model.stage.iconSource != "") ? UM.Theme.styles.topbar_header_tab_no_overlay : UM.Theme.styles.topbar_header_tab
  71. height: UM.Theme.getSize("sidebar_header").height
  72. onClicked: UM.Controller.setActiveStage(model.id)
  73. iconSource: model.stage.iconSource
  74. property color overlayColor: "transparent"
  75. property string overlayIconSource: ""
  76. }
  77. }
  78. ExclusiveGroup { id: topbarMenuGroup }
  79. }
  80. // View orientation Item
  81. Row
  82. {
  83. id: viewOrientationControl
  84. height: 30
  85. spacing: 2
  86. visible: UM.Controller.activeStage.stageId != "MonitorStage"
  87. anchors
  88. {
  89. verticalCenter: base.verticalCenter
  90. right: viewModeButton.left
  91. rightMargin: UM.Theme.getSize("default_margin").width
  92. }
  93. // #1 3d view
  94. Button
  95. {
  96. iconSource: UM.Theme.getIcon("view_3d")
  97. style: UM.Theme.styles.small_tool_button
  98. anchors.verticalCenter: viewOrientationControl.verticalCenter
  99. onClicked:UM.Controller.rotateView("3d", 0)
  100. visible: base.width - allItemsWidth - 4 * this.width > 0
  101. }
  102. // #2 Front view
  103. Button
  104. {
  105. iconSource: UM.Theme.getIcon("view_front")
  106. style: UM.Theme.styles.small_tool_button
  107. anchors.verticalCenter: viewOrientationControl.verticalCenter
  108. onClicked: UM.Controller.rotateView("home", 0);
  109. visible: base.width - allItemsWidth - 3 * this.width > 0
  110. }
  111. // #3 Top view
  112. Button
  113. {
  114. iconSource: UM.Theme.getIcon("view_top")
  115. style: UM.Theme.styles.small_tool_button
  116. anchors.verticalCenter: viewOrientationControl.verticalCenter
  117. onClicked: UM.Controller.rotateView("y", 90)
  118. visible: base.width - allItemsWidth - 2 * this.width > 0
  119. }
  120. // #4 Left view
  121. Button
  122. {
  123. iconSource: UM.Theme.getIcon("view_left")
  124. style: UM.Theme.styles.small_tool_button
  125. anchors.verticalCenter: viewOrientationControl.verticalCenter
  126. onClicked: UM.Controller.rotateView("x", 90)
  127. visible: base.width - allItemsWidth - 1 * this.width > 0
  128. }
  129. // #5 Right view
  130. Button
  131. {
  132. iconSource: UM.Theme.getIcon("view_right")
  133. style: UM.Theme.styles.small_tool_button
  134. anchors.verticalCenter: viewOrientationControl.verticalCenter
  135. onClicked: UM.Controller.rotateView("x", -90)
  136. visible: base.width - allItemsWidth > 0
  137. }
  138. }
  139. ComboBox
  140. {
  141. id: viewModeButton
  142. anchors {
  143. verticalCenter: parent.verticalCenter
  144. right: parent.right
  145. rightMargin: rightMargin
  146. }
  147. style: UM.Theme.styles.combobox
  148. visible: UM.Controller.activeStage.stageId != "MonitorStage"
  149. model: UM.ViewModel { }
  150. textRole: "name"
  151. // update the model's active index
  152. function updateItemActiveFlags () {
  153. currentIndex = getActiveIndex()
  154. for (var i = 0; i < model.rowCount(); i++) {
  155. model.getItem(i).active = (i == currentIndex)
  156. }
  157. }
  158. // get the index of the active model item on start
  159. function getActiveIndex () {
  160. for (var i = 0; i < model.rowCount(); i++) {
  161. if (model.getItem(i).active) {
  162. return i
  163. }
  164. }
  165. return 0
  166. }
  167. // set the active index
  168. function setActiveIndex (index) {
  169. UM.Controller.setActiveView(index)
  170. // the connection to UM.ActiveView will trigger update so there is no reason to call it manually here
  171. }
  172. onCurrentIndexChanged:
  173. {
  174. if (model.getItem(currentIndex).id != undefined)
  175. viewModeButton.setActiveIndex(model.getItem(currentIndex).id)
  176. }
  177. currentIndex: getActiveIndex()
  178. // watch the active view proxy for changes made from the menu item
  179. Connections
  180. {
  181. target: UM.ActiveView
  182. onActiveViewChanged: viewModeButton.updateItemActiveFlags()
  183. }
  184. }
  185. Loader
  186. {
  187. id: view_panel
  188. anchors.top: viewModeButton.bottom
  189. anchors.topMargin: UM.Theme.getSize("default_margin").height
  190. anchors.right: viewModeButton.right
  191. property var buttonTarget: Qt.point(viewModeButton.x + Math.round(viewModeButton.width / 2), viewModeButton.y + Math.round(viewModeButton.height / 2))
  192. height: childrenRect.height
  193. width: childrenRect.width
  194. source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : "";
  195. }
  196. // Expand or collapse sidebar
  197. Connections
  198. {
  199. target: Cura.Actions.expandSidebar
  200. onTriggered: updateMarginsAndSizes()
  201. }
  202. Component.onCompleted:
  203. {
  204. updateMarginsAndSizes();
  205. }
  206. }