SettingCategory.qml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright (c) 2022 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.5 as UM
  6. import Cura 1.5 as Cura
  7. Cura.CategoryButton
  8. {
  9. id: base
  10. anchors.left: parent.left
  11. anchors.right: parent.right
  12. categoryIcon: UM.Theme.getIcon(definition.icon)
  13. expanded: definition.expanded
  14. labelText: definition.label
  15. signal showTooltip(string text)
  16. signal hideTooltip()
  17. signal contextMenuRequested()
  18. signal showAllHiddenInheritedSettings(string category_id)
  19. signal focusReceived()
  20. signal setActiveFocusToNextSetting(bool forward)
  21. property var focusItem: base
  22. onClicked:
  23. {
  24. if (definition.expanded)
  25. {
  26. settingDefinitionsModel.collapseRecursive(definition.key)
  27. }
  28. else
  29. {
  30. settingDefinitionsModel.expandRecursive(definition.key)
  31. }
  32. //Set focus so that tab navigation continues from this point on.
  33. //NB: This must be set AFTER collapsing/expanding the category so that the scroll position is correct.
  34. forceActiveFocus()
  35. }
  36. onActiveFocusChanged:
  37. {
  38. if (activeFocus)
  39. {
  40. base.focusReceived()
  41. }
  42. }
  43. Keys.onTabPressed: base.setActiveFocusToNextSetting(true)
  44. Keys.onBacktabPressed: base.setActiveFocusToNextSetting(false)
  45. UM.SimpleButton
  46. {
  47. id: settingsButton
  48. visible: base.hovered || settingsButton.hovered
  49. height: UM.Theme.getSize("small_button_icon").height
  50. width: height
  51. anchors
  52. {
  53. right: inheritButton.visible ? inheritButton.left : parent.right
  54. // Use 1.9 as the factor because there is a 0.1 difference between the settings and inheritance warning icons
  55. rightMargin: inheritButton.visible ? Math.round(UM.Theme.getSize("default_margin").width / 2) : arrow.width + Math.round(UM.Theme.getSize("default_margin").width * 1.9)
  56. verticalCenter: parent.verticalCenter
  57. }
  58. color: UM.Theme.getColor("setting_control_button")
  59. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  60. iconSource: UM.Theme.getIcon("Sliders")
  61. onClicked: Cura.Actions.configureSettingVisibility.trigger(definition)
  62. }
  63. UM.SimpleButton
  64. {
  65. id: inheritButton
  66. anchors.verticalCenter: parent.verticalCenter
  67. anchors.right: parent.right
  68. anchors.rightMargin: arrow.width + UM.Theme.getSize("default_margin").width * 2
  69. visible:
  70. {
  71. if (Cura.SettingInheritanceManager.settingsWithInheritanceWarning.indexOf(definition.key) >= 0)
  72. {
  73. var children_with_override = Cura.SettingInheritanceManager.getChildrenKeysWithOverride(definition.key)
  74. for (var i = 0; i < children_with_override.length; i++)
  75. {
  76. if (!settingDefinitionsModel.getVisible(children_with_override[i]))
  77. {
  78. return true
  79. }
  80. }
  81. return false
  82. }
  83. return false
  84. }
  85. height: UM.Theme.getSize("small_button_icon").height
  86. width: height
  87. onClicked:
  88. {
  89. settingDefinitionsModel.expandRecursive(definition.key)
  90. base.showAllHiddenInheritedSettings(definition.key)
  91. }
  92. color: UM.Theme.getColor("setting_control_button")
  93. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  94. iconSource: UM.Theme.getIcon("Information")
  95. onEntered: base.showTooltip(catalog.i18nc("@label","Some hidden settings use values different from their normal calculated value.\n\nClick to make these settings visible."))
  96. onExited: base.hideTooltip()
  97. }
  98. }