diff --git a/src/activities/multiplication_tables/Multiplication_tables.qml b/src/activities/multiplication_tables/Multiplication_tables.qml index f0bc89c5a..f51cc50cc 100644 --- a/src/activities/multiplication_tables/Multiplication_tables.qml +++ b/src/activities/multiplication_tables/Multiplication_tables.qml @@ -1,303 +1,277 @@ /* GCompris - multiplication_tables.qml * * Copyright (C) 2016 Nitish Chauhan * * Authors: * * Nitish Chauhan (Qt Quick port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import QtQuick 2.1 import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 import QtQuick.Layouts 1.1 - import "../../core" -import "multiplication_tables.js" -as Activity -import "multiplicationtables_dataset.js" -as Dataset - +import "multiplication_tables.js" as Activity +import "multiplicationtables_dataset.js" as Dataset ActivityBase { id: activity - property string url: "qrc:/gcompris/src/activities/multiplication_tables/resource/" property double startTime: 0 - property int flag: 0 - property - var dataset: Dataset + property bool startButtonClicked: false + property var dataset: Dataset property string mode: "multiplicationtables" - onStart: focus = true onStop: {} pageComponent: Rectangle { id: background anchors.fill: parent color: "#ABCDEF" signal start signal stop Component.onCompleted: { activity.start.connect(start) activity.stop.connect(stop) } // Add here the QML items you need to access in javascript QtObject { - id: items property Item main: activity.main property alias background: background property alias bar: bar property alias bonus: bonus property alias start_button: start_button property alias stop_button: stop_button property alias time: time property alias score: score property alias questionGrid: questionGrid property alias repeater: repeater - } onStart: { Activity.start(items, mode, dataset, url) - } onStop: { Activity.stop() } Flow { - id: questionGrid anchors.fill: parent anchors.bottom: bar.top - spacing: 50 - + spacing: bar.height * 0.4 anchors { left: background.left right: background.rigth - margins: 60 + margins: bar.height * 0.6 } - Repeater { id: repeater model: 10 - Question { } } } Image { id: player source: url + "children.svg" anchors { bottom: bar.bottom right: parent.right } width: height * 0.83 height: bar.height * 1.2 } Button { id: stop_button text: qsTr(" FINISH ") anchors.bottom: parent.bottom anchors.right: parent.right anchors { - bottomMargin: 50 - rightMargin: 120 + bottomMargin: bar.height * 0.4 + rightMargin: bar.height * 1.5 } style: ButtonStyle { background: Rectangle { - implicitWidth: 100 - implicitHeight: 40 + implicitWidth: bar.height * 0.9 + implicitHeight: bar.height * 0.3 border.width: control.activeFocus ? 2 : 1 border.color: "blue" radius: 4 gradient: Gradient { GradientStop { position: 0;color: control.pressed ? "#729fcf" : "#729fcf" } GradientStop { position: 1;color: control.pressed ? "#3465a4" : "#3465a4" } } } } onClicked: { - if (flag == 1) { + if (startButtonClicked == true) { score.visible = true var str1 = new Date().getTime() - startTime - time.text = qsTr("Your time: %1 ms").arg(str1) + var str2 = str1/1000 + time.text = qsTr("Your time: %1 seconds").arg(str2) startTime = 0 - flag = 0 + startButtonClicked = false start_button.text = qsTr("START AGAIN") Activity.verifyAnswer() } } } - Button { id: start_button text: qsTr(" START ") anchors.bottom: parent.bottom anchors.right: stop_button.left anchors { - bottomMargin: 50 - rightMargin: 30 + bottomMargin: bar.height * 0.4 + rightMargin: bar.height * 0.4 } - style: ButtonStyle { background: Rectangle { - implicitWidth: 100 - implicitHeight: 40 + implicitWidth: bar.height * 0.9 + implicitHeight: bar.height * 0.3 border.width: control.activeFocus ? 2 : 1 border.color: "blue" radius: 4 gradient: Gradient { GradientStop { position: 0;color: control.pressed ? "#729fcf" : "#729fcf" } GradientStop { position: 1;color: control.pressed ? "#3465a4" : "#3465a4" } } } } - - onClicked: { - - if (startTime == 0 && flag == 0) { + if (startTime == 0 && startButtonClicked == false) { Activity.resetvalue() start_button.text = qsTr(" START ") - time.text = qsTr(" Your timer started...") + time.text = qsTr(" Your Timer Started...") startTime = new Date().getTime() - flag = 1 + startButtonClicked = true } } } - GCText { id: score font.pointSize: 20 color: "#4B6319" font.bold: true anchors.bottom: time.top anchors.right: parent.right - anchors { - bottomMargin: 15 - rightMargin: 150 + bottomMargin: bar.height * 0.09 + rightMargin: bar.height * 1.6 } Layout.alignment: Qt.AlignCenter } GCText { id: time font.pixelSize: 23 font.bold: true color: '#4B6319' anchors.bottom: start_button.top anchors.right: parent.right anchors { - bottomMargin: 30 + bottomMargin: bar.height * 0.3 rightMargin: 130 } text: qsTr("--") Layout.alignment: Qt.AlignCenter } DialogActivityConfig { id: dialogActivityConfig currentActivity: activity content: Component { Item { height: column.height - Column { id: column spacing: 10 width: parent.width GCDialogCheckBox { id: easyModeBox1 width: 250 * ApplicationInfo.ratio text: qsTr("School Mode") checked: background.easyMode onCheckedChanged: { background.easyMode = checked Activity.reloadRandom() } } } } } onLoadData: { if (dataToSave && dataToSave["mode"]) { background.easyMode = (dataToSave["mode"] === "true"); } } - onSaveData: { dataToSave = { "mode": "" + background.easyMode } } - onClose: home() } - - DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | level | config } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onReloadClicked: Activity.reloadRandom() onConfigClicked: { dialogActivityConfig.active = true displayDialog(dialogActivityConfig) } } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } } - } diff --git a/src/activities/multiplication_tables/Question.qml b/src/activities/multiplication_tables/Question.qml index 3b06f1b07..1e792adc8 100644 --- a/src/activities/multiplication_tables/Question.qml +++ b/src/activities/multiplication_tables/Question.qml @@ -1,87 +1,67 @@ /* GCompris * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import QtQuick 2.1 import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 import QtQuick.Layouts 1.1 import "multiplication_tables.js" as Activity import QtGraphicalEffects 1.0 import "../../core" import GCompris 1.0 - - - -Row { - - id: row1 - +Flow { + id: questionItem property string url: "qrc:/gcompris/src/activities/multiplication_tables/resource/" property alias questionText: questionText.text property alias answerText: answerText.text property alias questionImage: question_image.source property alias questionImage_visible: question_image.opacity - - - - // 10 questions GCText { id: questionText - text:"Question" + text:qsTr("Question") font.pointSize: 20 font.bold: true color: "black" - } - - TextField { - id: answerText height: 35 font.pixelSize: 20 - - style: TextFieldStyle { - textColor: "#006060" - background: Rectangle { - radius: 5 - color: "orange" - implicitWidth: 100 - implicitHeight: 24 - border.color: "#333" - border.width: 1 - } + textColor: "#006060" + background: Rectangle { + radius: 5 + color: "orange" + implicitWidth: bar.height * 0.9 + implicitHeight: bar.height * 0.3 + border.color: "#333" + border.width: 1 } - + } } Image { id: question_image - width: 70;height: 50 + width: bar.height * 0.3 + height: bar.height * 0.3 fillMode: Image.PreserveAspectFit source: "qrc:/gcompris/src/activities/multiplication_tables/resource/wrong.svg" opacity: 0 } - } - - - - diff --git a/src/activities/multiplication_tables/multiplication_tables.js b/src/activities/multiplication_tables/multiplication_tables.js index 7bac844d1..516812502 100644 --- a/src/activities/multiplication_tables/multiplication_tables.js +++ b/src/activities/multiplication_tables/multiplication_tables.js @@ -1,155 +1,113 @@ /* GCompris - multiplication_tables.js * * Copyright (C) 2016 Nitish Chauhan * * Authors: * * "Nitish Chauhan" (Qt Quick port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ .pragma library .import QtQuick 2.2 as Quick .import GCompris 1.0 as GCompris //for ApplicationInfo .import "qrc:/gcompris/src/core/core.js" as Core - var currentLevel = 0 var items var mode var dataset var numberOfLevel var url var table var question = [] var answer = [] var score_cnt = 0 - function start(_items, _mode, _dataset, _url) { - items = _items mode = _mode dataset = _dataset.get() url = _url numberOfLevel = dataset.length currentLevel = 0 initLevel() - } - function stop() {} function initLevel() { - items.bar.level = currentLevel + 1 loadQuestions() - } - function loadQuestions() { - var i - question = dataset[currentLevel].questions answer = dataset[currentLevel].answers table = dataset[currentLevel].TableName - for (i = 0; i < question.length; i++) { - items.repeater.itemAt(i).questionText = qsTr("%1 = ").arg(question[i]) - } - } - function verifyAnswer() { - var j - for (j = 0; j < question.length; j++) { - if (items.repeater.itemAt(j).answerText.toString() == answer[j]) { - score_cnt = score_cnt + 1 items.repeater.itemAt(j).questionImage = url + "right.svg" items.repeater.itemAt(j).questionImage_visible = 1 - - - } else { - + } + else { items.repeater.itemAt(j).questionImage_visible = 1 items.repeater.itemAt(j).questionImage = url + "wrong.svg" - } - } - - items.score.text = qsTr("Your Score :- %1").arg(score_cnt.toString()) - } - - function resetvalue() { - var k - for (k = 0; k < question.length; k++) { - - - items.repeater.itemAt(k).answerText = "" + items.repeater.itemAt(k).answerText = qsTr("") items.repeater.itemAt(k).questionImage_visible = 0 - - score_cnt = 0 items.score.visible = false - } - score_cnt = 0 items.score.visible = false - } - - - function nextLevel() { - - if (numberOfLevel <= ++currentLevel) { currentLevel = 0 } initLevel(); resetvalue(); items.start_button.text = qsTr("START") items.score.visible = false items.time.text = qsTr("--") } function previousLevel() { if (--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); resetvalue(); items.score.visible = false items.time.text = qsTr("--") } diff --git a/src/activities/multiplication_tables/multiplicationtables_dataset.js b/src/activities/multiplication_tables/multiplicationtables_dataset.js index 1d8c3a2b3..5282dc88c 100644 --- a/src/activities/multiplication_tables/multiplicationtables_dataset.js +++ b/src/activities/multiplication_tables/multiplicationtables_dataset.js @@ -1,61 +1,60 @@ /* GCompris - multiplicationtables_dataset.js * Copyright (C) 2016 Nitish Chauhan * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ function get() { return [ - { "TableName": "2", "questions": ["2 X 1", "2 X 2", "2 X 3", "2 X 4", "2 X 5", "2 X 6", "2 X 7", "2 X 8", "2 X 9", "2 X 10"], "answers": ["2", "4", "6", "8", "10", "12", "14", "16", "18", "20"] }, { "TableName": "3", "questions": ["3 X 1", "3 X 2", "3 X 3", "3 X 4", "3 X 5", "3 X 6", "3 X 7", "3 X 8", "3 X 9", "3 X 10"], "answers": ["3", "6", "9", "12", "15", "18", "21", "24", "27", "30"] }, { "TableName": "4", "questions": ["4 X 1", "4 X 2", "4 X 3", "4 X 4", "4 X 5", "4 X 6", "4 X 7", "4 X 8", "4 X 9", "4 X 10"], "answers": ["4", "8", "12", "16", "20", "24", "28", "32", "36", "40"] }, { "TableName": "5", "questions": ["5 X 1", "5 X 2", "5 X 3", "5 X 4", "5 X 5", "5 X 6", "5 X 7", "5 X 8", "5 X 9", "5 X 10"], "answers": ["5", "10", "15", "20", "25", "30", "35", "40", "45", "50"] }, { "TableName": "6", "questions": ["6 X 1", "6 X 2", "6 X 3", "6 X 4", "6 X 5", "6 X 6", "6 X 7", "6 X 8", "6 X 9", "6 X 10"], "answers": ["6", "12", "18", "24", "30", "36", "42", "48", "54", "60"] }, { "TableName": "7", "questions": ["7 X 1", "7 X 2", "7 X 3", "7 X 4", "7 X 5", "7 X 6", "7 X 7", "7 X 8", "7 X 9", "7 X 10"], "answers": ["7", "14", "21", "28", "35", "42", "48", "56", "63", "70"] }, { "TableName": "8", "questions": ["8 X 1", "8 X 2", "8 X 3", "8 X 4", "8 X 5", "8 X 6", "8 X 7", "8 X 8", "8 X 9", "8 X 10"], "answers": ["8", "16", "24", "32", "40", "48", "56", "64", "72", "80"] }, { "TableName": "9", "questions": ["9 X 1", "9 X 2", "9 X 3", "9 X 4", "9 X 5", "9 X 6", "9 X 7", "9 X 8", "9 X 9", "9 X 10"], "answers": ["9", "18", "27", "36", "45", "54", "63", "72", "81", "90"] } ] }