Warning, /education/gcompris/src/activities/number_sequence/NumberSequence.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - NumberSequence.qml 0002 * 0003 * SPDX-FileCopyrightText: 2014 Emmanuel Charruau <echarruau@gmail.com> 0004 * 0005 * Authors: 0006 * Olivier Ponchaut <opvg@mailoo.org> (GTK+ version) 0007 * Emmanuel Charruau <echarruau@gmail.com> (Qt Quick port) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 import QtQuick 2.12 0012 import GCompris 1.0 0013 import "../../core" 0014 import "." 0015 import "number_sequence.js" as Activity 0016 import "number_sequence_dataset.js" as Dataset 0017 0018 0019 ActivityBase { 0020 id: activity 0021 property string mode: "number_sequence" 0022 property var dataset: Dataset 0023 property real pointImageOpacity: 1.0 0024 property string url: "qrc:/gcompris/src/activities/number_sequence/resource/" 0025 onStart: focus = true 0026 onStop: {} 0027 0028 pageComponent: Image { 0029 id: background 0030 anchors.fill: parent 0031 source: "qrc:/gcompris/src/activities/chess/resource/background-wood.svg" 0032 sourceSize.width: parent.width 0033 sourceSize.height: parent.height 0034 signal start 0035 signal stop 0036 0037 Component.onCompleted: { 0038 dialogActivityConfig.initialize() 0039 activity.start.connect(start) 0040 activity.stop.connect(stop) 0041 } 0042 0043 // Add here the QML items you need to access in javascript 0044 QtObject { 0045 id: items 0046 property Item main: activity.main 0047 property alias background: background 0048 property int currentLevel: activity.currentLevel 0049 property alias bonus: bonus 0050 property GCSfx audioEffects: activity.audioEffects 0051 property GCAudio audioVoices: activity.audioVoices 0052 property alias pointImageRepeater: pointImageRepeater 0053 property alias segmentsRepeater: segmentsRepeater 0054 property alias imageBack: imageBack 0055 property alias imageBack2: imageBack2 0056 property int pointIndexToClick 0057 property int mode: 1 // default is automatic 0058 property bool highlightEnabled: true // make the point to click bigger. Always true in drawletters, drawnumbers and clickanddraw 0059 } 0060 0061 onStart: { Activity.start(items,mode,dataset,url) } 0062 onStop: { Activity.stop() } 0063 0064 Image { 0065 id: imageBack 0066 anchors.top: parent.top 0067 anchors.horizontalCenter: background.horizontalCenter 0068 width: Math.min((background.height - bar.height * 1.5), background.width) 0069 height: imageBack.width 0070 sourceSize.width: imageBack.width 0071 sourceSize.height: imageBack.height 0072 } 0073 0074 Image { 0075 id: imageBack2 0076 anchors.centerIn: imageBack 0077 width: imageBack.width 0078 height: imageBack.height 0079 sourceSize.width: imageBack2.width 0080 sourceSize.height: imageBack2.height 0081 } 0082 0083 Repeater { 0084 id: segmentsRepeater 0085 0086 Rectangle { 0087 id: line 0088 opacity: 0 0089 color: "#373737" 0090 transformOrigin: Item.TopLeft 0091 x: imageBack.x + modelData[0] * imageBack.width / 520 0092 y: modelData[1] * imageBack.height / 520 0093 property double x2: imageBack.x + modelData[2] * imageBack.width / 520 0094 property double y2: modelData[3] * imageBack.height / 520 0095 width: Math.sqrt(Math.pow(x - x2, 2) + Math.pow(y- y2, 2)) 0096 height: 3 * ApplicationInfo.ratio 0097 rotation: (Math.atan((y2 - y)/(x2-x)) * 180 / Math.PI) + (((y2-y) < 0 && (x2-x) < 0) * 180) + (((y2-y) >= 0 && (x2-x) < 0) * 180) 0098 0099 } 0100 } 0101 0102 Item { 0103 id: playArea 0104 anchors.fill: parent 0105 0106 Repeater { 0107 id: pointImageRepeater 0108 0109 Image { 0110 id: pointImage 0111 source: Activity.url + (highlight ? 0112 (pointImageOpacity ? "bluepoint.svg" : "bluepointHighlight.svg") : 0113 markedAsPointInternal ? "blackpoint.svg" : "greenpoint.svg") 0114 0115 sourceSize.height: (items.highlightEnabled && items.pointIndexToClick == index) ? 0116 imageBack2.width * 0.08 : imageBack2.width * 0.04 //to change the size of dots 0117 0118 x: imageBack.x + modelData[0] * imageBack.width / 520 - sourceSize.height/2 0119 y: modelData[1] * imageBack.height / 520 - sourceSize.height/2 0120 z: items.pointIndexToClick == index ? 1000 : index 0121 0122 // only hide last point for clickanddraw and number_sequence 0123 // as the last point is also the first point 0124 visible: (mode=="clickanddraw" || mode=="number_sequence") && 0125 index == pointImageRepeater.count - 1 && 0126 items.pointIndexToClick == 0 ? false : true 0127 0128 function drawSegment() { 0129 Activity.drawSegment(index) 0130 } 0131 property bool highlight: false 0132 // draw a point instead of hiding the clicked node if it is 0133 // the first point of the current line to draw 0134 // (helpful to know where the line starts) 0135 property bool markedAsPointInternal: markedAsPoint && items.pointIndexToClick == index+1 0136 property bool markedAsPoint: false 0137 0138 scale: markedAsPointInternal ? 0.2 : 1 0139 opacity: index >= items.pointIndexToClick || markedAsPointInternal ? 1 : 0 0140 0141 property int xAreaStart: x 0142 property int xAreaEnd: x + width 0143 property int yAreaStart: y 0144 property int yAreaEnd: y + height 0145 0146 GCText { 0147 id: pointNumberText 0148 opacity: pointImageOpacity 0149 text: index + 1 0150 anchors.horizontalCenter: parent.horizontalCenter 0151 anchors.verticalCenter: parent.verticalCenter 0152 fontSize: 11 0153 font.weight: Font.DemiBold 0154 style: Text.Outline 0155 styleColor: "black" 0156 color: "white" 0157 } 0158 } 0159 } 0160 } 0161 0162 MultiPointTouchArea { 0163 anchors.fill: parent 0164 minimumTouchPoints: 1 0165 maximumTouchPoints: 1 0166 z: 100 0167 0168 function checkPoints(touchPoints) { 0169 for(var i in touchPoints) { 0170 var touch = touchPoints[i] 0171 for(var p = 0; p < pointImageRepeater.count; p++) { 0172 var part = pointImageRepeater.itemAt(p) 0173 // Could not make it work with the item.contains() api 0174 if(touch.x > part.xAreaStart && touch.x < part.xAreaEnd && 0175 touch.y > part.yAreaStart && touch.y < part.yAreaEnd) { 0176 part.drawSegment() 0177 } 0178 } 0179 } 0180 } 0181 0182 onPressed: { 0183 checkPoints(touchPoints) 0184 } 0185 onTouchUpdated: { 0186 checkPoints(touchPoints) 0187 } 0188 } 0189 0190 DialogHelp { 0191 id: dialogHelp 0192 onClose: home() 0193 } 0194 0195 DialogChooseLevel { 0196 id: dialogActivityConfig 0197 currentActivity: activity.activityInfo 0198 0199 onClose: home() 0200 0201 onLoadData: { 0202 if(activityData && activityData["mode"]) { 0203 items.mode = activityData["mode"]; 0204 } 0205 // This option exists only for number_sequence 0206 if(activityData && activityData["highlight"]) { 0207 items.highlightEnabled = activityData["highlight"] === "true" 0208 } 0209 } 0210 onStartActivity: { 0211 background.stop() 0212 Activity.initLevel() 0213 } 0214 } 0215 0216 Bar { 0217 id: bar 0218 level: items.currentLevel + 1 0219 content: BarEnumContent { value: help | home | level | activityConfig } 0220 onHelpClicked: { 0221 displayDialog(dialogHelp) 0222 } 0223 onPreviousLevelClicked: Activity.previousLevel() 0224 onNextLevelClicked: Activity.nextLevel() 0225 onHomeClicked: activity.home() 0226 onActivityConfigClicked: { 0227 displayDialog(dialogActivityConfig) 0228 } 0229 } 0230 0231 Bonus { 0232 id: bonus 0233 onWin: if(items.mode == 1) Activity.nextLevel(); 0234 } 0235 } 0236 }