ExpandableCard.qml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // TODO: Theme & documentation!
  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. Item
  12. {
  13. id: base
  14. property bool expanded: false
  15. property var borderWidth: 1
  16. property color borderColor: "#EAEAEC"
  17. property color headerBackgroundColor: "white"
  18. property color headerHoverColor: "#f5f5f5"
  19. property color drawerBackgroundColor: "white"
  20. property alias headerItem: header.children
  21. property alias drawerItem: drawer.children
  22. width: parent.width
  23. height: childrenRect.height
  24. Rectangle
  25. {
  26. id: header
  27. border
  28. {
  29. color: borderColor
  30. width: borderWidth
  31. }
  32. color: headerMouseArea.containsMouse ? headerHoverColor : headerBackgroundColor
  33. height: childrenRect.height
  34. width: parent.width
  35. Behavior on color
  36. {
  37. ColorAnimation
  38. {
  39. duration: 100
  40. }
  41. }
  42. }
  43. MouseArea
  44. {
  45. id: headerMouseArea
  46. anchors.fill: header
  47. onClicked: base.expanded = !base.expanded
  48. hoverEnabled: true
  49. }
  50. Rectangle
  51. {
  52. id: drawer
  53. anchors
  54. {
  55. top: header.bottom
  56. topMargin: -1
  57. }
  58. border
  59. {
  60. color: borderColor
  61. width: borderWidth
  62. }
  63. clip: true
  64. color: headerBackgroundColor
  65. height: base.expanded ? childrenRect.height : 0
  66. width: parent.width
  67. Behavior on height
  68. {
  69. NumberAnimation
  70. {
  71. duration: 100
  72. }
  73. }
  74. }
  75. }