SettingCategory.qml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. // Copyright (c) 2018 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.0
  5. import UM 1.1 as UM
  6. import Cura 1.0 as Cura
  7. Button
  8. {
  9. id: base
  10. anchors.left: parent.left
  11. anchors.right: parent.right
  12. // To avoid overlaping with the scrollBars
  13. anchors.rightMargin: 2 * UM.Theme.getSize("thin_margin").width
  14. hoverEnabled: true
  15. background: Rectangle
  16. {
  17. id: backgroundRectangle
  18. implicitHeight: UM.Theme.getSize("section").height
  19. color:
  20. {
  21. if (base.color)
  22. {
  23. return base.color
  24. }
  25. else if (!base.enabled)
  26. {
  27. return UM.Theme.getColor("setting_category_disabled")
  28. }
  29. else if (base.hovered && base.checkable && base.checked)
  30. {
  31. return UM.Theme.getColor("setting_category_active_hover")
  32. }
  33. else if (base.pressed || (base.checkable && base.checked))
  34. {
  35. return UM.Theme.getColor("setting_category_active")
  36. }
  37. else if (base.hovered)
  38. {
  39. return UM.Theme.getColor("setting_category_hover")
  40. }
  41. return UM.Theme.getColor("setting_category")
  42. }
  43. Behavior on color { ColorAnimation { duration: 50; } }
  44. Rectangle
  45. {
  46. id: backgroundLiningRectangle
  47. height: UM.Theme.getSize("default_lining").height
  48. width: parent.width
  49. anchors.bottom: parent.bottom
  50. color:
  51. {
  52. if (!base.enabled)
  53. {
  54. return UM.Theme.getColor("setting_category_disabled_border")
  55. } else if ((base.hovered || base.activeFocus) && base.checkable && base.checked)
  56. {
  57. return UM.Theme.getColor("setting_category_active_hover_border")
  58. } else if (base.pressed || (base.checkable && base.checked))
  59. {
  60. return UM.Theme.getColor("setting_category_active_border")
  61. } else if (base.hovered || base.activeFocus)
  62. {
  63. return UM.Theme.getColor("setting_category_hover_border")
  64. } else
  65. {
  66. return UM.Theme.getColor("setting_category_border")
  67. }
  68. }
  69. }
  70. }
  71. signal showTooltip(string text)
  72. signal hideTooltip()
  73. signal contextMenuRequested()
  74. signal showAllHiddenInheritedSettings(string category_id)
  75. signal focusReceived()
  76. signal setActiveFocusToNextSetting(bool forward)
  77. property var focusItem: base
  78. contentItem: Item
  79. {
  80. anchors.fill: parent
  81. Label
  82. {
  83. id: settingNameLabel
  84. anchors
  85. {
  86. left: parent.left
  87. leftMargin: 2 * UM.Theme.getSize("default_margin").width + UM.Theme.getSize("section_icon").width
  88. right: parent.right
  89. verticalCenter: parent.verticalCenter
  90. }
  91. text: definition.label
  92. textFormat: Text.PlainText
  93. renderType: Text.NativeRendering
  94. font: UM.Theme.getFont("setting_category")
  95. color:
  96. {
  97. if (!base.enabled)
  98. {
  99. return UM.Theme.getColor("setting_category_disabled_text")
  100. } else if ((base.hovered || base.activeFocus) && base.checkable && base.checked)
  101. {
  102. return UM.Theme.getColor("setting_category_active_hover_text")
  103. } else if (base.pressed || (base.checkable && base.checked))
  104. {
  105. return UM.Theme.getColor("setting_category_active_text")
  106. } else if (base.hovered || base.activeFocus)
  107. {
  108. return UM.Theme.getColor("setting_category_hover_text")
  109. } else
  110. {
  111. return UM.Theme.getColor("setting_category_text")
  112. }
  113. }
  114. fontSizeMode: Text.HorizontalFit
  115. minimumPointSize: 8
  116. }
  117. UM.RecolorImage
  118. {
  119. id: category_arrow
  120. anchors.verticalCenter: parent.verticalCenter
  121. anchors.right: parent.right
  122. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  123. width: UM.Theme.getSize("standard_arrow").width
  124. height: UM.Theme.getSize("standard_arrow").height
  125. sourceSize.width: width
  126. sourceSize.height: width
  127. color:
  128. {
  129. if (!base.enabled)
  130. {
  131. return UM.Theme.getColor("setting_category_disabled_text")
  132. }
  133. else if ((base.hovered || base.activeFocus) && base.checkable && base.checked)
  134. {
  135. return UM.Theme.getColor("setting_category_active_hover_text")
  136. }
  137. else if (base.pressed || (base.checkable && base.checked))
  138. {
  139. return UM.Theme.getColor("setting_category_active_text")
  140. }
  141. else if (base.hovered || base.activeFocus)
  142. {
  143. return UM.Theme.getColor("setting_category_hover_text")
  144. }
  145. return UM.Theme.getColor("setting_category_text")
  146. }
  147. source: base.checked ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  148. }
  149. }
  150. UM.RecolorImage
  151. {
  152. id: icon
  153. anchors.verticalCenter: parent.verticalCenter
  154. anchors.left: parent.left
  155. anchors.leftMargin: UM.Theme.getSize("thin_margin").width
  156. color:
  157. {
  158. if (!base.enabled)
  159. {
  160. return UM.Theme.getColor("setting_category_disabled_text")
  161. }
  162. else if((base.hovered || base.activeFocus) && base.checkable && base.checked)
  163. {
  164. return UM.Theme.getColor("setting_category_active_hover_text")
  165. }
  166. else if(base.pressed || (base.checkable && base.checked))
  167. {
  168. return UM.Theme.getColor("setting_category_active_text")
  169. }
  170. else if(base.hovered || base.activeFocus)
  171. {
  172. return UM.Theme.getColor("setting_category_hover_text")
  173. }
  174. return UM.Theme.getColor("setting_category_text")
  175. }
  176. source: UM.Theme.getIcon(definition.icon)
  177. width: UM.Theme.getSize("section_icon").width
  178. height: UM.Theme.getSize("section_icon").height
  179. sourceSize.width: width + 15 * screenScaleFactor
  180. sourceSize.height: width + 15 * screenScaleFactor
  181. }
  182. checkable: true
  183. checked: definition.expanded
  184. onClicked:
  185. {
  186. if (definition.expanded)
  187. {
  188. settingDefinitionsModel.collapse(definition.key)
  189. }
  190. else
  191. {
  192. settingDefinitionsModel.expandRecursive(definition.key)
  193. }
  194. //Set focus so that tab navigation continues from this point on.
  195. //NB: This must be set AFTER collapsing/expanding the category so that the scroll position is correct.
  196. forceActiveFocus()
  197. }
  198. onActiveFocusChanged:
  199. {
  200. if (activeFocus)
  201. {
  202. base.focusReceived()
  203. }
  204. }
  205. Keys.onTabPressed: base.setActiveFocusToNextSetting(true)
  206. Keys.onBacktabPressed: base.setActiveFocusToNextSetting(false)
  207. UM.SimpleButton
  208. {
  209. id: settingsButton
  210. visible: base.hovered || settingsButton.hovered
  211. height: Math.round(base.height * 0.6)
  212. width: Math.round(base.height * 0.6)
  213. anchors
  214. {
  215. right: inheritButton.visible ? inheritButton.left : parent.right
  216. // Use 1.9 as the factor because there is a 0.1 difference between the settings and inheritance warning icons
  217. rightMargin: inheritButton.visible ? Math.round(UM.Theme.getSize("default_margin").width / 2) : category_arrow.width + Math.round(UM.Theme.getSize("default_margin").width * 1.9)
  218. verticalCenter: parent.verticalCenter
  219. }
  220. color: UM.Theme.getColor("setting_control_button")
  221. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  222. iconSource: UM.Theme.getIcon("settings")
  223. onClicked: Cura.Actions.configureSettingVisibility.trigger(definition)
  224. }
  225. UM.SimpleButton
  226. {
  227. id: inheritButton
  228. anchors.verticalCenter: parent.verticalCenter
  229. anchors.right: parent.right
  230. anchors.rightMargin: category_arrow.width + UM.Theme.getSize("default_margin").width * 2
  231. visible:
  232. {
  233. if (Cura.SettingInheritanceManager.settingsWithInheritanceWarning.indexOf(definition.key) >= 0)
  234. {
  235. var children_with_override = Cura.SettingInheritanceManager.getChildrenKeysWithOverride(definition.key)
  236. for (var i = 0; i < children_with_override.length; i++)
  237. {
  238. if (!settingDefinitionsModel.getVisible(children_with_override[i]))
  239. {
  240. return true
  241. }
  242. }
  243. return false
  244. }
  245. return false
  246. }
  247. height: Math.round(parent.height / 2)
  248. width: height
  249. onClicked:
  250. {
  251. settingDefinitionsModel.expandRecursive(definition.key)
  252. base.checked = true
  253. base.showAllHiddenInheritedSettings(definition.key)
  254. }
  255. color: UM.Theme.getColor("setting_control_button")
  256. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  257. iconSource: UM.Theme.getIcon("notice")
  258. onEntered: base.showTooltip(catalog.i18nc("@label","Some hidden settings use values different from their normal calculated value.\n\nClick to make these settings visible."))
  259. onExited: base.hideTooltip()
  260. UM.I18nCatalog { id: catalog; name: "cura" }
  261. }
  262. }