added range of TextFields

This commit is contained in:
Max 2018-11-26 19:33:59 +01:00
parent 6a25683375
commit 6288bac43a
5 changed files with 106 additions and 48 deletions

View file

@ -8,12 +8,13 @@ Item {
property int sum: 0 property int sum: 0
property int nextNum: 0 property int nextNum: 0
property int lastNum: 0 property int lastNum: 0
property int actualNums: 0 property int actualNumCount: 0
property int min: 0 property int min: 1
property int max: 9 property int max: 9
property int tickInterval: 1000 property int tickInterval: 1000
property int numCount: 10 property int numCount: 10
property bool negate: false property bool endPageVisibility: false
property string endPageLabelText: "You Lose!"
signal pageOpened() signal pageOpened()
@ -21,10 +22,6 @@ Item {
calculator.state = "starting" calculator.state = "starting"
} }
onNumCountChanged: {
initNums()
}
states: [ states: [
State { State {
name: "starting" name: "starting"
@ -79,6 +76,7 @@ Item {
Component { Component {
id: calculatorEndPageComp id: calculatorEndPageComp
CalculatorEndPage { CalculatorEndPage {
id: calculatorEndPage
} }
} }
@ -117,7 +115,8 @@ Item {
randNum = Math.floor((Math.random()*(range+1))+min) randNum = Math.floor((Math.random()*(range+1))+min)
} }
nextNum = randNum nextNum = randNum
actualNums += 1 calculator.sum += randNum
actualNumCount += 1
} }
function start(min, max) { function start(min, max) {
@ -125,10 +124,20 @@ Item {
calculator.state = "running" calculator.state = "running"
} }
function initNums() { function reset() {
while (nums.length < numCount) { calculator.state = "starting"
nums.push(0) calculator.sum = 0
console.log(nums.length) calculator.actualNumCount = 0
} calculator.endPageLabelText = "You Lose!"
calculator.endPageVisibility = false
calculator.lastNum = 0
calculator.nextNum = 0
}
function checkSum(sumInputText) {
if (calculator.sum === parseInt(sumInputText)) {
calculator.endPageLabelText = "You Won!"
}
calculator.endPageVisibility = true
} }
} }

View file

@ -7,43 +7,80 @@ Page {
signal pageOpened() signal pageOpened()
onPageOpened: { TextField {
rectAnim.start() id: sumInput
startRectAnim2.start() placeholderText: "sum"
visible: !won.visible
validator: IntValidator {bottom: -1000000; top: 1000000;}
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: parent.height * 0.1
} }
Keys.onReturnPressed: calculator.checkSum(sumInput.text)
Rectangle { }
id: rect Label {
anchors.fill: parent id: won
property string col: "darkgreen" text: calculator.endPageLabelText
color: col font.pixelSize: parent.width * 0.2
visible: calculator.endPageVisibility
Timer { anchors {
id: startRectAnim2 horizontalCenter: parent.horizontalCenter
interval: 5000 top: parent.top
running: false topMargin: parent.height * 0.2
repeat: false
onTriggered: {
rectAnim2.start()
} }
} }
ColorAnimation { /*
id: rectAnim Row {
target: rect anchors {
property: "color" horizontalCenter: parent.horizontalCenter
from: "darkGreen" bottom: parent.bottom
to: "yellow" bottomMargin: parent.height * 0.2
duration: 5000
} }
ColorAnimation { height: childrenRect.height
id: rectAnim2 width: childrenRect.width
target: rect spacing: root.height * 0.1
property: "color"
from: "yellow" RoundButton {
to: "darkRed" id: homeButton
duration: 5000 height: parent.width * 0.2
width: height
text: "home"
onClicked: {
game.state = "starting"
calculator.reset()
}
}
RoundButton {
id: startButtons
height: parent.width * 0.2
width: height
text: "start"
onClicked: {
calculator.reset()
calculator.state = "starting"
}
}
}
*/
RoundButton {
id: homeButton
height: parent.width * 0.2
width: height
text: "home"
visible: endPageVisibility
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: parent.height * 0.1
}
onClicked: {
calculator.reset()
calculator.state = "starting"
} }
} }
} }

View file

@ -65,7 +65,7 @@ Page {
running: calculator.state === "running" running: calculator.state === "running"
onTriggered: { onTriggered: {
if(calculator.actualNums < calculator.numCount){ if (calculator.actualNumCount < calculator.numCount) {
nextNumber() nextNumber()
tick.start() tick.start()
} }

View file

@ -32,40 +32,48 @@ Page {
id: tickInterval id: tickInterval
text: calculator.tickInterval text: calculator.tickInterval
placeholderText: "interval" placeholderText: "interval"
validator: IntValidator {bottom: 1; top: 100000;}
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05 Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05 Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
} }
TextField { TextField {
id: numCount id: numCount
text: calculator.numCount text: calculator.numCount
placeholderText: "numbercount" placeholderText: "numbercount"
validator: IntValidator {bottom: 1; top: 100000;}
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05 Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05 Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
} }
TextField { TextField {
id: min id: min
text: calculator.min text: calculator.min
placeholderText: "min" placeholderText: "min"
validator: IntValidator {bottom: -100000; top: 100000;}
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05 Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05 Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
} }
TextField { TextField {
id: max id: max
text: calculator.max text: calculator.max
placeholderText: "max" placeholderText: "max"
validator: IntValidator {bottom: -100000; top: 100000;}
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05 Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05 Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
} }
RoundButton { RoundButton {
@ -78,11 +86,15 @@ Page {
Layout.leftMargin: parent.width * 0.05 Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05 Layout.rightMargin: parent.width * 0.05
onClicked: { onClicked: {
updateVars() root.start()
}
}
}
function start() {
root.updateVars()
calculator.start() calculator.start()
} }
}
}
function updateVars() { function updateVars() {
calculator.tickInterval = tickInterval.text calculator.tickInterval = tickInterval.text
calculator.numCount = numCount.text calculator.numCount = numCount.text

View file

@ -13,11 +13,11 @@ Window {
id: game id: game
anchors.fill: parent anchors.fill: parent
state: "idle" state: "starting"
states: [ states: [
State { State {
name: "idle" name: "starting"
PropertyChanges { PropertyChanges {
target: mainStack target: mainStack
currPage: startPageComp currPage: startPageComp