HiddenBlock.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import QtQuick 1.1
  2. Rectangle {
  3. id: hiddenBlock
  4. width: parent.width
  5. property alias title: txtTitle.text
  6. property alias titleHeght: itemTitle.height
  7. property variant contentBlock
  8. state: "close"
  9. color: "transparent"
  10. clip: true
  11. states: [
  12. State {
  13. name: "close"
  14. PropertyChanges { target: contentLoader; opacity: 0 }
  15. PropertyChanges { target: hiddenBlock; height: itemTitle.height + itemTitle.anchors.topMargin }
  16. PropertyChanges { target: imgState; rotation: 180 }
  17. },
  18. State {
  19. name: "open"
  20. PropertyChanges { target: contentLoader; opacity: 1 }
  21. PropertyChanges { target: hiddenBlock; height: itemTitle.height + itemTitle.anchors.topMargin +contentLoader.height + contentLoader.anchors.topMargin }
  22. PropertyChanges { target: imgState; rotation: -90 }
  23. }
  24. ]
  25. transitions: [
  26. Transition {
  27. from: "close"; to: "open"
  28. ParallelAnimation {
  29. RotationAnimation { target: imgState; duration: 400; direction: RotationAnimation.Clockwise }
  30. NumberAnimation { target: hiddenBlock; property: "height"; duration: 400; easing.type: Easing.InOutQuad }
  31. NumberAnimation { target: contentLoader; property: "opacity"; duration: 300; easing.type: Easing.InOutQuad }
  32. }
  33. },
  34. Transition {
  35. from: "open"; to: "close"
  36. ParallelAnimation {
  37. RotationAnimation { target: imgState; duration: 400; direction: RotationAnimation.Counterclockwise }
  38. NumberAnimation { target: hiddenBlock; property: "height"; duration: 400; easing.type: Easing.InOutQuad }
  39. NumberAnimation { target: contentLoader; property: "opacity"; duration: 300; easing.type: Easing.InOutQuad }
  40. }
  41. }
  42. ]
  43. Rectangle {
  44. id: itemTitle
  45. height: 70
  46. width: parent.width
  47. anchors.top: parent.top
  48. anchors.topMargin: 10
  49. anchors.left: parent.left
  50. radius: 8
  51. border.color: "gray"
  52. border.width: 1
  53. smooth: true
  54. gradient: gr_normal
  55. Gradient {
  56. id: gr_normal
  57. GradientStop { position: 0; color: "lightgray" }
  58. GradientStop { position: 1; color: "#a0a0a0" }
  59. //GradientStop { position: 0; color: "white" }
  60. //GradientStop { position: 0.5; color: "#ededed" }
  61. //GradientStop { position: 1; color: "#d7d7d7" }
  62. }
  63. Gradient {
  64. id: gr_press
  65. GradientStop { position: 0; color: "#a0a0a0" }
  66. GradientStop { position: 1; color: "lightgray" }
  67. //GradientStop { position: 0; color: "#d7d7d7" }
  68. //GradientStop { position: 1; color: "#d7d7d7" }
  69. }
  70. Image {
  71. id: imgState
  72. source: "qrc:/qml/images/small_arrow_black.png"
  73. rotation: hiddenBlock.state == "close" ? 180 : -90
  74. anchors.verticalCenter: parent.verticalCenter
  75. anchors.left: parent.left
  76. anchors.leftMargin: 15
  77. smooth: true
  78. }
  79. Text {
  80. id: txtTitle
  81. anchors.verticalCenter: parent.verticalCenter
  82. anchors.left: imgState.right
  83. anchors.leftMargin: 20
  84. text: "Title"
  85. font.pixelSize: 26
  86. }
  87. MouseArea {
  88. id: maTitle
  89. anchors.fill: parent
  90. onClicked: {
  91. if( hiddenBlock.state == "close" ) {
  92. hiddenBlock.state = "open"
  93. } else {
  94. hiddenBlock.state = "close"
  95. }
  96. }
  97. onPressedChanged: {
  98. if(pressed) {
  99. itemTitle.gradient = gr_press
  100. } else {
  101. itemTitle.gradient = gr_normal
  102. }
  103. }
  104. }
  105. }
  106. Loader {
  107. id: contentLoader
  108. anchors.top: itemTitle.bottom
  109. anchors.topMargin: 40
  110. anchors.left: parent.left
  111. sourceComponent: contentBlock
  112. }
  113. }