import QtQuick 2.11 import QtQuick.Controls 2.4 import "./" Item { id: calculator property int sum: 0 property int nextNum: 0 property int lastNum: 0 property int actualNums: 0 property int min: 0 property int max: 9 property int tickInterval: 1000 property int numCount: 10 property bool negate: false signal pageOpened() onPageOpened: { calculator.state = "starting" } onNumCountChanged: { initNums() } states: [ State { name: "starting" PropertyChanges { target: calculatorStack currPage: calculatorStartPageComp } }, State { name: "running" PropertyChanges { target: calculatorStack currPage: calculatorMainPageComp } }, State { name: "ending" PropertyChanges { target: calculatorStack currPage: calculatorEndPageComp } } ] StackView { id: calculatorStack property var currPage; anchors.fill: parent onCurrPageChanged: { calculatorStack.replace(currPage) } onCurrentItemChanged: { calculatorStack.currentItem.pageOpened() } Component { id: calculatorStartPageComp CalculatorStartPage { } } Component { id: calculatorMainPageComp CalculatorMainPage { } } Component { id: calculatorEndPageComp CalculatorEndPage { } } 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 var range = calculator.max - calculator.min lastNum = nextNum while(randNum===0 || randNum === lastNum){ randNum = Math.floor((Math.random()*(range+1))+min) } nextNum = randNum actualNums += 1 } function start(min, max){ calculator.nextNumber() calculator.state = "running" } function initNums() { while (nums.length < numCount) { nums.push(0) console.log(nums.length) } } }