ExpandableCard.qml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) 2019 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. radius: 2 * screenScaleFactor // TODO: Theme!
  38. Behavior on color
  39. {
  40. ColorAnimation
  41. {
  42. duration: 100
  43. }
  44. }
  45. }
  46. MouseArea
  47. {
  48. id: headerMouseArea
  49. anchors.fill: header
  50. onClicked:
  51. {
  52. if (!base.enabled) return
  53. base.expanded = !base.expanded
  54. }
  55. hoverEnabled: base.enabled
  56. }
  57. Rectangle
  58. {
  59. id: drawer
  60. anchors
  61. {
  62. top: header.bottom
  63. topMargin: -1
  64. }
  65. border
  66. {
  67. color: borderColor
  68. width: borderWidth
  69. }
  70. clip: true
  71. color: headerBackgroundColor
  72. height: base.expanded ? childrenRect.height : 0
  73. width: parent.width
  74. radius: 2 * screenScaleFactor // TODO: Theme!
  75. Behavior on height
  76. {
  77. NumberAnimation
  78. {
  79. duration: 100
  80. }
  81. }
  82. }
  83. }