diff --git a/src/activities/lang/Lang.qml b/src/activities/lang/Lang.qml index 6e81554eb..0b70b9460 100644 --- a/src/activities/lang/Lang.qml +++ b/src/activities/lang/Lang.qml @@ -1,413 +1,425 @@ /* GCompris - lang.qml - * -<<<<<<< HEAD - * Copyright (C) 2014 -======= - * Copyright (C) 2014 Siddhesh suthar ->>>>>>> lang activity with simplified javascript code - * - * Authors: - * Pascal Georges (pascal.georges1@free.fr) (GTK+ version) - * Siddhesh suthar (Qt Quick port) - * Bruno Coudoin (Integration Lang dataset) - * - * 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 . - */ +* +* Copyright (C) Holger Kaelberer (Qt Quick port of imageid) +* +* Authors: +* Pascal Georges (pascal.georges1@free.fr) (GTK+ version) +* Holger Kaelberer (Qt Quick port of imageid) +* Siddhesh suthar (Qt Quick port) +* Bruno Coudoin (Integration Lang dataset) +* +* 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 GCompris 1.0 import QtGraphicalEffects 1.0 import "../../core" import "lang.js" as Activity import "qrc:/gcompris/src/core/core.js" as Core ActivityBase { id: activity onStart: focus = true onStop: {} pageComponent: Image { id: background source: "qrc:/gcompris/src/activities/lang/resource/imageid-bg.svg" fillMode: Image.PreserveAspectCrop sourceSize.width: parent.width property bool horizontalLayout: background.width > background.height property bool keyNavigation: false readonly property string wordsResource: "data2/words/words.rcc" property bool englishFallback: false property bool downloadWordsNeeded: false signal start signal stop signal voiceError signal voiceDone 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 score: score property alias wordImage: wordImage + property alias imageFrame: imageFrame property alias wordText: wordText property alias categoryText: categoryText property alias wordListModel: wordListModel property alias parser: parser property int count: 0 property variant goodWord property int goodWordIndex property alias englishFallbackDialog: englishFallbackDialog + property alias quiz: quiz function playWord() { if (!activity.audioVoices.append(ApplicationInfo.getAudioFilePath(goodWord.voice))) voiceError(); } onGoodWordChanged: playWord() } function handleResourceRegistered(resource) { if (resource == wordsResource) Activity.start(items); } onStart: { - Activity.init(items) + Activity.init(items,quiz) //change here passing quiz repeatItem.visible = false keyNavigation = false activity.audioVoices.error.connect(voiceError) activity.audioVoices.done.connect(voiceDone) // check for words.rcc: if (DownloadManager.isDataRegistered("words")) { // words.rcc is already registered -> start right away Activity.start(items); } else if(DownloadManager.haveLocalResource(wordsResource)) { // words.rcc is there, but not yet registered -> updateResource DownloadManager.resourceRegistered.connect(handleResourceRegistered); DownloadManager.updateResource(wordsResource); } else { // words.rcc has not been downloaded yet -> ask for download downloadWordsNeeded = true } } onStop: { DownloadManager.resourceRegistered.disconnect(handleResourceRegistered); Activity.stop() } JsonParser { id: parser onError: console.error("lang: Error parsing json: " + msg); } ListModel { id: wordListModel } Rectangle{ id: categoryTextbg x: categoryText.x -4 y: categoryText.y -4 width: imageFrame.width height: categoryText.height +4 color: "#5090ff" border.color: "#000000" border.width: 2 radius: 16 anchors.bottom: imageFrame.top anchors.left: imageFrame.left anchors.bottomMargin: 20 GCText{ id: categoryText text: "" fontSize: largeSize font.weight: Font.DemiBold width: parent.width horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "white" wrapMode: Text.WordWrap property string nextCategory function changeCategory(nextCategory_) { nextCategory = nextCategory_ animCategory.start() } SequentialAnimation { id: animCategory PropertyAnimation { target: categoryText property: "opacity" to: 0 duration: 100 } PropertyAction { target: categoryText property: "text" value: "Category: "+ categoryText.nextCategory } PropertyAnimation { target: categoryText property: "opacity" to: 1 duration: 100 } } } } Image { id: imageFrame width: background.width * 0.55 height: background.horizontalLayout ? (background.height - bar.height)* 0.7 : (background.height - bar.height) * 0.4 anchors { horizontalCenter: background.horizontalCenter top: background.top topMargin: (background.height - bar.height) * 0.15 } source: "qrc:/gcompris/src/activities/lang/resource/imageid_frame.svg" sourceSize.width: background.horizontalLayout ? parent.width * 0.9 : parent.height * 1.2 z: 11 Image { id: wordImage sourceSize.width: parent.width * 0.6 anchors { centerIn: parent margins: 0.05 + parent.width } property string nextSource function changeSource(nextSource_) { nextSource = nextSource_ animImage.start() } SequentialAnimation { id: animImage PropertyAnimation { target: wordImage property: "opacity" to: 0 duration: 100 } PropertyAction { target: wordImage property: "source" value: wordImage.nextSource } PropertyAnimation { target: wordImage property: "opacity" to: 1 duration: 100 } } } Image{ id: previousWordButton source: "qrc:/gcompris/src/core/resource/bar_previous.svg"; sourceSize.width: 30 * 1.2 * ApplicationInfo.ratio anchors{ right: parent.left rightMargin: 30 top: parent.top topMargin: parent.height/2 - previousWordButton.height/2 } MouseArea{ id: previousWordButtonArea anchors.fill: parent onClicked: Activity.prevSubLevel() } } Image{ id: nextWordButton source: "qrc:/gcompris/src/core/resource/bar_next.svg"; sourceSize.width: 30 * 1.2 * ApplicationInfo.ratio anchors{ left: parent.right leftMargin: 30 top: parent.top topMargin: parent.height/2 - previousWordButton.height/2 } MouseArea{ id: nextWordButtonArea anchors.fill: parent onClicked: Activity.nextSubLevel(); } } } Rectangle{ id: wordTextbg x: wordText.x -4 y: wordText.y -4 width: imageFrame.width height: wordText.height +4 color: "#5090ff" border.color: "#000000" border.width: 2 radius: 16 anchors.top: imageFrame.bottom anchors.left: imageFrame.left anchors.topMargin: 20 GCText{ id: wordText text: "" fontSize: largeSize font.weight: Font.DemiBold width: parent.width horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "white" wrapMode: Text.WordWrap property string nextWord function changeText(nextWord_) { nextWord = nextWord_ animWord.start() } SequentialAnimation { id: animWord PropertyAnimation { target: wordText property: "opacity" to: 0 duration: 100 } PropertyAction { target: wordText property: "text" value: wordText.nextWord } PropertyAnimation { target: wordText property: "opacity" to: 1 duration: 100 } } } } onVoiceDone: repeatItem.visible = true onVoiceError: repeatItem.visible = false BarButton { id: repeatItem source: "qrc:/gcompris/src/core/resource/bar_repeat.svg"; sourceSize.width: 80 * ApplicationInfo.ratio z: 12 anchors { top: parent.top left: parent.left margins: 10 * ApplicationInfo.ratio } onClicked: items.playWord() } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | level } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() + onReloadClicked: { + items.count = 0 + list.visible = false + } } - } - Bonus { - id: bonus - Component.onCompleted: win.connect(Activity.nextLevel) - } + Bonus { + id: bonus + Component.onCompleted: win.connect(Activity.nextLevel) + } - Loader { - id: englishFallbackDialog - sourceComponent: GCDialog { - parent: activity.main - message: qsTr("We are sorry, we don't have yet a translation for your language.") + " " + - qsTr("GCompris is developed by the KDE community, you can translate GCompris by joining a translation team on %2").arg("http://l10n.kde.org/") + - "

" + - qsTr("We switched to English for this activity but you can select another language in the configuration dialog.") - onClose: background.englishFallback = false + Loader { + id: englishFallbackDialog + sourceComponent: GCDialog { + parent: activity.main + message: qsTr("We are sorry, we don't have yet a translation for your language.") + " " + + qsTr("GCompris is developed by the KDE community, you can translate GCompris by joining a translation team on %2").arg("http://l10n.kde.org/") + + "

" + + qsTr("We switched to English for this activity but you can select another language in the configuration dialog.") + onClose: background.englishFallback = false + } + anchors.fill: parent + focus: true + active: background.englishFallback + onStatusChanged: if (status == Loader.Ready) item.start() } - anchors.fill: parent - focus: true - active: background.englishFallback - onStatusChanged: if (status == Loader.Ready) item.start() - } - Loader { - id: downloadWordsDialog - sourceComponent: GCDialog { - parent: activity.main - message: qsTr("The images for this activity are not yet installed.") - button1Text: qsTr("Download the images") - onClose: background.downloadWordsNeeded = false - onButton1Hit: { - DownloadManager.resourceRegistered.connect(handleResourceRegistered); - DownloadManager.downloadResource(wordsResource) - var downloadDialog = Core.showDownloadDialog(activity, {}); + Loader { + id: downloadWordsDialog + sourceComponent: GCDialog { + parent: activity.main + message: qsTr("The images for this activity are not yet installed.") + button1Text: qsTr("Download the images") + onClose: background.downloadWordsNeeded = false + onButton1Hit: { + DownloadManager.resourceRegistered.connect(handleResourceRegistered); + DownloadManager.downloadResource(wordsResource) + var downloadDialog = Core.showDownloadDialog(activity, {}); + } } + anchors.fill: parent + focus: true + active: background.downloadWordsNeeded + onStatusChanged: if (status == Loader.Ready) item.start() } - anchors.fill: parent - focus: true - active: background.downloadWordsNeeded - onStatusChanged: if (status == Loader.Ready) item.start() - } - Score { - id: score + Score { + id: score + + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 * ApplicationInfo.ratio + anchors.right: parent.right + anchors.rightMargin: 10 * ApplicationInfo.ratio + anchors.top: undefined + } + + Quiz{ + id: quiz + displayed: false + width: parent.width + height: parent.height - bar.height +// wordImageQuiz: visible + } - anchors.bottom: parent.bottom - anchors.bottomMargin: 10 * ApplicationInfo.ratio - anchors.right: parent.right - anchors.rightMargin: 10 * ApplicationInfo.ratio - anchors.top: undefined } } diff --git a/src/activities/lang/lang.js b/src/activities/lang/lang.js index 0a58573f1..8bc1c4a70 100644 --- a/src/activities/lang/lang.js +++ b/src/activities/lang/lang.js @@ -1,148 +1,238 @@ /* GCompris - lang.js * -<<<<<<< HEAD - * Copyright (C) 2014 -======= * Copyright (C) 2014 Siddhesh suthar ->>>>>>> lang activity with simplified javascript code * * Authors: * Pascal Georges (pascal.georges1@free.fr) (GTK+ version) * Siddhesh suthar (Qt Quick port) * Bruno Coudoin (Integration Lang dataset) * * 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.0 as Quick .import GCompris 1.0 as GCompris .import "qrc:/gcompris/src/core/core.js" as Core .import "qrc:/gcompris/src/activities/lang/lang_api.js" as Lang var currentLevel = 0; var currentSubLevel = 0; var level = null; var maxLevel; var maxSubLevel; var items; +var quizItems; var baseUrl = "qrc:/gcompris/src/activities/lang/resource/"; var dataset = null; var lessons var wordList var subLevelsLeft -var backFlag -var flag +var miniGame -function init(items_) { +function init(items_,quiz_) { items = items_ + quizItems = quiz_ maxLevel = 0 maxSubLevel = 0 currentLevel = 0 currentSubLevel = 0 } function start() { currentLevel = 0; currentSubLevel = 0; dataset = Lang.load(items.parser, baseUrl, "words.json", "content-$LOCALE.json") if(!dataset) { // English fallback items.background.englishFallback = true dataset = Lang.load(items.parser, baseUrl, "words.json", "content-en.json") } else { items.background.englishFallback = false } lessons = Lang.getAllLessons(dataset) maxLevel = lessons.length initLevel(); } function stop() { } function initLevel() { items.bar.level = currentLevel + 1; var currentLesson = lessons[currentLevel] wordList = Lang.getLessonWords(dataset, currentLesson); -// Core.shuffle(wordList); -// stopped shuffling for testing purposes. + // Core.shuffle(wordList); + // stopped shuffling for testing purposes. maxSubLevel = wordList.length; items.score.numberOfSubLevels = maxSubLevel; items.score.visible = true items.count = 0; + miniGame = 1; items.categoryText.changeCategory(currentLesson.name); subLevelsLeft = []; for(var i in wordList){ subLevelsLeft.push(i) // This is available in all editors. - } + } initSubLevel() } function initSubLevel() { // initialize sublevel items.goodWord = wordList[items.score.currentSubLevel] items.wordImage.changeSource("qrc:/gcompris/data/" + items.goodWord.image) items.wordText.changeText(items.goodWord.translatedTxt) } function nextLevel() { if(maxLevel <= ++currentLevel ) { currentLevel = 0 } items.score.currentSubLevel = 0; + items.imageFrame.visible = true + items.quiz.displayed = false initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = maxLevel - 1 } items.score.currentSubLevel = 0; + items.imageFrame.visible = true + items.quiz.displayed = false initLevel(); } function nextSubLevel() { - items.score.currentSubLevel++; if(items.score.currentSubLevel == items.score.numberOfSubLevels){ - items.score.visible = false - items.bonus.good("smiley"); + // items.score.visible = false + // items.bonus.good("smiley"); //here logic for starting quiz game + items.imageFrame.visible = false + items.quiz.displayed = true + initQuiz() } else{ initSubLevel(); } } function prevSubLevel() { if(--items.score.currentSubLevel < 0) { + //TO DO + //should not allow beyond zero. what to do display an error message + // not changing it for quickly passing through the main activity while testing. items.score.currentSubLevel = maxSubLevel - 1; } initSubLevel() } // Append to the queue of words for the sublevel the error function badWordSelected(wordIndex) { if (subLevelsLeft[0] != wordIndex) subLevelsLeft.unshift(wordIndex); } + +function initQuiz(){ + + subLevelsLeft = []; + for(var i in wordList){ + subLevelsLeft.push(i) // This is available in all editors. + } + + items.score.currentSubLevel = 0 + quizItems.score.currentSubLevel = 0 + initSubLevelQuiz() + + +} + +function initSubLevelQuiz(){ + + if(quizItems.score.currentSubLevel < quizItems.score.numberOfSubLevels) + quizItems.score.currentSubLevel = currentSubLevel + 1; + else + quizItems.score.visible = false + + quizItems.goodWordIndex = subLevelsLeft.pop() + quizItems.goodWord = wordList[quizItems.score.currentSubLevel] + + var selectedWords = [] + var selectedImages = [] + selectedWords.push(quizItems.goodWord.translatedTxt) + selectedImages.push("qrc:/gcompris/data/"+ quizItems.goodWord.image) + + for (var i = 0; i < wordList.length; i++) { + if(wordList[i].translatedTxt !== selectedWords[0]){ + selectedWords.push(wordList[i].translatedTxt) + selectedImages.push("qrc:/gcompris/data/"+ wordList[i].image) + } + if(selectedWords.length > 4) + break + } + + // Push the result in the model + quizItems.wordListModel.clear(); + + var y = Math.random(); + shuffle(selectedWords,y); + shuffle(selectedImages,y); + + for (var j = 0; j < selectedWords.length; j++) { + quizItems.wordListModel.append({"word": selectedWords[j], "image": selectedImages[j]}) + } + + quizItems.wordImage.changeSource("qrc:/gcompris/data/" + quizItems.goodWord.image) + + if(miniGame==3){ + quizItems.wordImage.visible = false + quizItems.imageFrame.visible = false + } +} + +function nextSubLevelQuiz(){ + ++quizItems.score.currentSubLevel + if(subLevelsLeft.length === 0) { + + if(miniGame==3){ + items.imageFrame.visible = true + items.quiz.displayed = false + items.bonus.good("smiley") + } + else{ + ++miniGame; + initQuiz() + } + + } else { + initSubLevelQuiz(); + } +} + +//used from core, modified for shuffling the image and words in the same way +function shuffle(o,y) { + for(var j, x, i = o.length; i; + j = Math.floor(y * i), x = o[--i], o[i] = o[j], o[j] = x); + return o; +}