SettingCategory.qml 8.9 KB

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