MainWindowHeader.qml 7.0 KB

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