SettingCategory.qml 9.9 KB

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