PageSwitcher.qml 697 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import QtQuick 2.0
  2. Loader {
  3. id: root
  4. property var pageHistory: []
  5. function gotoPage(src) {
  6. if (source) pageHistory.push(source)
  7. source = src
  8. }
  9. function back() {
  10. if (pageHistory.length > 0) {
  11. source = pageHistory.pop()
  12. }
  13. }
  14. function gotoPageOrBack(src) {
  15. if (source == src && pageHistory.length > 0) {
  16. back()
  17. }
  18. else {
  19. gotoPage(src)
  20. }
  21. }
  22. onLoaded: {
  23. item.switcher = gotoPage
  24. }
  25. function gotoMainPage() {
  26. gotoPage("qrc:/qml/pages/MainPage.qml")
  27. }
  28. function gotoSettingsPage() {
  29. gotoPageOrBack("qrc:/qml/pages/SettingsPage.qml")
  30. }
  31. property DPage page
  32. Component.onCompleted: {
  33. gotoMainPage()
  34. }
  35. }