KPageStack.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import QtQuick 1.0
  2. import "KPageStack.js" as SVM
  3. Rectangle {
  4. id: root
  5. anchors.fill: parent
  6. default property alias content: viewsContainer.children
  7. clip: true
  8. PropertyAnimation {
  9. id: currentViewAnimation
  10. duration : 500
  11. property: "x"
  12. easing.type: Easing.InQuad
  13. onRunningChanged: if(!running) target.visible = false
  14. }
  15. PropertyAnimation {
  16. id: nextViewAnimation
  17. duration : 500
  18. property: "x"
  19. easing.type: Easing.InQuad
  20. }
  21. Rectangle {
  22. id: viewsContainer
  23. anchors.fill: parent
  24. color: "red"
  25. onWidthChanged: {
  26. var views = viewsContainer.children;
  27. if(views.length > 0) {
  28. SVM.currentView = views[0];
  29. var view;
  30. for(var i = 0; i < views.length; i++) {
  31. view = views[i]
  32. if (view.visible==true){
  33. view.anchors.fill = viewsContainer;
  34. //view.width= viewsContainer.width
  35. //view.height = viewsContainer.height
  36. }
  37. }
  38. }
  39. }
  40. }
  41. Component.onCompleted: {
  42. var views = viewsContainer.children;
  43. if(views.length > 0) {
  44. SVM.currentView = views[0];
  45. var view;
  46. for(var i = 0; i < views.length; i++) {
  47. view = views[i]
  48. view.visible = (i == 0);
  49. //view.anchors.fill = parent;
  50. SVM.connectViewEvents(view);
  51. /*if(i > 0)
  52. {
  53. view.x = root.width;
  54. }*/
  55. }
  56. }
  57. }
  58. function push(page,properties){
  59. var pageComp;
  60. if (page.createObject) {
  61. // page defined as component
  62. pageComp = page;
  63. } else if (typeof page == "string") {
  64. // page defined as string (a url)
  65. pageComp = Qt.createComponent(page);
  66. }
  67. if (pageComp) {
  68. if (pageComp.status == Component.Error) {
  69. throw new Error("Error while loading page: " + pageComp.errorString());
  70. } else {
  71. // instantiate page from component
  72. page = pageComp.createObject(viewsContainer);
  73. }
  74. }
  75. //Copy properties to the page
  76. console.log("Propierties "+ properties)
  77. for (var prop in properties) {
  78. page[prop] = properties[prop];
  79. console.log("Propiedad "+ prop + " " +properties[prop])
  80. }
  81. //page.visible=false
  82. page.width= root.width
  83. page.height= root.height
  84. page.parent=viewsContainer
  85. SVM.connectViewEvents(page);
  86. //SVM.showView(page);
  87. page.visible=true
  88. }
  89. function pop(){
  90. var page=SVM.viewHistory.pop()
  91. page.visible=true
  92. page=SVM.viewHistory.pop()
  93. }
  94. }