ExpandableCard.qml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.0
  5. import UM 1.3 as UM
  6. import Cura 1.0 as Cura
  7. /**
  8. * The expandable component has 3 major sub components:
  9. * - The headerItem Always visible and should hold some info about what happens if the component is expanded
  10. * - The popupItem The content that needs to be shown if the component is expanded.
  11. */
  12. Item
  13. {
  14. id: base
  15. property bool expanded: false
  16. property bool enabled: true
  17. property var borderWidth: 1
  18. property color borderColor: UM.Theme.getColor("monitor_card_border")
  19. property color headerBackgroundColor: UM.Theme.getColor("monitor_icon_accent")
  20. property color headerHoverColor: UM.Theme.getColor("monitor_card_hover")
  21. property color drawerBackgroundColor: UM.Theme.getColor("monitor_icon_accent")
  22. property alias headerItem: header.children
  23. property alias drawerItem: drawer.children
  24. width: parent.width
  25. height: childrenRect.height
  26. Rectangle
  27. {
  28. id: header
  29. border
  30. {
  31. color: borderColor
  32. width: borderWidth
  33. }
  34. color: base.enabled && headerMouseArea.containsMouse ? headerHoverColor : headerBackgroundColor
  35. height: childrenRect.height
  36. width: parent.width
  37. Behavior on color
  38. {
  39. ColorAnimation
  40. {
  41. duration: 100
  42. }
  43. }
  44. }
  45. MouseArea
  46. {
  47. id: headerMouseArea
  48. anchors.fill: header
  49. onClicked:
  50. {
  51. if (!base.enabled) return
  52. base.expanded = !base.expanded
  53. }
  54. hoverEnabled: base.enabled
  55. }
  56. Rectangle
  57. {
  58. id: drawer
  59. anchors
  60. {
  61. top: header.bottom
  62. topMargin: -1
  63. }
  64. border
  65. {
  66. color: borderColor
  67. width: borderWidth
  68. }
  69. clip: true
  70. color: headerBackgroundColor
  71. height: base.expanded ? childrenRect.height : 0
  72. width: parent.width
  73. Behavior on height
  74. {
  75. NumberAnimation
  76. {
  77. duration: 100
  78. }
  79. }
  80. }
  81. }