Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.0
- import Sailfish.Silica 1.0
- Item {
- id: root
- property int currentIndex: 0
- readonly property Item currentItem: localPageStack.currentItem
- default property var _newChild
- function appendPage(page, properties, operationType) {
- if (localPageStack.depth > 0) {
- while (localPageStack.currentPage.canNavigateForward) {
- ++localPageStack.currentIndex;
- localPageStack.navigateForward(PageStackAction.Immediate);
- }
- localPageStack.pushAttached(page, properties, operationType);
- while (localPageStack.currentIndex > root.currentIndex) {
- localPageStack.navigateBack(PageStackAction.Immediate);
- --localPageStack.currentIndex;
- }
- } else {
- localPageStack.push(page, properties, operationType);
- localPageStack.currentItem = localPageStack.currentPage;
- }
- }
- function navigateBack() {
- return localPageStack.navigateBack(PageStackAction.Animated, PageNavigation.Right);
- }
- function navigateForward() {
- return localPageStack.navigateForward();
- }
- implicitWidth: parent.width
- implicitHeight: parent.height
- Binding {
- id: currentIndexBinding
- target: root
- property: "currentIndex"
- value: localPageStack.currentIndex
- when: false
- }
- PageStack {
- id: localPageStack
- property int currentIndex: 0
- property Item currentItem: null
- anchors.fill: parent
- onCurrentPageChanged: {
- if (localPageStack.currentIndex === root.currentIndex) {
- currentIndexBinding.when = true;
- if (localPageStack.previousPage(currentPage) === localPageStack.currentItem) {
- ++localPageStack.currentIndex;
- localPageStack.currentItem = localPageStack.currentPage;
- } else if (localPageStack.nextPage(currentPage) === localPageStack.currentItem) {
- --localPageStack.currentIndex;
- localPageStack.currentItem = localPageStack.currentPage;
- }
- currentIndexBinding.when = false;
- }
- }
- }
- onCurrentIndexChanged: {
- if (root.currentIndex > localPageStack.currentIndex) {
- localPageStack.completeAnimation();
- while (root.currentIndex > localPageStack.currentIndex + 1) {
- localPageStack.navigateForward(PageStackAction.Immediate);
- ++localPageStack.currentIndex;
- }
- localPageStack.navigateForward();
- } else if (currentIndex < localPageStack.currentIndex) {
- localPageStack.completeAnimation();
- while (root.currentIndex < localPageStack.currentIndex - 1) {
- localPageStack.navigateBack(PageStackAction.Immediate);
- --localPageStack.currentIndex;
- }
- localPageStack.navigateBack();
- }
- localPageStack.currentIndex = root.currentIndex;
- localPageStack.currentItem = localPageStack.currentPage;
- }
- on_NewChildChanged: {
- if (!_newChild) return;
- if (/^QQmlComponent/.test(_newChild.toString()) || _newChild.__silica_page !== undefined) {
- appendPage(_newChild, { }, PageStackAction.Immediate);
- } else {
- _newChild.parent = root;
- }
- _newChild = undefined;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement