SettingCategory.qml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. height: UM.Theme.getSize("section_icon_column").height
  16. background: Rectangle
  17. {
  18. id: backgroundRectangle
  19. height: UM.Theme.getSize("section").height
  20. anchors.verticalCenter: parent.verticalCenter
  21. color:
  22. {
  23. if (!base.enabled)
  24. {
  25. return UM.Theme.getColor("setting_category_disabled")
  26. }
  27. else if (base.hovered)
  28. {
  29. return UM.Theme.getColor("setting_category_hover")
  30. }
  31. return UM.Theme.getColor("setting_category")
  32. }
  33. Behavior on color { ColorAnimation { duration: 50; } }
  34. }
  35. signal showTooltip(string text)
  36. signal hideTooltip()
  37. signal contextMenuRequested()
  38. signal showAllHiddenInheritedSettings(string category_id)
  39. signal focusReceived()
  40. signal setActiveFocusToNextSetting(bool forward)
  41. property var focusItem: base
  42. property bool expanded: definition.expanded
  43. property color text_color:
  44. {
  45. if (!base.enabled)
  46. {
  47. return UM.Theme.getColor("setting_category_disabled_text")
  48. } else if (base.hovered || base.pressed || base.activeFocus)
  49. {
  50. return UM.Theme.getColor("setting_category_active_text")
  51. }
  52. return UM.Theme.getColor("setting_category_text")
  53. }
  54. contentItem: Item
  55. {
  56. anchors.fill: parent
  57. Label
  58. {
  59. id: settingNameLabel
  60. anchors
  61. {
  62. left: parent.left
  63. leftMargin: 2 * UM.Theme.getSize("default_margin").width + UM.Theme.getSize("section_icon").width
  64. right: parent.right
  65. verticalCenter: parent.verticalCenter
  66. }
  67. text: definition.label
  68. textFormat: Text.PlainText
  69. renderType: Text.NativeRendering
  70. font: UM.Theme.getFont("medium_bold")
  71. color: base.text_color
  72. fontSizeMode: Text.HorizontalFit
  73. minimumPointSize: 8
  74. }
  75. UM.RecolorImage
  76. {
  77. id: category_arrow
  78. anchors.verticalCenter: parent.verticalCenter
  79. anchors.right: parent.right
  80. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  81. width: UM.Theme.getSize("standard_arrow").width
  82. height: UM.Theme.getSize("standard_arrow").height
  83. sourceSize.height: width
  84. color: UM.Theme.getColor("setting_control_button")
  85. source: definition.expanded ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleLeft")
  86. }
  87. }
  88. UM.RecolorImage
  89. {
  90. id: icon
  91. anchors.verticalCenter: parent.verticalCenter
  92. anchors.left: parent.left
  93. anchors.leftMargin: UM.Theme.getSize("thin_margin").width
  94. color: base.text_color
  95. source: UM.Theme.getIcon(definition.icon)
  96. width: UM.Theme.getSize("section_icon").width
  97. height: UM.Theme.getSize("section_icon").height
  98. sourceSize.width: width
  99. sourceSize.height: width
  100. }
  101. onClicked:
  102. {
  103. if (definition.expanded)
  104. {
  105. settingDefinitionsModel.collapseRecursive(definition.key)
  106. }
  107. else
  108. {
  109. settingDefinitionsModel.expandRecursive(definition.key)
  110. }
  111. //Set focus so that tab navigation continues from this point on.
  112. //NB: This must be set AFTER collapsing/expanding the category so that the scroll position is correct.
  113. forceActiveFocus()
  114. }
  115. onActiveFocusChanged:
  116. {
  117. if (activeFocus)
  118. {
  119. base.focusReceived()
  120. }
  121. }
  122. Keys.onTabPressed: base.setActiveFocusToNextSetting(true)
  123. Keys.onBacktabPressed: base.setActiveFocusToNextSetting(false)
  124. UM.SimpleButton
  125. {
  126. id: settingsButton
  127. visible: base.hovered || settingsButton.hovered
  128. height: UM.Theme.getSize("small_button_icon").height
  129. width: height
  130. anchors
  131. {
  132. right: inheritButton.visible ? inheritButton.left : parent.right
  133. // Use 1.9 as the factor because there is a 0.1 difference between the settings and inheritance warning icons
  134. 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)
  135. verticalCenter: parent.verticalCenter
  136. }
  137. color: UM.Theme.getColor("setting_control_button")
  138. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  139. iconSource: UM.Theme.getIcon("Sliders")
  140. onClicked: Cura.Actions.configureSettingVisibility.trigger(definition)
  141. }
  142. UM.SimpleButton
  143. {
  144. id: inheritButton
  145. anchors.verticalCenter: parent.verticalCenter
  146. anchors.right: parent.right
  147. anchors.rightMargin: category_arrow.width + UM.Theme.getSize("default_margin").width * 2
  148. visible:
  149. {
  150. if (Cura.SettingInheritanceManager.settingsWithInheritanceWarning.indexOf(definition.key) >= 0)
  151. {
  152. var children_with_override = Cura.SettingInheritanceManager.getChildrenKeysWithOverride(definition.key)
  153. for (var i = 0; i < children_with_override.length; i++)
  154. {
  155. if (!settingDefinitionsModel.getVisible(children_with_override[i]))
  156. {
  157. return true
  158. }
  159. }
  160. return false
  161. }
  162. return false
  163. }
  164. height: UM.Theme.getSize("small_button_icon").height
  165. width: height
  166. onClicked:
  167. {
  168. settingDefinitionsModel.expandRecursive(definition.key)
  169. base.showAllHiddenInheritedSettings(definition.key)
  170. }
  171. color: UM.Theme.getColor("setting_control_button")
  172. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  173. iconSource: UM.Theme.getIcon("Information")
  174. onEntered: base.showTooltip(catalog.i18nc("@label","Some hidden settings use values different from their normal calculated value.\n\nClick to make these settings visible."))
  175. onExited: base.hideTooltip()
  176. }
  177. }