Advertisement
Guest User

Untitled

a guest
Jun 14th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 3.50 KB | None | 0 0
  1. import QtQuick 2.0
  2. import Sailfish.Silica 1.0
  3.  
  4. Item {
  5.     id: root
  6.  
  7.     property int currentIndex: 0
  8.     readonly property Item currentItem: localPageStack.currentItem
  9.     default property var _newChild
  10.  
  11.     function appendPage(page, properties, operationType) {
  12.         if (localPageStack.depth > 0) {
  13.             while (localPageStack.currentPage.canNavigateForward) {
  14.                 ++localPageStack.currentIndex;
  15.                 localPageStack.navigateForward(PageStackAction.Immediate);
  16.             }
  17.             localPageStack.pushAttached(page, properties, operationType);
  18.             while (localPageStack.currentIndex > root.currentIndex) {
  19.                 localPageStack.navigateBack(PageStackAction.Immediate);
  20.                 --localPageStack.currentIndex;
  21.             }
  22.         } else {
  23.             localPageStack.push(page, properties, operationType);
  24.             localPageStack.currentItem = localPageStack.currentPage;
  25.         }
  26.     }
  27.  
  28.     function navigateBack() {
  29.         return localPageStack.navigateBack(PageStackAction.Animated, PageNavigation.Right);
  30.     }
  31.  
  32.     function navigateForward() {
  33.         return localPageStack.navigateForward();
  34.     }
  35.  
  36.     implicitWidth: parent.width
  37.     implicitHeight: parent.height
  38.  
  39.     Binding {
  40.         id: currentIndexBinding
  41.  
  42.         target: root
  43.         property: "currentIndex"
  44.         value: localPageStack.currentIndex
  45.         when: false
  46.     }
  47.     PageStack {
  48.         id: localPageStack
  49.  
  50.         property int currentIndex: 0
  51.         property Item currentItem: null
  52.  
  53.         anchors.fill: parent
  54.  
  55.         onCurrentPageChanged: {
  56.             if (localPageStack.currentIndex === root.currentIndex) {
  57.                 currentIndexBinding.when = true;
  58.                 if (localPageStack.previousPage(currentPage) === localPageStack.currentItem) {
  59.                     ++localPageStack.currentIndex;
  60.                     localPageStack.currentItem = localPageStack.currentPage;
  61.                 } else if (localPageStack.nextPage(currentPage) === localPageStack.currentItem) {
  62.                     --localPageStack.currentIndex;
  63.                     localPageStack.currentItem = localPageStack.currentPage;
  64.                 }
  65.                 currentIndexBinding.when = false;
  66.             }
  67.         }
  68.     }
  69.  
  70.     onCurrentIndexChanged: {
  71.         if (root.currentIndex > localPageStack.currentIndex) {
  72.             localPageStack.completeAnimation();
  73.             while (root.currentIndex > localPageStack.currentIndex + 1) {
  74.                 localPageStack.navigateForward(PageStackAction.Immediate);
  75.                 ++localPageStack.currentIndex;
  76.             }
  77.             localPageStack.navigateForward();
  78.         } else if (currentIndex < localPageStack.currentIndex) {
  79.             localPageStack.completeAnimation();
  80.             while (root.currentIndex < localPageStack.currentIndex - 1) {
  81.                 localPageStack.navigateBack(PageStackAction.Immediate);
  82.                 --localPageStack.currentIndex;
  83.             }
  84.             localPageStack.navigateBack();
  85.         }
  86.         localPageStack.currentIndex = root.currentIndex;
  87.         localPageStack.currentItem = localPageStack.currentPage;
  88.     }
  89.     on_NewChildChanged: {
  90.         if (!_newChild) return;
  91.         if (/^QQmlComponent/.test(_newChild.toString()) || _newChild.__silica_page !== undefined) {
  92.             appendPage(_newChild, { }, PageStackAction.Immediate);
  93.         } else {
  94.             _newChild.parent = root;
  95.         }
  96.         _newChild = undefined;
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement