SettingCategory.qml 9.5 KB

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