Commit 9611b598 authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

scalesboard, added support for messages

Now we display message instructions for each level
Implemented the scalesboard weight (kilo and gram unit)
parent 8552402a
......@@ -19,6 +19,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
import QtGraphicalEffects 1.0
import "../../core"
import "scalesboard.js" as Activity
......@@ -59,10 +60,14 @@ Rectangle {
masseArea.masseModel.remove(index)
}
function addMasse(img, weight, index, dragEnabled) {
/* weight is the absolute weight
* text is the text being displayed on the masseAreaCenter
*/
function addMasse(img, weight, text, index, dragEnabled) {
masseModel.append( {
img: img,
weight: weight,
text: text,
masseIndex: index,
opacity: 1.0,
dragEnabled: dragEnabled
......@@ -126,6 +131,7 @@ Rectangle {
property int masseIndex: model.masseIndex
property int modelIndex: index
property int weight: model.weight
property string text: model.text
property int masseOriginX
property int masseOriginY
property int originX
......@@ -175,6 +181,7 @@ Rectangle {
}
masseArea.addMasse(parent.img,
parent.weight,
parent.text,
parent.masseIndex,
/* dragEnabled */ true)
if(parent.currentMasseArea != masseAreaCenter) {
......@@ -210,12 +217,30 @@ Rectangle {
}
Text {
id: text
anchors.fill: parent
text: model.weight
font.pointSize: 18
text: model.text.replace(" ", "\n")
color: "white"
fontSizeMode: Text.Fit
minimumPointSize: 10
font.pointSize: 24
font.bold : true
style: Text.Outline
styleColor: "black"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
DropShadow {
anchors.fill: text
cached: true
horizontalOffset: 3
verticalOffset: 3
radius: 8.0
samples: 16
color: "#80000000"
source: text
}
}
}
......
/* GCompris - Message.qml
*
* Copyright (C) 2014 Bruno Coudoin
*
* Authors:
* Bruno Coudoin <bruno.coudoin@gcompris.net> (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 <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
Item {
id: message
property alias text: messageText.text
property bool displayed: messageText.text != "" ? true : false
onDisplayedChanged: console.log(displayed)
Rectangle {
id: messageBg
x: messageText.x - 4
y: messageText.y - 4
width: messageText.width + 8
height: messageText.height + 8
color: "#ddd6e598"
border.color: "black"
border.width: 2
radius: 8
opacity: message.displayed ? 1 : 0
MouseArea {
anchors.fill: parent
onClicked: message.text = ""
}
Behavior on opacity { NumberAnimation { duration: 100 } }
}
Text {
id: messageText
anchors {
top: parent.top
right: parent.right
left: parent.left
}
color: "black"
font.pointSize: 14
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: TextEdit.WordWrap
opacity: message.displayed ? 1 : 0
Behavior on opacity { NumberAnimation { duration: 100 } }
}
}
......@@ -23,33 +23,35 @@
Scalesboard {
dataset: [
{
"masses": [1, 2, 2, 5, 5, 10, 10],
"targets": [3, 4, 6, 7, 8, 9],
"masses": [[1, "1"], [2, "2"], [2, "2"], [5, "5"], [5, "5"], [10, "10"], [10, "10"]],
"targets": [[3, "3"], [4, "4"], [6, "6"], [7, "7"], [8, "8"], [9, "9"]],
"rightDrop": false
},
{
"masses": [1, 2, 2, 5, 5, 10, 10],
"targets": [12, 13, 14, 15, 16],
"masses": [[1, "1"], [2, "2"], [2, "2"], [5, "5"], [5, "5"], [10, "10"], [10, "10"]],
"targets": [[12, "12"], [13, "13"], [14, "14"], [15, "15"], [16, "16"]],
"rightDrop": false
},
{
"masses": [2, 2, 5, 5, 5],
"targets": [8, 11, 13],
"rightDrop": true
"masses": [[2, "2"], [2, "2"], [5, "5"], [5, "5"], [5, "5"]],
"targets": [[8, "8"], [11, "11"], [13, "13"]],
"rightDrop": true,
"message": qsTr("Take care, you can drop weights on both sides of the scale.")
},
{
"masses": [2, 5, 10, 10],
"targets": [3, 8, 13],
"masses": [[2, "2"], [5, "5"], [10, "10"], [10, "10"], [12, "12"]],
"targets": [[3, "3"], [8, "8"], [13, "13"]],
"rightDrop": true
},
{
"masses": [2, 4, 7, 10],
"targets": [3, 5, 8, 9],
"masses": [[2, "2"], [4, "4"], [7, "7"], [10, "10"], [12, "12"]],
"targets": [[3, "3"], [5, "5"], [8, "8"], [9, "9"]],
"rightDrop": true
},
{
"masses": [5, 8, 9, 10, 11, 12],
"targets": [6, 7, 13, 14, 15, 16, 17, 18],
"masses": [[5, "5"], [8, "8"], [9, "9"], [10, "10"], [11, "11"], [12, "12"]],
"targets": [[6, "6"], [7, "7"], [13, "13"], [14, "14"], [15, "15"], [16, "16"],
[17, "17"], [18, "18"]],
"rightDrop": true
}
]
......
......@@ -20,6 +20,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
import GCompris 1.0
import "../../core"
import "scalesboard.js" as Activity
......@@ -55,6 +56,8 @@ ActivityBase {
property alias background: background
property alias bar: bar
property alias bonus: bonus
property int numberOfSubLevels
property int currentSubLevel
property variant dataset: activity.dataset
property alias masseAreaCenter: masseAreaCenter
property alias masseAreaLeft: masseAreaLeft
......@@ -209,6 +212,19 @@ ActivityBase {
dropEnabled: true
}
Message {
id: message
anchors {
top: parent.top
topMargin: 10
right: parent.right
rightMargin: 10
left: parent.left
leftMargin: 10
}
}
DialogHelp {
id: dialogHelp
onClose: home()
......@@ -223,8 +239,19 @@ ActivityBase {
onPreviousLevelClicked: Activity.previousLevel()
onNextLevelClicked: Activity.nextLevel()
onHomeClicked: activity.home()
onLevelChanged: message.text = items.dataset[bar.level - 1].message ? items.dataset[bar.level - 1].message : ""
}
Score {
id: score
numberOfSubLevels: items.numberOfSubLevels
currentSubLevel: items.currentSubLevel
}
Bonus {
id: bonus
Component.onCompleted: win.connect(Activity.nextSubLevel)
......
......@@ -732,7 +732,7 @@
xlink:href="#linearGradient9315"
id="linearGradient4383"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.3788253,0,0,1.0064112,-112.51029,-2.0768244)"
gradientTransform="matrix(1.3854556,0,0,1.1156838,-115.70813,-94.222098)"
x1="987.9989"
y1="803.56128"
x2="987.9989"
......@@ -3860,11 +3860,11 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.59375"
inkscape:cx="139.71228"
inkscape:cy="347.17368"
inkscape:zoom="1.296875"
inkscape:cx="383.33983"
inkscape:cy="328.38041"
inkscape:document-units="px"
inkscape:current-layer="layer1"
inkscape:current-layer="g7685"
showgrid="false"
inkscape:showpageshadow="true"
inkscape:window-width="1366"
......@@ -3898,43 +3898,9 @@
id="path4066"
d="m 29.089738,417.04758 1307.740362,0 0,133.18607 -1307.740362,0 z"
style="fill:url(#linearGradient4380);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
inkscape:connector-curvature="0"
id="rect3835"
d="m 21.996569,234.76768 0,612.32641 14.335508,0 0,-161.2978 1300.629423,0 0,161.26754 14.3354,0 0,-612.29615 -14.3354,0 0,179.66699 -1300.629423,0 0,-179.66699 -14.335508,0 z m 14.335508,189.56275 1300.629423,0 0,120.83717 -1300.629423,0 0,-120.83717 z m 0,130.73293 1300.629423,0 0,120.83717 -1300.629423,0 0,-120.83717 z"
style="fill:#faffef;fill-opacity:1;fill-rule:nonzero;stroke:#dde9af;stroke-width:0.78774089;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<g
transform="matrix(1.401708,0,0,0.96839207,-114.70116,2.6383588)"
id="g16300"
style="stroke:#000000;stroke-width:2.79278708;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none">
<path
style="fill:url(#linearGradient16312);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:2.79278708;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 106.6496,188.96973 925.3322,0 c 8.3944,0 15.1523,6.75792 15.1523,15.15229 l 0,32.70822 c 0,8.39437 -6.7579,15.15229 -15.1523,15.15229 l -925.3322,0 c -8.394358,0 -15.152286,-6.75792 -15.152286,-15.15229 l 0,-32.70822 c 0,-8.39437 6.757928,-15.15229 15.152286,-15.15229 z"
id="rect3831"
inkscape:connector-curvature="0"
sodipodi:nodetypes="sssssssss" />
<path
style="opacity:0.2;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:2.79278708;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 224.21074,188.96973 0,63 78.78125,0 0,-63 z m 86.875,0 0,63 18.1875,0 0,-63 z m 21.21875,0 0,63 18.18749,0 0,-63 z"
id="path3916"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccccccccc" />
<path
style="fill:url(#linearGradient16314);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:2.79278708;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 85.775014,234.47056 967.081386,0 0,18.52216 -967.081385,0 z"
id="rect3862"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path3944"
d="m 85.77902,251.99272 0,1 967.07338,0 0,-1 z"
style="fill:#7c916f;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:2.79278708;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
</g>
<path
style="fill:url(#linearGradient4383);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:3.25381017;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 29.633586,247.07036 1307.196614,0 0,599.51966 -1307.196614,0 z"
d="m 27.119257,181.97662 1313.482443,0 0,664.61344 -1313.482443,0 z"
id="path4070"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
......
......@@ -26,7 +26,6 @@
var url = "qrc:/gcompris/src/activities/scalesboard/resource/"
var currentLevel = 0
var currentSubLevel = 0
var numberOfLevel
var items
var currentTargets = []
......@@ -44,13 +43,15 @@ function stop() {
function initLevel() {
items.bar.level = currentLevel + 1
currentSubLevel = 0
currentTargets = Core.shuffle(items.dataset[currentLevel].targets)
items.currentSubLevel = 1
items.numberOfSubLevels = currentTargets.length
displayLevel()
}
function displayLevel()
{
initCompleted = false
items.masseAreaLeft.init()
items.masseAreaRight.init()
......@@ -58,12 +59,14 @@ function displayLevel()
var data = items.dataset[currentLevel]
for(var i=0; i < data.masses.length; i++)
items.masseAreaCenter.addMasse("masse" + (i % 5 + 1) + ".svg",
data.masses[i],
data.masses[i][0],
data.masses[i][1],
i,
/* dragEnabled */ true)
items.masseAreaRight.addMasse("masse" + 1 + ".svg",
currentTargets[currentSubLevel],
items.masseAreaRight.addMasse("gift.svg",
currentTargets[items.currentSubLevel - 1][0],
currentTargets[items.currentSubLevel - 1][1],
0,
/* dragEnabled */ false)
......@@ -71,10 +74,10 @@ function displayLevel()
}
function nextSubLevel() {
if(currentTargets.length <= ++currentSubLevel ) {
displayLevel()
if(items.numberOfSubLevels < ++items.currentSubLevel ) {
nextLevel();
}
nextLevel();
displayLevel()
}
function nextLevel() {
......
/* GCompris - scalesboard_weight.qml
/* GCompris - Scalesboard.qml
*
* Copyright (C) 2014 Bruno Coudoin
*
* Authors:
* Wolfram Sang <wolfram@iswi.org> (GTK+ version)
* miguel DE IZARRA <miguel2i@free.fr> (GTK+ version)
* Bruno Coudoin <bruno.coudoin@gcompris.net> (Qt Quick port)
*
* This program is free software; you can redistribute it and/or modify
......@@ -19,12 +19,69 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
import "../../core"
import "../scalesboard"
Scalesboard {
id: activity
function g(value) {
/* g == gram */
return qsTr("%1 g").arg(value)
}
function kg(value) {
/* kg == kilogram */
return qsTr("%1 kg").arg(value)
}
dataset: [
{
"masses": [[1, kg(1)], [2, kg(2)], [2, kg(2)], [5, kg(5)],
[5, kg(5)], [1, kg(10)], [1, kg(10)]],
"targets": [[3, kg(3)], [4, kg(4)], [6, kg(6)], [7, kg(7)], [8, kg(8)], [9, kg(9)]],
"rightDrop": false,
"message": qsTr('The "kg" symbol at the end of a number means kilogram.') + " " +
qsTr('The kilogram is a unit of mass, a property which corresponds to the ' +
'common perception of how "heavy” an object is.')
},
{
"masses": [[100, g(100)], [200, g(200)], [200, g(200)], [500, g(500)],
[500, g(500)], [1000, g(1000)], [1000, g(1000)]],
"targets": [[300, g(300)], [400, g(400)], [600, g(600)], [700, g(700)],
[800, g(800)], [900, g(900)]],
"rightDrop": false,
"message": qsTr('The "g" symbol at the end of a number means gram. One kilogram equals 1000 grams')
},
{
"masses": [[2, kg(2)], [2, kg(2)], [5, kg(5)], [5, kg(5)], [5, kg(5)]],
"targets": [[8, kg(8)], [11, kg(11)], [13, kg(13)]],
"rightDrop": true,
"message": qsTr("Take care, you can drop weights on both sides of the scale.")
},
{
"masses": [[100, g(100)], [200, g(200)], [200, g(200)], [500, g(500)],
[500, g(500)], [1000, kg(1)], [1000, kg(1)]],
"targets": [[1200, kg(1.2)], [1300, kg(1.3)], [1400, kg(1.4)],
[1500, kg(1.5)], [1600, kg(1.6)]],
"rightDrop": false,
"message": qsTr("Remember, one kilo ('kg') equals 1000 grams ('g').")
},
{
"masses": [[200, g(200)], [500, g(500)], [1000, kg(1)], [1000, kg(1)], [1200, kg(1.2)]],
"targets": [[300, g(300)], [800, g(800)], [1300, kg(1.3)]],
"rightDrop": true
},
{
"masses": [[200, g(200)], [400, g(400)], [700, g(700)], [1000, kg(1)]],
"targets": [[300, g(300)], [500, g(500)], [800, g(800)], [900, g(900)]],
"rightDrop": true
},
{
"masses": [[500, g(500)], [800, g(800)], [900, g(900)], [1000, kg(1)],
[1100, kg(1.1)], [1200, kg(1.2)]],
"targets": [[600, g(600)], [700, g(700)], [1300, kg(1.3)], [1400, kg(1.4)],
[1500, kg(1.5)], [1600, kg(1.6)], [1700, kg(1.7)], [1800, kg(1.8)]],
"rightDrop": true
}
]
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment