SettingCategory.qml 6.4 KB

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