added structure

This commit is contained in:
Max Grützner 2018-12-19 20:30:50 +01:00
parent e1ae773ec0
commit 565ae69709
20 changed files with 279 additions and 1188 deletions

View file

@ -1,12 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.4
import "./"
Page {
id: cal
signal pageOpened()
Rectangle {
anchors.fill: parent
color: "red"
}
}

View file

@ -1,44 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.4
import "./"
Page {
id: root
signal pageOpened()
RoundButton {
id: calenderButton
text: "calender"
height: parent.width * 0.2
width: height
font.pixelSize: parent.width * 0.03
anchors {
left: parent.left
top: parent.top
leftMargin: parent.width * 0.5 - width * 0.5
topMargin: parent.height * 0.3 - height * 0.5
}
onClicked: {
game.calender()
}
}
RoundButton {
id: calculatorButton
text: "calculator"
height: parent.width * 0.2
width: height
font.pixelSize: parent.width * 0.03
anchors {
left: parent.left
top: parent.top
leftMargin: parent.width * 0.5 - width * 0.5
topMargin: parent.height * 0.6 - height * 0.5
}
onClicked: {
game.calculator()
}
}
}

View file

@ -0,0 +1,82 @@
<?xml version="1.0"?>
<manifest package="com.max.mathtrainingstuff" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="mathtrainingstuff" android:icon="@drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="mathtrainingstuff" android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Application arguments -->
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
<!-- Application arguments -->
<meta-data android:name="android.app.lib_name" android:value="mathtrainingstuff"/>
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="1"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="1"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs" android:value="plugins/platforms/android/libqtforandroid.so:plugins/bearer/libqandroidbearer.so:lib/libQt5QuickParticles.so"/>
<meta-data android:name="android.app.load_local_jars" android:value="jar/QtAndroid.jar:jar/QtAndroidBearer.jar"/>
<meta-data android:name="android.app.static_init_classes" android:value=""/>
<!-- Used to specify custom system library path to run with local system libs -->
<!-- <meta-data android:name="android.app.system_libs_prefix" android:value="/system/lib/"/> -->
<!-- Messages maps -->
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<!-- Messages maps -->
<!-- Splash screen -->
<!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->
<!-- meta-data android:name="android.app.splash_screen_sticky" android:value="true"/ -->
<!-- Splash screen -->
<!-- Background running -->
<!-- Warning: changing this value to true may cause unexpected crashes if the
application still try to draw after
"applicationStateChanged(Qt::ApplicationSuspended)"
signal is sent! -->
<meta-data android:name="android.app.background_running" android:value="false"/>
<!-- Background running -->
<!-- auto screen scale factor -->
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="false"/>
<!-- auto screen scale factor -->
<!-- extract android style -->
<!-- available android:values :
* full - useful QWidget & Quick Controls 1 apps
* minimal - useful for Quick Controls 2 apps, it is much faster than "full"
* none - useful for apps that don't use any of the above Qt modules
-->
<meta-data android:name="android.app.extract_android_style" android:value="full"/>
<!-- extract android style -->
</activity>
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
Remove the comment if you do not require these default features. -->
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
</manifest>

View file

@ -1,152 +0,0 @@
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 actualNumCount: 0
property int min: 1
property int max: 9
property int tickInterval: 1000
property int numCount: 10
property bool endPageVisibility: false
property string endPageLabelText: "You Lose!"
signal pageOpened()
onPageOpened: {
calculator.start()
}
states: [
State {
name: "starting"
PropertyChanges {
target: calculatorStack
currPage: calculatorStartPageComp
}
},
State {
name: "running"
PropertyChanges {
target: calculatorStack
currPage: calculatorRunningPageComp
}
},
State {
name: "gameOver"
PropertyChanges {
target: calculatorStack
currPage: calculatorGameOverPageComp
}
}
]
StackView {
id: calculatorStack
property var currPage;
anchors.fill: parent
onCurrPageChanged: {
calculatorStack.replace(currPage)
}
onCurrentItemChanged: {
calculatorStack.currentItem.pageOpened()
}
Component {
id: calculatorStartPageComp
CalculatorStartPage {
}
}
Component {
id: calculatorRunningPageComp
CalculatorRunningPage {
}
}
Component {
id: calculatorGameOverPageComp
CalculatorGameOverPage {
}
}
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 start() {
calculator.reset()
calculator.state = "starting"
}
function run() {
calculator.nextNumber()
calculator.state = "running"
}
function gameOver() {
calculator.state = "gameOver"
}
function reset() {
calculator.sum = 0
calculator.actualNumCount = 0
calculator.endPageLabelText = "You Lose!"
calculator.endPageVisibility = false
calculator.lastNum = 0
calculator.nextNum = 0
}
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
calculator.sum += randNum
actualNumCount += 1
}
function checkSum(sumInputText) {
if (sumInputText !== "") {
if (calculator.sum === parseInt(sumInputText)) {
calculator.endPageLabelText = "You Won!"
}
calculator.endPageVisibility = true
}
}
}

View file

@ -1,96 +0,0 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import "./"
Page {
id: root
signal pageOpened()
TextField {
id: sumInput
placeholderText: "sum"
visible: !endPageVisibility
validator: IntValidator {bottom: -1000000; top: 1000000;}
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: parent.height * 0.1
}
Keys.onReturnPressed: calculator.checkSum(sumInput.text)
}
RoundButton {
id: checkButton
height: parent.width * 0.2
width: height
text: "check"
font.pixelSize: parent.width * 0.03
visible: !calculator.endPageVisibility
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: parent.height * 0.3
}
onClicked: {
calculator.checkSum(sumInput.text)
}
}
Label {
id: won
text: calculator.endPageLabelText
font.pixelSize: parent.width * 0.2
visible: calculator.endPageVisibility
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: parent.height * 0.05
}
}
Label {
id: sum
text: "Sum: " + calculator.sum
font.pixelSize: parent.width * 0.1
visible: calculator.endPageVisibility ? ( won.text==="You Lose!" ? true:false):false
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: parent.height * 0.4
}
}
Row {
id: buttonRow
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: parent.height * 0.15
}
height: childrenRect.height
width: childrenRect.width
spacing: parent.width * 0.1
visible: calculator.endPageVisibility ? true:false
RoundButton {
id: homeButton
height: root.width * 0.2
width: height
text: "home"
onClicked: {
game.start()
}
}
RoundButton {
id: startButtons
height: root.width * 0.2
width: height
text: "start"
onClicked: {
calculator.start()
}
}
}
}

View file

@ -1,110 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.4
import "./"
Page {
id: root
signal pageOpened()
Label {
id: num
anchors.centerIn: parent
font.pixelSize: parent.height * 0.6
text: calculator.nextNum
}
Label {
id: gameProcess
text: calculator.actualNumCount + " of " + calculator.numCount
font.pixelSize: parent.width * 0.05
anchors {
right: parent.right
rightMargin: parent.width * 0.025
bottom: parent.bottom
bottomMargin: parent.height * 0.05
}
}
ProgressBar {
id: prog
property int progress: 0
property string color: "green"
value: progress/100
anchors {
bottom: parent.bottom
bottomMargin: parent.height * 0.02
left: parent.left
leftMargin: parent.width * 0.01
right: parent.right
rightMargin: parent.width * 0.01
}
contentItem: Item {
Rectangle {
width: prog.visualPosition * parent.width
height: parent.height
color: prog.color
}
}
NumberAnimation {
id: progNumAnim
target: prog
property: "progress"
from: 100
to: 0
duration: tick.interval
easing.type: Easing.Linear
}
SequentialAnimation {
id: progColAnim
loops: 1
ColorAnimation {
id: progColAnim1
target: prog
property: "color"
from: "green"
to: "goldenrod"
duration: tick.interval/2
easing.type: Easing.Linear
}
ColorAnimation {
id: progColAnim2
target: prog
property: "color"
from: "goldenrod"
to: "darkRed"
duration: tick.interval/2
easing.type: Easing.Linear
}
}
}
Timer {
id: tick
interval: calculator.tickInterval
repeat: false
running: calculator.state === "running"
onTriggered: {
if (calculator.actualNumCount < calculator.numCount) {
nextNumber()
tick.start()
}
else {
calculator.state = "gameOver"
}
}
onRunningChanged: {
if(running){
progNumAnim.start()
progColAnim.start()
}
}
}
}

View file

@ -1,133 +0,0 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import "./"
Page {
id: root
signal pageOpened()
ColumnLayout {
id: column
//spacing: height / 40
width: parent.width
anchors.fill: parent
anchors.topMargin: parent.height * 0.02
anchors.bottomMargin: parent.height * 0.02
Label {
id: heading
font.pixelSize: parent.width * 0.075
text: "Calculator"
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.5 - width * 0.5
Layout.rightMargin: parent.width * 0.5 - width * 0.5
}
Label {
id: tickIntervalInfo
text: "Interval:"
font.pixelSize: parent.height * 0.05
Layout.leftMargin: parent.width * 0.05
}
TextField {
id: tickInterval
text: calculator.tickInterval
placeholderText: "interval"
validator: IntValidator {bottom: 1; top: 100000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
Label {
id: numCountInfo
text: "Summands:"
font.pixelSize: parent.height * 0.05
Layout.leftMargin: parent.width * 0.05
}
TextField {
id: numCount
text: calculator.numCount
placeholderText: "summands"
validator: IntValidator {bottom: 1; top: 100000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
Label {
id: minInfo
text: "Minimum:"
font.pixelSize: parent.height * 0.05
Layout.leftMargin: parent.width * 0.05
}
TextField {
id: min
text: calculator.min
placeholderText: "minimum"
validator: IntValidator {bottom: -100000; top: 100000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
Label {
id: maxInfo
text: "Maximum:"
font.pixelSize: parent.height * 0.05
Layout.leftMargin: parent.width * 0.05
}
TextField {
id: max
text: calculator.max
placeholderText: "maximum"
validator: IntValidator {bottom: -100000; top: 100000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
RoundButton {
id: startButton
text: "start"
height: parent.width * 0.1
width: height
//font.pixelSize: parent.width * 0.03
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
onClicked: {
root.start()
}
}
}
function start() {
if (tickInterval.text > 0 && numCount.text > 0 && max.text > min.text) {
root.updateVars()
calculator.run()
}
}
function updateVars() {
calculator.tickInterval = tickInterval.text
calculator.numCount = numCount.text
calculator.min = min.text
calculator.max = max.text
}
}

View file

@ -1,197 +0,0 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import "./"
Item {
id: calender
property string nextDate: "31.12.1799"
property string lastDate: "30.12.1799"
property int actualDateCount: 0
property int min: 1800
property int max: 2199
property int tickInterval: 10000
property int dateCount: 10
property int correct: 0
property int wrong: 0
property int weekDay: 1
property bool runningPageState: true
signal pageOpened()
onPageOpened: {
calender.start()
}
states: [
State {
name: "starting"
PropertyChanges {
target: calenderStack
currPage: calenderStartPageComp
}
},
State {
name: "running"
PropertyChanges {
target: calenderStack
currPage: calenderRunningPageComp
}
},
State {
name: "gameOver"
PropertyChanges {
target: calenderStack
currPage: calenderGameOverPageComp
}
}
]
StackView {
id: calenderStack
property var currPage;
anchors.fill: parent
onCurrPageChanged: {
calenderStack.replace(currPage)
}
onCurrentItemChanged: {
calenderStack.currentItem.pageOpened()
}
Component {
id: calenderStartPageComp
CalenderStartPage {
}
}
Component {
id: calenderRunningPageComp
CalenderRunningPage {
}
}
Component {
id: calenderGameOverPageComp
CalenderGameOverPage {
}
}
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 start() {
calender.reset()
calender.state = "starting"
}
function run() {
calender.generateNextDate()
calender.state = "running"
}
function gameOver() {
calender.state = "gameOver"
}
function reset() {
calender.actualDateCount = 0
calender.lastDate = 0
calender.nextDate = 0
calender.correct = 0
calender.wrong = 0
}
function generateNextDate() {
var daysPerMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
var monthCodes = [6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
var yearCode = 0
var randDate = calender.nextDate
var randDay = 31
var randMonth = 12
var randYear = 1799
var range = calender.max - calender.min
var century = 17
var weekDay = 1
calender.lastDate = calender.nextDate
while (randDate === calender.lastDate) {
//console.log("entered mainwhile " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
randYear = Math.floor((Math.random()*(range+1))+calender.min)
//console.log("generated year " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
century = Math.floor(randYear/100)
//console.log("calculated century " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
yearCode = (randYear - century * 100) + Math.floor((randYear - century * 100)/4)
//console.log("generated yearCode " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
while (century > 21) {
century -= 4
//console.log("down count century " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
}
switch (century) {
case 18:
yearCode += 3
break
case 19:
yearCode += 1
break
case 21:
yearCode += 5
break
default:
//console.log("added century specified value to yearCode " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
}
randMonth = Math.floor((Math.random()*(12))+1)
//console.log("generated month " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
if (randYear % 4 === 0 && randMonth <= 2) {
yearCode += 6
//console.log("if leap-year " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
}
while (yearCode >= 7) {
yearCode -= 7
//console.log("down count yearCode " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
}
randDay = Math.floor((Math.random()*(daysPerMonth[randMonth-1]))+1)
//console.log("generated Day " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
randDate = String(randDay) + "." + String(randMonth) + "." + String(randYear)
//console.log("generated randDate " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
}
weekDay = (yearCode + monthCodes[randMonth-1] + randDay) // - 7*Math.floor((yearCode + monthCodes[randMonth-1] + randDay)/7)
//console.log("generated weekday " + "yearCode: " + yearCode + " randDate: " + randDate + " randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + " century: " + century + " weekDay: " + weekDay)
//weekDay -= 7*Math.floor(weekDay/7)
while (weekDay >= 7) {
weekDay -= 7
//console.log("down count weekday " + "yearCode: " + yearCode + " randDate: " + randDate + /*" randDay: " + randDay + " randMonth: " + randMonth + " randYear: " + randYear + " Range: " + range + */ " century: " + century + " weekDay: " + weekDay)
}
console.log("randDate: " + randDate + " yearCode: " + yearCode + " century: " + century + " weekDay: " + weekDay)
calender.weekDay = weekDay
calender.nextDate = randDate
calender.actualDateCount += 1
}
}

View file

@ -1,52 +0,0 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import "./"
Page {
id: root
signal pageOpened()
Label {
id: percent
text: "You had " + calender.dateCount/calender.correct*100 + "% right!"
font.pixelSize: parent.width * 0.05
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: parent.height * 0.2
}
}
Row {
id: buttonRow
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: parent.height * 0.15
}
height: childrenRect.height
width: childrenRect.width
spacing: parent.width * 0.1
RoundButton {
id: homeButton
height: root.width * 0.2
width: height
text: "home"
onClicked: {
game.start()
}
}
RoundButton {
id: startButtons
height: root.width * 0.2
width: height
text: "start"
onClicked: {
calender.start()
}
}
}
}

View file

@ -1,138 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.4
import "./"
Page {
id: root
signal pageOpened()
Label {
id: date
anchors.centerIn: parent
font.pixelSize: parent.height * 0.2
text: calender.nextDate
visible: calender.runningPageState ? true:false
}
Label {
id: gameProcess
text: calender.actualDateCount + " of " + calender.dateCount
font.pixelSize: parent.width * 0.05
anchors {
right: parent.right
rightMargin: parent.width * 0.025
bottom: parent.bottom
bottomMargin: parent.height * 0.05
}
}
ProgressBar {
id: prog
property int progress: 0
property string color: "green"
value: progress/100
anchors {
bottom: parent.bottom
bottomMargin: parent.height * 0.02
left: parent.left
leftMargin: parent.width * 0.01
right: parent.right
rightMargin: parent.width * 0.01
}
visible: calender.runningPageState ? true:false
contentItem: Item {
Rectangle {
width: prog.visualPosition * parent.width
height: parent.height
color: prog.color
}
}
NumberAnimation {
id: progNumAnim
target: prog
property: "progress"
from: 100
to: 0
duration: tick.interval
easing.type: Easing.Linear
}
SequentialAnimation {
id: progColAnim
loops: 1
ColorAnimation {
id: progColAnim1
target: prog
property: "color"
from: "green"
to: "goldenrod"
duration: tick.interval/2
easing.type: Easing.Linear
}
ColorAnimation {
id: progColAnim2
target: prog
property: "color"
from: "goldenrod"
to: "darkRed"
duration: tick.interval/2
easing.type: Easing.Linear
}
}
}
ComboBox {
id: comboBox
model: ["None", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
anchors.centerIn: parent
visible: calender.runningPageState ? false:true
onCurrentTextChanged: {
if (currentIndex !== 0) {
if (currentIndex === calender.weekDay) {
calender.correct += 1
}
else {
calender.wrong += 1
}
/*
Timer, {
id: pause
interval: 200
repeat: false
}
*/
if (calender.actualDateCount < calender.dateCount) {
calender.generateNextDate()
tick.start()
calender.runningPageState = true
}
else {
calender.state = "gameOver"
}
}
}
}
Timer {
id: tick
interval: calender.tickInterval
repeat: false
running: calender.state === "running"
onTriggered: {
calender.runningPageState = false
comboBox.currentIndex = 0
}
onRunningChanged: {
if(running){
progNumAnim.start()
progColAnim.start()
}
}
}
}

View file

@ -1,132 +0,0 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import "./"
Page {
id: root
signal pageOpened()
ColumnLayout {
id: column
//spacing: height / 40
width: parent.width
anchors.fill: parent
anchors.topMargin: parent.height * 0.02
anchors.bottomMargin: parent.height * 0.02
Label {
id: heading
font.pixelSize: parent.width * 0.075
text: "Calender"
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.5 - width * 0.5
Layout.rightMargin: parent.width * 0.5 - width * 0.5
}
Label {
id: tickIntervalInfo
text: "Interval:"
font.pixelSize: parent.height * 0.05
Layout.leftMargin: parent.width * 0.05
}
TextField {
id: tickInterval
text: calender.tickInterval
placeholderText: "interval"
validator: IntValidator {bottom: 1; top: 1000000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
Label {
id: dateCountInfo
text: "Dates:"
font.pixelSize: parent.height * 0.05
Layout.leftMargin: parent.width * 0.05
}
TextField {
id: dateCount
text: calender.dateCount
placeholderText: "dates"
validator: IntValidator {bottom: 1; top: 100000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
Label {
id: minInfo
text: "Minimum:"
font.pixelSize: parent.height * 0.05
Layout.leftMargin: parent.width * 0.05
}
TextField {
id: min
text: calender.min
placeholderText: "minimum"
validator: IntValidator {bottom: 1800; top: 10000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
Label {
id: maxInfo
text: "Maximum:"
font.pixelSize: parent.height * 0.05
Layout.leftMargin: parent.width * 0.05
}
TextField {
id: max
text: calender.max
placeholderText: "maximum"
validator: IntValidator {bottom: 1800; top: 10000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
RoundButton {
id: startButton
text: "start"
height: parent.width * 0.1
width: height
//font.pixelSize: parent.width * 0.03
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
onClicked: {
root.start()
}
}
}
function start() {
if (tickInterval.text > 0 && dateCount.text > 0 && min.text >= 1800 && max.text >= min.text) {
root.updateVars()
calender.run()
}
}
function updateVars() {
calender.tickInterval = tickInterval.text
calender.dateCount = dateCount.text
calender.min = min.text
calender.max = max.text
}
}

42
headers/appsettings.h Normal file
View file

@ -0,0 +1,42 @@
#ifndef APPSETTINGS_H
#define APPSETTINGS_H
#include <QObject>
#include <QtDebug>
#include <QSettings>
#include <QStandardPaths>
class AppSettings : public QObject
{
Q_OBJECT
public:
explicit AppSettings(QObject *parent = nullptr);
// This is the Constructor of the AppSettings class
~AppSettings();
// This is the Destructor of the AppSettings class
private:
QSettings *settingsManager;
// QSettings object which cares about our settings.ini file
QSettings *themeSettingsManager;
// QSettings object which cares about our themes
signals:
public slots:
Q_INVOKABLE QString read(const QString &key);
// function to read values from the settings file
Q_INVOKABLE void write(const QString &key, const QVariant &value);
// function to write values from the settings file
Q_INVOKABLE void setDefault(const QString &key, const QVariant &defaultValue);
// function to create a key (/ setting) with a default value if it hasn't been created yet
Q_INVOKABLE QString theme(QString key);
// function to get style settings from a theme file
};
#endif // APPSETTINGS_H

106
main.qml
View file

@ -1,106 +0,0 @@
import QtQuick 2.9
import QtQuick.Window 2.3
import QtQuick.Controls 2.4
import "./calender"
import "./calculator"
Window {
visible: true
width: 640
height: 480
title: qsTr("Training")
Item {
id: game
anchors.fill: parent
state: "starting"
states: [
State {
name: "starting"
PropertyChanges {
target: mainStack
currPage: startPageComp
}
},
State {
name: "calender"
PropertyChanges {
target: mainStack
currPage: calenderPageComp
}
},
State {
name: "calculator"
PropertyChanges {
target: mainStack
currPage: calculatorPageComp
}
}
]
StackView {
id: mainStack
property var currPage
anchors.fill: parent
onCurrPageChanged: {
mainStack.replace(currPage)
}
onCurrentItemChanged: {
mainStack.currentItem.pageOpened()
}
Component {
id: startPageComp
StartPage {
}
}
Component {
id: calenderPageComp
Calender {
}
}
Component {
id: calculatorPageComp
Calculator {
}
}
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
}
}
}
function start() {
game.state = "starting"
}
function calender() {
game.state = "calender"
}
function calculator() {
game.state = "calculator"
}
}
}

View file

@ -13,9 +13,16 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \ SOURCES += \
sources\main.cpp sources/main.cpp \
sources/appsettings.cpp
RESOURCES += qml/qml.qrc \
shared/shared.qrc
HEADERS += \
headers/ \
headers/appsettings.h
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model # Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH = QML_IMPORT_PATH =
@ -27,3 +34,10 @@ QML_DESIGNER_IMPORT_PATH =
qnx: target.path = /tmp/$${TARGET}/bin qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target !isEmpty(target.path): INSTALLS += target
DISTFILES += \
android-sources/AndroidManifest.xml
android {
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
}

14
qml.qrc
View file

@ -1,14 +0,0 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>calender/Calender.qml</file>
<file>StartPage.qml</file>
<file>calculator/CalculatorRunningPage.qml</file>
<file>calculator/CalculatorStartPage.qml</file>
<file>calculator/CalculatorGameOverPage.qml</file>
<file>calculator/Calculator.qml</file>
<file>calender/CalenderStartPage.qml</file>
<file>calender/CalenderRunningPage.qml</file>
<file>calender/CalenderGameOverPage.qml</file>
</qresource>
</RCC>

View file

@ -0,0 +1,37 @@
import QtQuick 2.0
import QtQuick.Controls 2.2
Button {
id: control
width: height
font.pixelSize: width * 0.15
scale: pressed ? 0.8:1
contentItem: Text {
text: control.text
font: control.font
opacity: enabled ? 1.0 : 0.3
color: settings.theme("ButtonTextColor")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
color: settings.theme("ButtonBackgroundColor")
radius: width * 0.5
border.color: settings.theme("ButtonBorderColor")
border.width: parseInt(settings.theme("ButtonBorderWidth"))
}
Behavior on scale {
NumberAnimation {
easing.type: Easing.InOutQuad
duration: 200
}
}
}

5
shared/shared.qrc Normal file
View file

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>themes/default.ini</file>
</qresource>
</RCC>

View file

@ -0,0 +1,8 @@
[MathTrainingStuffTheme]
PageBackgroundColor=white
PageTextColor=black
ButtonBackgroundColor=black
ButtonTextColor=white
ButtonBorderWidth=0
ButtonBorderColor=

86
sources/appsettings.cpp Normal file
View file

@ -0,0 +1,86 @@
#include "headers/appsettings.h"
AppSettings::AppSettings(QObject* parent)
:QObject(parent)
{
// This is the Constructor of the AppSettings class
// get writable path to store the settings.ini file
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
qDebug() << "app settings path: " << path;
// create or open the settings.ini file
this->settingsManager = new QSettings(path+"/settings.ini", QSettings::IniFormat);
// set the values to their defaults if they haven't been created yet
this->setDefault("highscore", "0");
// create or open the settings.ini file
this->themeSettingsManager = new QSettings(":/themes/default.ini", QSettings::IniFormat);
}
QString AppSettings::read(const QString &key)
{
// function to read values from the settings file
// open the value-group
this->settingsManager->beginGroup("AppSettings");
// read the value
QString value = this->settingsManager->value(key , false).toString();
// close the value-group
this->settingsManager->endGroup();
// return the value
return(value);
}
QString AppSettings::theme(QString key)
{
// function to get style settings from a theme file
// open the value-group
this->themeSettingsManager->beginGroup("MathTrainingStuffTheme");
// read the value
QString value = this->themeSettingsManager->value(key, false).toString();
// close the value-group
this->themeSettingsManager->endGroup();
// return the value
return(value);
}
void AppSettings::write(const QString &key, const QVariant &value)
{
// function to write values to the settings file
// open the value-group
this->settingsManager->beginGroup("AppSettings");
// write the value
this->settingsManager->setValue(key, value);
// close the value-group
this->settingsManager->endGroup();
}
void AppSettings::setDefault(const QString &key, const QVariant &defaultValue)
{
// function to create a key (/ setting) with a default value if it hasnt been ceated yet
// read the current value
QString value = this->read(key);
if(value == "false"){
// if it is not defined yet, the read function will return "false" (as a string)
// -> if that is the case -> create the key with the default value
this->write(key, defaultValue);
}
}
AppSettings::~AppSettings()
{
// This is the Destructor of the AppSettings class
// delete the settings manager
delete settingsManager;
// delete the theme Manager
delete themeSettingsManager;
}

View file

@ -1,5 +1,6 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include "headers/appsettings.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -7,6 +8,8 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
qmlRegisterType<AppSettings>("com.max.mathtrainingstuff", 1, 0, "AppSettings");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty()) if (engine.rootObjects().isEmpty())