SettingCategory.qml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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("medium_bold")
  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.height: width
  100. color: UM.Theme.getColor("setting_control_button")
  101. source: base.checked ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  102. }
  103. }
  104. UM.RecolorImage
  105. {
  106. id: icon
  107. anchors.verticalCenter: parent.verticalCenter
  108. anchors.left: parent.left
  109. anchors.leftMargin: UM.Theme.getSize("thin_margin").width
  110. color:
  111. {
  112. if (!base.enabled)
  113. {
  114. return UM.Theme.getColor("setting_category_disabled_text")
  115. }
  116. else if((base.hovered || base.activeFocus) && base.checkable && base.checked)
  117. {
  118. return UM.Theme.getColor("setting_category_active_hover_text")
  119. }
  120. else if(base.pressed || (base.checkable && base.checked))
  121. {
  122. return UM.Theme.getColor("setting_category_active_text")
  123. }
  124. else if(base.hovered || base.activeFocus)
  125. {
  126. return UM.Theme.getColor("setting_category_hover_text")
  127. }
  128. return UM.Theme.getColor("setting_category_text")
  129. }
  130. source: UM.Theme.getIcon(definition.icon)
  131. width: UM.Theme.getSize("section_icon").width
  132. height: UM.Theme.getSize("section_icon").height
  133. sourceSize.width: width + 15 * screenScaleFactor
  134. sourceSize.height: width + 15 * screenScaleFactor
  135. }
  136. checkable: true
  137. checked: definition.expanded
  138. onClicked:
  139. {
  140. if (definition.expanded)
  141. {
  142. settingDefinitionsModel.collapse(definition.key)
  143. }
  144. else
  145. {
  146. settingDefinitionsModel.expandRecursive(definition.key)
  147. }
  148. //Set focus so that tab navigation continues from this point on.
  149. //NB: This must be set AFTER collapsing/expanding the category so that the scroll position is correct.
  150. forceActiveFocus()
  151. }
  152. onActiveFocusChanged:
  153. {
  154. if (activeFocus)
  155. {
  156. base.focusReceived()
  157. }
  158. }
  159. Keys.onTabPressed: base.setActiveFocusToNextSetting(true)
  160. Keys.onBacktabPressed: base.setActiveFocusToNextSetting(false)
  161. UM.SimpleButton
  162. {
  163. id: settingsButton
  164. visible: base.hovered || settingsButton.hovered
  165. height: Math.round(base.height * 0.6)
  166. width: Math.round(base.height * 0.6)
  167. anchors
  168. {
  169. right: inheritButton.visible ? inheritButton.left : parent.right
  170. // Use 1.9 as the factor because there is a 0.1 difference between the settings and inheritance warning icons
  171. 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)
  172. verticalCenter: parent.verticalCenter
  173. }
  174. color: UM.Theme.getColor("setting_control_button")
  175. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  176. iconSource: UM.Theme.getIcon("settings")
  177. onClicked: Cura.Actions.configureSettingVisibility.trigger(definition)
  178. }
  179. UM.SimpleButton
  180. {
  181. id: inheritButton
  182. anchors.verticalCenter: parent.verticalCenter
  183. anchors.right: parent.right
  184. anchors.rightMargin: category_arrow.width + UM.Theme.getSize("default_margin").width * 2
  185. visible:
  186. {
  187. if (Cura.SettingInheritanceManager.settingsWithInheritanceWarning.indexOf(definition.key) >= 0)
  188. {
  189. var children_with_override = Cura.SettingInheritanceManager.getChildrenKeysWithOverride(definition.key)
  190. for (var i = 0; i < children_with_override.length; i++)
  191. {
  192. if (!settingDefinitionsModel.getVisible(children_with_override[i]))
  193. {
  194. return true
  195. }
  196. }
  197. return false
  198. }
  199. return false
  200. }
  201. height: Math.round(parent.height / 2)
  202. width: height
  203. onClicked:
  204. {
  205. settingDefinitionsModel.expandRecursive(definition.key)
  206. base.checked = true
  207. base.showAllHiddenInheritedSettings(definition.key)
  208. }
  209. color: UM.Theme.getColor("setting_control_button")
  210. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  211. iconSource: UM.Theme.getIcon("notice")
  212. onEntered: base.showTooltip(catalog.i18nc("@label","Some hidden settings use values different from their normal calculated value.\n\nClick to make these settings visible."))
  213. onExited: base.hideTooltip()
  214. UM.I18nCatalog { id: catalog; name: "cura" }
  215. }
  216. }