SettingCategory.qml 7.9 KB

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