SettingCategory.qml 9.5 KB

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