import QtQuick 2.11 import QtQuick.Controls 2.4 Item { id: calculator property var nums: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] property int currIndex: -1 property int tickInterval: 1000 property int numCount: 10 signal pageOpened() onPageOpened: { calculator.state = "starting" } states: [ State { name: "starting" PropertyChanges { target: calculatorStack currPage: calculatorStartPageComp } }, State { name: "running" PropertyChanges { target: calculatorStack currPage: calculatorGamePageComp } } ] StackView { id: calculatorStack property var currPage; anchors.fill: parent onCurrPageChanged: { calculatorStack.replace(currPage) } onCurrentItemChanged: { calculatorStack.currentItem.pageOpened() } Component { id: calculatorStartPageComp CalculateStartPage { id: calculatorStartPage } } Component { id: calculatorGamePageComp CalculatePage { } } replaceExit: Transition { NumberAnimation { from: 1 to: 0 property: "opacity" duration: 200 easing.type: Easing.InOutQuad } } replaceEnter: Transition { NumberAnimation { from: 0 to: 1 property: "opacity" duration: 200 easing.type: Easing.InOutQuad } } } /*------------------------- ---------functions--------- -------------------------*/ function nextNumber(){ var randNum = 0 while(randNum === 0 || randNum === calculator.nums[currIndex]){ randNum = Math.floor(Math.random() * 9) } calculator.nums[calculator.currIndex+1] = randNum calculator.currIndex += 1 } function start(){ calculator.nextNumber() calculator.state = "running" } }