RecommendedSettingSection.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (c) 2022 UltiMaker
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import QtQuick.Layouts 2.10
  6. import UM 1.7 as UM
  7. import Cura 1.7 as Cura
  8. Item
  9. {
  10. id: settingSection
  11. property alias title: sectionTitle.text
  12. property alias icon: sectionTitle.source
  13. property alias enableSectionSwitchVisible: enableSectionSwitch.visible
  14. property alias enableSectionSwitchChecked: enableSectionSwitch.checked
  15. property alias enableSectionSwitchEnabled: enableSectionSwitch.enabled
  16. property string tooltipText: ""
  17. property var enableSectionClicked: { return }
  18. property int leftColumnWidth: Math.floor(width * 0.35)
  19. property bool isCompressed: false
  20. property alias contents: settingColumn.children
  21. function onEnableSectionChanged(state) {}
  22. height: childrenRect.height
  23. Item
  24. {
  25. id: sectionHeader
  26. anchors.top: parent.top
  27. anchors.right: parent.right
  28. anchors.left: parent.left
  29. height: UM.Theme.getSize("section_header").height
  30. Cura.IconWithText
  31. {
  32. id: sectionTitle
  33. width: leftColumnWidth
  34. anchors.left: parent.left
  35. anchors.verticalCenter: parent.verticalCenter
  36. source: UM.Theme.getIcon("PrintQuality")
  37. spacing: UM.Theme.getSize("default_margin").width
  38. iconSize: UM.Theme.getSize("medium_button_icon").width
  39. iconColor: UM.Theme.getColor("text")
  40. font: UM.Theme.getFont("medium_bold")
  41. }
  42. MouseArea
  43. {
  44. id: tooltipArea
  45. anchors.fill: sectionTitle
  46. propagateComposedEvents: true
  47. hoverEnabled: true
  48. onEntered: base.showTooltip(parent, Qt.point(-UM.Theme.getSize("thick_margin").width, 0), tooltipText)
  49. onExited: base.hideTooltip()
  50. }
  51. }
  52. UM.Switch
  53. {
  54. id: enableSectionSwitch
  55. anchors.left: parent.left
  56. // These numbers come from the IconWithText in RecommendedSettingSection.
  57. anchors.leftMargin: leftColumnWidth + UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width
  58. anchors.verticalCenter: sectionHeader.verticalCenter
  59. visible: false
  60. // This delay forces the setting change to happen after the setting section open/close animation. This is so the animation is smooth.
  61. Timer
  62. {
  63. id: updateTimer
  64. interval: 500 // This interval is set long enough so you can spam click the button on/off without lag.
  65. repeat: false
  66. onTriggered: onEnableSectionChanged(enableSectionSwitch.checked)
  67. }
  68. onClicked: updateTimer.restart()
  69. }
  70. ColumnLayout
  71. {
  72. id: settingColumn
  73. width: parent.width
  74. spacing: UM.Theme.getSize("thin_margin").height
  75. anchors.left: parent.left
  76. anchors.right: parent.right
  77. anchors.top: sectionHeader.bottom
  78. anchors.topMargin: UM.Theme.getSize("narrow_margin").height
  79. }
  80. states:
  81. [
  82. State
  83. {
  84. name: "settingListClosed"
  85. when: !enableSectionSwitchChecked && enableSectionSwitchEnabled
  86. PropertyChanges
  87. {
  88. target: settingSection
  89. isCompressed: true
  90. implicitHeight: 0
  91. }
  92. PropertyChanges
  93. {
  94. target: settingColumn
  95. spacing: 0
  96. }
  97. },
  98. State
  99. {
  100. // Use default properties. This is only here for the animation.
  101. name: "settingListOpened"
  102. when: enableSectionSwitchChecked && enableSectionSwitchEnabled
  103. }
  104. ]
  105. // Animate section closing
  106. transitions: Transition
  107. {
  108. from: "settingListOpened"; to: "settingListClosed"
  109. reversible: true
  110. // Animate section compressing as it closes
  111. NumberAnimation { property: "implicitHeight"; duration: 100; }
  112. }
  113. }