KContextMenu.qml 1.5 KB

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