KMenu.qml 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import QtQuick 1.1
  2. Rectangle {
  3. id: root
  4. width:parent.width
  5. height:parent.height
  6. visible: false
  7. y: screen.height
  8. color: "transparent"
  9. function close() {
  10. root.y=screen.height
  11. root.visible=false
  12. }
  13. function open(){
  14. visible=true
  15. }
  16. MouseArea{
  17. anchors.fill:parent
  18. onClicked: root.close()
  19. }
  20. PropertyAnimation {
  21. id: apperAnimation
  22. target: root
  23. property: "y"
  24. to:screen.height-root.height
  25. duration : 200
  26. }
  27. onVisibleChanged: {
  28. if (visible==true){
  29. apperAnimation.running = true
  30. }
  31. }
  32. Rectangle{
  33. id:containerBackground
  34. color: "lightgray"
  35. anchors.fill:container
  36. }
  37. Column {
  38. id:container
  39. width:parent.width
  40. height: 0
  41. anchors.bottom: parent.bottom
  42. }
  43. onChildrenChanged: {
  44. //Connect menu items clicked signal to menu close method and calculate the height dinamically
  45. var numChildren = root.children.length
  46. var totalHeight=container.height
  47. for (var i = 0; i < numChildren; ++i) {
  48. //console.log("objname "+root.children[i].objName + root.children[i].id )
  49. if (root.children[i].hasOwnProperty("text")){
  50. root.children[i].clicked.connect(close)
  51. totalHeight=totalHeight+root.children[i].height
  52. root.children[i].parent=container
  53. }
  54. }
  55. container.height=totalHeight
  56. }
  57. }