RecommendedSettingItem.qml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.5 as UM
  7. import Cura 1.7 as Cura
  8. Item
  9. {
  10. id: settingItem
  11. width: parent.width
  12. Layout.minimumHeight: UM.Theme.getSize("section_header").height
  13. Layout.fillWidth: true
  14. property alias settingControl: settingContainer.children
  15. property alias settingName: settingLabel.text
  16. property string tooltipText: ""
  17. property bool isCompressed: false
  18. UM.Label
  19. {
  20. id: settingLabel
  21. width: leftColumnWidth
  22. anchors.left: parent.left
  23. anchors.verticalCenter: parent.verticalCenter
  24. // These numbers come from the IconWithText in RecommendedSettingSection
  25. anchors.leftMargin: UM.Theme.getSize("medium_button_icon").width + UM.Theme.getSize("default_margin").width
  26. }
  27. MouseArea
  28. {
  29. id: tooltipArea
  30. anchors.fill: settingLabel
  31. propagateComposedEvents: true
  32. hoverEnabled: true
  33. onEntered: base.showTooltip(parent, Qt.point(-UM.Theme.getSize("thick_margin").width, 0), tooltipText)
  34. onExited: base.hideTooltip()
  35. }
  36. Item
  37. {
  38. id: settingContainer
  39. height: childrenRect.height
  40. anchors.left: settingLabel.right
  41. anchors.right: parent.right
  42. anchors.verticalCenter: parent.verticalCenter
  43. }
  44. states:
  45. [
  46. State
  47. {
  48. name: "sectionClosed" // Section is hidden when the switch in parent is off
  49. when: isCompressed
  50. PropertyChanges
  51. {
  52. target: settingItem;
  53. opacity: 0
  54. height: 0
  55. implicitHeight: 0
  56. Layout.preferredHeight: 0
  57. Layout.minimumHeight: 0
  58. enabled: false // Components can still be clickable with height 0 so they need to be disabled as well.
  59. }
  60. },
  61. State
  62. {
  63. // All values are default. This state is only here for the animation.
  64. name: "sectionOpened"
  65. when: !isCompressed
  66. }
  67. ]
  68. transitions: Transition
  69. {
  70. from: "sectionOpened"; to: "sectionClosed"
  71. reversible: true
  72. ParallelAnimation
  73. {
  74. // Animate section compressing as it closes
  75. NumberAnimation { property: "Layout.minimumHeight"; duration: 100; }
  76. // Animate section dissapearring as it closes
  77. NumberAnimation { property: "opacity"; duration: 100; }
  78. }
  79. }
  80. }