MainWindowHeader.qml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // Copyright (c) 2021 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.4
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. import "../Account"
  8. import "../ApplicationSwitcher"
  9. Item
  10. {
  11. id: base
  12. implicitHeight: UM.Theme.getSize("main_window_header").height
  13. implicitWidth: UM.Theme.getSize("main_window_header").width
  14. Image
  15. {
  16. id: logo
  17. anchors.left: parent.left
  18. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  19. anchors.verticalCenter: parent.verticalCenter
  20. source: UM.Theme.getImage("logo")
  21. width: UM.Theme.getSize("logo").width
  22. height: UM.Theme.getSize("logo").height
  23. fillMode: Image.PreserveAspectFit
  24. sourceSize.width: width
  25. sourceSize.height: height
  26. }
  27. UM.Label
  28. {
  29. id: extra_version_label
  30. anchors.left: logo.right
  31. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  32. anchors.verticalCenter: parent.verticalCenter
  33. color: "yellow"
  34. text: "BUILD: " + CuraApplication.extraVersionText
  35. }
  36. ButtonGroup
  37. {
  38. buttons: stagesListContainer.children
  39. }
  40. Row
  41. {
  42. id: stagesListContainer
  43. spacing: Math.round(UM.Theme.getSize("default_margin").width / 2)
  44. anchors
  45. {
  46. horizontalCenter: parent.horizontalCenter
  47. verticalCenter: parent.verticalCenter
  48. leftMargin: UM.Theme.getSize("default_margin").width
  49. }
  50. // The main window header is dynamically filled with all available stages
  51. Repeater
  52. {
  53. id: stagesHeader
  54. model: UM.StageModel { }
  55. delegate: Button
  56. {
  57. id: stageSelectorButton
  58. text: model.name.toUpperCase()
  59. checkable: true
  60. checked: UM.Controller.activeStage !== null && model.id == UM.Controller.activeStage.stageId
  61. anchors.verticalCenter: parent.verticalCenter
  62. //style: UM.Theme.styles.main_window_header_tab
  63. height: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
  64. // This id is required to find the stage buttons through Squish
  65. property string stageId: model.id
  66. hoverEnabled: true
  67. leftPadding: 2 * UM.Theme.getSize("default_margin").width
  68. rightPadding: 2 * UM.Theme.getSize("default_margin").width
  69. // Set top & bottom padding to whatever space is left from height and the size of the text.
  70. bottomPadding: Math.round((height - buttonLabel.contentHeight) / 2)
  71. topPadding: bottomPadding
  72. background: Rectangle
  73. {
  74. radius: UM.Theme.getSize("action_button_radius").width
  75. color:
  76. {
  77. if (stageSelectorButton.checked)
  78. {
  79. return UM.Theme.getColor("main_window_header_button_background_active")
  80. }
  81. else
  82. {
  83. if (stageSelectorButton.hovered)
  84. {
  85. return UM.Theme.getColor("main_window_header_button_background_hovered")
  86. }
  87. return UM.Theme.getColor("main_window_header_button_background_inactive")
  88. }
  89. }
  90. }
  91. contentItem: UM.Label
  92. {
  93. id: buttonLabel
  94. text: stageSelectorButton.text
  95. anchors.centerIn: stageSelectorButton
  96. font: UM.Theme.getFont("medium")
  97. color:
  98. {
  99. if (stageSelectorButton.checked)
  100. {
  101. return UM.Theme.getColor("main_window_header_button_text_active")
  102. }
  103. else
  104. {
  105. if (stageSelectorButton.hovered)
  106. {
  107. return UM.Theme.getColor("main_window_header_button_text_hovered")
  108. }
  109. return UM.Theme.getColor("main_window_header_button_text_inactive")
  110. }
  111. }
  112. }
  113. // This is a trick to assure the activeStage is correctly changed. It doesn't work properly if done in the onClicked (see CURA-6028)
  114. MouseArea
  115. {
  116. anchors.fill: parent
  117. onClicked: UM.Controller.setActiveStage(model.id)
  118. }
  119. }
  120. }
  121. }
  122. // Shortcut button to quick access the Toolbox
  123. Button
  124. {
  125. id: marketplaceButton
  126. text: catalog.i18nc("@action:button", "Marketplace")
  127. height: Math.round(0.5 * UM.Theme.getSize("main_window_header").height)
  128. onClicked: Cura.Actions.browsePackages.trigger()
  129. hoverEnabled: true
  130. background: Rectangle
  131. {
  132. id: marketplaceButtonBorder
  133. radius: UM.Theme.getSize("action_button_radius").width
  134. color: UM.Theme.getColor("main_window_header_background")
  135. border.width: UM.Theme.getSize("default_lining").width
  136. border.color: UM.Theme.getColor("primary_text")
  137. Rectangle
  138. {
  139. id: marketplaceButtonFill
  140. anchors.fill: parent
  141. radius: parent.radius
  142. color: UM.Theme.getColor("primary_text")
  143. opacity: marketplaceButton.hovered ? 0.2 : 0
  144. Behavior on opacity { NumberAnimation { duration: 100 } }
  145. }
  146. }
  147. contentItem: UM.Label
  148. {
  149. id: label
  150. text: marketplaceButton.text
  151. color: UM.Theme.getColor("primary_text")
  152. width: contentWidth
  153. }
  154. anchors
  155. {
  156. right: applicationSwitcher.left
  157. rightMargin: UM.Theme.getSize("default_margin").width
  158. verticalCenter: parent.verticalCenter
  159. }
  160. Cura.NotificationIcon
  161. {
  162. id: marketplaceNotificationIcon
  163. anchors
  164. {
  165. top: parent.top
  166. right: parent.right
  167. rightMargin: (-0.5 * width) | 0
  168. topMargin: (-0.5 * height) | 0
  169. }
  170. visible: CuraApplication.getPackageManager().packagesWithUpdate.length > 0
  171. labelText:
  172. {
  173. const itemCount = CuraApplication.getPackageManager().packagesWithUpdate.length
  174. return itemCount > 9 ? "9+" : itemCount
  175. }
  176. }
  177. }
  178. ApplicationSwitcher
  179. {
  180. id: applicationSwitcher
  181. anchors
  182. {
  183. verticalCenter: parent.verticalCenter
  184. right: accountWidget.left
  185. rightMargin: UM.Theme.getSize("default_margin").width
  186. }
  187. }
  188. AccountWidget
  189. {
  190. id: accountWidget
  191. anchors
  192. {
  193. verticalCenter: parent.verticalCenter
  194. right: parent.right
  195. rightMargin: UM.Theme.getSize("default_margin").width
  196. }
  197. }
  198. }