diff --git a/src/activities/computer/Computer.qml b/src/activities/computer/Computer.qml index 6db7a643a..ac4d85c33 100644 --- a/src/activities/computer/Computer.qml +++ b/src/activities/computer/Computer.qml @@ -1,389 +1,394 @@ /* GCompris - computer.qml * * Copyright (C) 2015 Sagar Chand Agarwal * * Authors: * * Sagar Chand Agarwal (Qt Quick) * * 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 "../../core" import "computer.js" as Activity ActivityBase { id: activity onStart: focus = true onStop: {} pageComponent: Image { id: background anchors.fill: parent source: Activity.url + "images/background.svg" sourceSize.width: parent.width sourceSize.height: parent.height 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 img: img property alias name: name property alias info: intro_text property alias answers: answers property alias proceed: proceed } // show of current part of topic Rectangle { id: intro_textbg x: intro_text.x - 4 y: intro_text.y - 4 width: intro_text.width + 4 height: intro_text.height + 4 color: "#d8ffffff" border.color: "#2a2a2a" border.width: 2 radius: 8 } GCText { id: intro_text font.weight: Font.DemiBold horizontalAlignment: Text.AlignHCenter anchors { top: parent.top topMargin: 10 * ApplicationInfo.ratio right: parent.right rightMargin: 5 * ApplicationInfo.ratio left: parent.left leftMargin: 5 * ApplicationInfo.ratio } width: parent.width wrapMode: Text.WordWrap fontSize: smallSize * 0.5 text: qsTr("Click on the box below.") } // starts with openBox Image { id: closebox source: Activity.url + "images/closebox.svg" sourceSize.width: parent.width*0.15 anchors { centerIn: parent } visible: true NumberAnimation on scale{ id: box_scale running: true loops: Animation.Infinite from: 1 to: 1.5 duration: 2000 } MouseArea { anchors.fill: closebox id: closebox_area onClicked: { openbox.visible = true box_scale.running = false closebox.visible= false show.start() } } } Image { id: openbox source: Activity.url + "images/openbox.svg" sourceSize.width: parent.width*0.15 anchors { centerIn: parent } visible: false } // timer activated on click on close box Timer { id: show interval: 500 repeat: false running: false onTriggered: { intro_text.text = qsTr("Parts of the Computer") holder.visible = true openbox.visible = false show.stop() previous.visible = true next.visible = true intro_text.visible = true Activity.next() holder.visible = true } } // Images are shown here Rectangle { id: holder visible: false width: Math.max(img.width * 1.1, img.height * 1.1) height: name_text.y + name_text.height anchors { horizontalCenter: parent.horizontalCenter top: intro_text.bottom } color: "black" radius: 10 border.width: 2 border.color: "black" gradient: Gradient { GradientStop { position: 0.0; color: "#80FFFFFF" } GradientStop { position: 0.9; color: "#80EEEEEE" } GradientStop { position: 1.0; color: "#80AAAAAA" } } Item { id: spacer height: 20 } Image { id: img anchors.horizontalCenter: holder.horizontalCenter anchors.top: spacer.bottom width: Math.min((background.width - 120 * ApplicationInfo.ratio) * 0.7, (background.height - 100 * ApplicationInfo.ratio) * 0.7) height: width } Rectangle { id: name_text width: holder.width height: name.height * 1.5 anchors.horizontalCenter: holder.horizontalCenter anchors.margins: 20 anchors.top: img.bottom radius: 10 border.width: 2 border.color: "black" gradient: Gradient { GradientStop { position: 0.0; color: "#000" } GradientStop { position: 0.9; color: "#666" } GradientStop { position: 1.0; color: "#AAA" } } } GCText { id: name anchors { horizontalCenter: name_text.horizontalCenter verticalCenter: name_text.verticalCenter } style: Text.Outline; styleColor: "black" color: "white" fontSize: smallSize visible: true } } // Load the previous part Image { visible: false id: previous anchors.right: holder.left anchors.rightMargin: 20 * ApplicationInfo.ratio anchors.verticalCenter: holder.verticalCenter source: "qrc:/gcompris/src/core/resource/bar_previous.svg" sourceSize.height: 80 * ApplicationInfo.ratio Behavior on scale { PropertyAnimation { duration: 100} } MouseArea { anchors.fill: parent hoverEnabled: true onEntered: previous.scale = 1.1 onExited: previous.scale = 1 onClicked: Activity.previous() } } // Load the next part Keys.onRightPressed: Activity.next() Keys.onLeftPressed: Activity.previous() Image { visible: false id: next anchors.left: holder.right anchors.leftMargin: 20 * ApplicationInfo.ratio anchors.verticalCenter: holder.verticalCenter source: "qrc:/gcompris/src/core/resource/bar_next.svg" sourceSize.height: 80 * ApplicationInfo.ratio Behavior on scale { PropertyAnimation { duration: 100} } MouseArea { anchors.fill: parent hoverEnabled: true onEntered: next.scale = 1.1 onExited: next.scale = 1 onClicked: Activity.next() } } //Proceed to nextpart Rectangle { id: proceed visible: false anchors { right: parent.right bottom: parent.bottom bottomMargin: parent.height * 0.05 rightMargin: parent.width * 0.05 } border.color: "black" radius: 4 smooth: true border.width: 0 width: proceed_text.width * 1.1 * ApplicationInfo.ratio height: proceed_text.height * 1.1 * ApplicationInfo.ratio color: "#AAFFFFFF" GCText { id: proceed_text anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter font.bold: true fontSize: smallSize text: qsTr("Visual
Demo") Behavior on scale { PropertyAnimation { duration: 100} } } MouseArea { anchors.fill: proceed hoverEnabled: true onEntered: proceed_text.scale = 1.1 onExited: proceed_text.scale = 1 onClicked: { if(proceed_text.text == qsTr("Visual
Demo")) { reset() proceed_text.text = qsTr("Quiz") page.source = Activity.url + "levels/Level1.qml" proceed.visible = false } else if(proceed_text.text == qsTr("Quiz")) { reset() Activity.nextQuestion() - holder.visible = true proceed.visible = false + intro_textbg.visible = true + intro_text.visible = true } } } } function reset () { openbox.visible = false closebox.visible = false holder.visible = false next.visible = false previous.visible = false intro_textbg.visible = false intro_text.visible = false page.source = "" } // loaders for sublevels Loader { id: page anchors.fill: parent source: "" } //quiz - Column + Grid { id: buttonHolder property bool buttonHolderMouseArea : true - spacing: 10 * ApplicationInfo.ratio - x: holder.x - width - 10 * ApplicationInfo.ratio - y: 30 + spacing: 20 * ApplicationInfo.ratio + anchors.centerIn: parent add: Transition { NumberAnimation { properties: "y"; from: 10; duration: 500 } } + rows: 2 + columns: 2 Repeater { id: answers - AnswerButton { - width: 120 * ApplicationInfo.ratio - height: 80 * ApplicationInfo.ratio - textLabel: modelData - onPressed: { - if(modelData === Activity.getCorrectAnswer()) Activity.showAnswer() + Image { + width: img.height / 2 + height: width + source: modelData + MouseArea { + anchors.fill: parent + onPressed: { + if(modelData === Activity.getCorrectAnswer()) Activity.showAnswer() + } } } } } onStart: { Activity.start(items) } onStop: { Activity.stop() } 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() } Bonus { id: bonus } } } diff --git a/src/activities/computer/computer.js b/src/activities/computer/computer.js index e3f0cebc7..3810a2414 100644 --- a/src/activities/computer/computer.js +++ b/src/activities/computer/computer.js @@ -1,160 +1,163 @@ /* GCompris - computer.js * * Copyright (C) 2015 Sagar Chand Agarwal * * Authors: * * Sagar Chand Agarwal (Qt Quick) * * 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 //for Applicationdataset .import "qrc:/gcompris/src/core/core.js" as Core var url = "qrc:/gcompris/src/activities/computer/resource/" // number of levels var dataset = [ [ { desc : "A monitor or a display is an electronic visual display for computers. The monitor comprises the display device, circuitry and an enclosure.", name : qsTr("Monitor"), - img : url + "images/monitor_off.svg" + img : url + "images/monitor_off.svg" , + ques : "Which device is used to show output of the keyboard ?" }, { desc : " central processing unit (CPU) is the electronic circuitry within a computer that carries out the instructions of a computer program by performing the basic arithmetic, logical, control and input/output (I/O) operations specified by the instructions. ", name : qsTr("CPU"), - img : url + "images/cpu.svg" + ques : "It is known as the Brain of the Computer. Click on the image." , + img : url + "images/cpu.svg" , }, { desc : " the keyboard is used as a text entry interface to type text and numbers into a word processor, text editor or other programs.A keyboard is also used to give commands to the operating system of a computer", name : qsTr("Keyboard"), - img : url + "images/keyboard.svg" + img : url + "images/keyboard.svg", + ques : "Which device has alphabets, numeric and special keys on it ? " }, { desc : "In computing, a mouse is a pointing device that detects two-dimensional motion relative to a surface. This motion is typically translated into the motion of a pointer on a display, which allows for fine control of a graphical user interface.", name : qsTr("Mouse"), - img : url + "images/mouse.svg" + img : url + "images/mouse.svg" , + ques : "It is used as a pointing device. Can you guess it? " } ] ] var currentLevel = 0 var numberOfLevel = 0 var items var count = 0 var level = 0 var quiz var index = 0 function start(items_,quiz_) { items = items_ currentLevel = 0 initLevel() count = 0 level = 0 quiz = quiz_ index = 0 } function stop() { } function initLevel() { items.bar.level = currentLevel + 1 } function previous() { display() if(count == 0) count = dataset[level].length - 1 else count-- } function next() { display() if( count == dataset[level].length - 1) { items.proceed.visible = true count = 0 } else { count++ } } function nextLevel() { if(numberOfLevel <= ++currentLevel ) { currentLevel = 0 } initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); } function display() { items.img.source = dataset[level][count].img items.name.text = dataset[level][count].name items.info.text = dataset[level][count].desc } function nextQuestion() { items.answers.model = [] var answerModel = new Array() for (var i = 0 ;i < dataset[level].length; i++) { - answerModel.push(dataset[level][i].name) + answerModel.push(dataset[level][i].img) } - items.img.source = dataset[level][index].img + items.info.text = dataset[level][index].ques items.answers.model = answerModel } function getCorrectAnswer() { - return dataset[level][index].name + return dataset[level][index].img } function showAnswer() { console.log(dataset[level][index].name) - items.name.visible = true win() } function win () { items.bonus.good("flower") items.name.visible = false - if(index < dataset[level].length) + if(index < dataset[level].length - 1) { index++ nextQuestion() } else { nextLevel() } } function sublevel() { items.proceed.visible = true }