Changeset View
Changeset View
Standalone View
Standalone View
src/activities/analog_electricity/Analog_electricity.qml
- This file was added.
1 | /* GCompris - Analog_Electricity.qml | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright (C) 2019 Deepak Kumar <deepakdk2431@gmail.com> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or modify | ||||
6 | * it under the terms of the GNU General Public License as published by | ||||
7 | * the Free Software Foundation; either version 3 of the License, or | ||||
8 | * (at your option) any later version. | ||||
9 | * | ||||
10 | * This program is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | * GNU General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU General Public License | ||||
16 | * along with this program; if not, see <https://www.gnu.org/licenses/>. | ||||
17 | */ | ||||
18 | import QtQuick 2.6 | ||||
19 | import GCompris 1.0 | ||||
20 | | ||||
21 | import "../../core" | ||||
22 | import "analog_electricity.js" as Activity | ||||
23 | | ||||
24 | ActivityBase { | ||||
25 | id: activity | ||||
26 | | ||||
27 | onStart: focus = true | ||||
28 | onStop: {} | ||||
29 | | ||||
30 | property string mode: "tutorial" | ||||
31 | property bool isTutorialMode: mode == "tutorial" ? true : false | ||||
32 | | ||||
33 | pageComponent: Image { | ||||
34 | id: background | ||||
35 | anchors.fill: parent | ||||
36 | source: Activity.url + "texture02.png" | ||||
37 | fillMode: Image.Tile | ||||
38 | signal start | ||||
39 | signal stop | ||||
40 | | ||||
41 | property bool hori: background.width >= background.height | ||||
42 | | ||||
43 | Component.onCompleted: { | ||||
44 | dialogActivityConfig.getInitialConfiguration() | ||||
45 | activity.start.connect(start) | ||||
46 | activity.stop.connect(stop) | ||||
47 | } | ||||
48 | | ||||
49 | Keys.onPressed: { | ||||
50 | if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && okButton.enabled) { | ||||
51 | Activity.checkAnswer() | ||||
52 | } | ||||
53 | if (event.key === Qt.Key_Plus) { | ||||
54 | Activity.zoomIn() | ||||
55 | } | ||||
56 | if (event.key === Qt.Key_Minus) { | ||||
57 | Activity.zoomOut() | ||||
58 | } | ||||
59 | if (event.key === Qt.Key_Right) { | ||||
60 | playArea.x -= 200; | ||||
61 | } | ||||
62 | if (event.key === Qt.Key_Left) { | ||||
63 | playArea.x += 200 | ||||
64 | } | ||||
65 | if (event.key === Qt.Key_Up) { | ||||
66 | playArea.y += 200 | ||||
67 | } | ||||
68 | if (event.key === Qt.Key_Down) { | ||||
69 | playArea.y -= 200 | ||||
70 | } | ||||
71 | if (playArea.x >= mousePan.drag.maximumX) { | ||||
72 | playArea.x = mousePan.drag.maximumX | ||||
73 | } | ||||
74 | if (playArea.y >= mousePan.drag.maximumY) { | ||||
75 | playArea.y = mousePan.drag.maximumY | ||||
76 | } | ||||
77 | if (playArea.x <= mousePan.drag.minimumX) { | ||||
78 | playArea.x = mousePan.drag.minimumX | ||||
79 | } | ||||
80 | if (playArea.y <= mousePan.drag.minimumY) { | ||||
81 | playArea.y = mousePan.drag.minimumY | ||||
82 | } | ||||
83 | } | ||||
84 | | ||||
85 | onHoriChanged: { | ||||
86 | if (hori == true) { | ||||
87 | playArea.x += items.toolsMargin | ||||
88 | playArea.y -= items.toolsMargin | ||||
89 | } else { | ||||
90 | playArea.x -= items.toolsMargin | ||||
91 | playArea.y += items.toolsMargin | ||||
92 | } | ||||
93 | } | ||||
94 | | ||||
95 | // Add here the QML items you need to access in javascript | ||||
96 | QtObject { | ||||
97 | id: items | ||||
98 | property Item main: activity.main | ||||
99 | property alias playArea: playArea | ||||
100 | property alias mousePan: mousePan | ||||
101 | property alias bar: bar | ||||
102 | property alias bonus: bonus | ||||
103 | property alias availablePieces: availablePieces | ||||
104 | property alias toolTip: toolTip | ||||
105 | property alias infoTxt: infoTxt | ||||
106 | property alias dataset: dataset | ||||
107 | property alias tutorialDataset: tutorialDataset | ||||
108 | property alias infoImage: infoImage | ||||
109 | property bool isTutorialMode: activity.isTutorialMode | ||||
110 | property alias tutorialInstruction: tutorialInstruction | ||||
111 | property real toolsMargin: 90 * ApplicationInfo.ratio | ||||
112 | property real zoomLvl: 0.25 | ||||
113 | } | ||||
114 | | ||||
115 | Loader { | ||||
116 | id: dataset | ||||
117 | asynchronous: false | ||||
118 | } | ||||
119 | | ||||
120 | Dataset { | ||||
121 | id: tutorialDataset | ||||
122 | } | ||||
123 | | ||||
124 | IntroMessage { | ||||
125 | id: tutorialInstruction | ||||
126 | intro: [] | ||||
127 | textContainerWidth: background.hori ? parent.width - inputComponentsContainer.width - items.toolsMargin : 0.9 * background.width | ||||
128 | textContainerHeight: background.hori ? 0.5 * parent.height : parent.height - inputComponentsContainer.height - (bar.height * 2) - items.toolsMargin | ||||
129 | anchors { | ||||
130 | fill: undefined | ||||
131 | top: background.hori ? parent.top : inputComponentsContainer.bottom | ||||
132 | topMargin: 10 | ||||
133 | right: parent.right | ||||
134 | rightMargin: 5 | ||||
135 | left: background.hori ? inputComponentsContainer.right : parent.left | ||||
136 | leftMargin: 5 | ||||
137 | } | ||||
138 | z: 5 | ||||
139 | } | ||||
140 | | ||||
141 | onStart: { Activity.start(items) } | ||||
142 | onStop: { Activity.stop() } | ||||
143 | | ||||
144 | Rectangle { | ||||
145 | id: visibleArea | ||||
146 | color: "#00000000" | ||||
147 | width: background.hori ? background.width - items.toolsMargin - 10 : background.width - 10 | ||||
148 | height: background.hori ? background.height - bar.height - items.toolsMargin - 10 : background.height - bar.height - 10 | ||||
149 | anchors { | ||||
150 | fill: undefined | ||||
151 | top: background.hori ? parent.top : inputComponentsContainer.bottom | ||||
152 | topMargin: 5 | ||||
153 | right: parent.right | ||||
154 | rightMargin: 5 | ||||
155 | left: background.hori ? inputComponentsContainer.right : parent.left | ||||
156 | leftMargin: 5 | ||||
157 | bottom: bar.top | ||||
158 | bottomMargin: 20 | ||||
159 | } | ||||
160 | z: 6 | ||||
161 | | ||||
162 | GCText { | ||||
163 | id: infoTxt | ||||
164 | anchors { | ||||
165 | horizontalCenter: parent.horizontalCenter | ||||
166 | top: parent.top | ||||
167 | topMargin: 2 | ||||
168 | } | ||||
169 | fontSizeMode: Text.Fit | ||||
170 | minimumPixelSize: 10 | ||||
171 | font.pixelSize: 150 | ||||
172 | color: "white" | ||||
173 | horizontalAlignment: Text.AlignHLeft | ||||
174 | width: mediumSize | ||||
175 | height: mediumSize | ||||
176 | wrapMode: TextEdit.WordWrap | ||||
177 | visible: false | ||||
178 | z: 4 | ||||
179 | } | ||||
180 | | ||||
181 | Rectangle { | ||||
182 | id: infoTxtContainer | ||||
183 | anchors.fill: parent | ||||
184 | opacity: 1 | ||||
185 | radius: 10 | ||||
186 | color: "#373737" | ||||
187 | border.width: 2 | ||||
188 | border.color: "#F2F2F2" | ||||
189 | visible: infoTxt.visible | ||||
190 | MouseArea { | ||||
191 | anchors.fill: parent | ||||
192 | onClicked: infoTxt.visible = false | ||||
193 | } | ||||
194 | z: 3 | ||||
195 | } | ||||
196 | | ||||
197 | Image { | ||||
198 | id: infoImage | ||||
199 | property bool imgVisible: false | ||||
200 | height: source == "" ? 0 : parent.height * 0.3 - 10 | ||||
201 | width: source == "" ? 0 : parent.width - 10 | ||||
202 | fillMode: Image.PreserveAspectFit | ||||
203 | visible: infoTxt.visible && imgVisible | ||||
204 | anchors { | ||||
205 | top: infoTxt.bottom | ||||
206 | horizontalCenter: infoTxtContainer.horizontalCenter | ||||
207 | } | ||||
208 | z: 5 | ||||
209 | } | ||||
210 | } | ||||
211 | | ||||
212 | Rectangle { | ||||
213 | id: playArea | ||||
214 | color: "#10000000" | ||||
215 | x: background.hori ? items.toolsMargin : 0 | ||||
216 | y: background.hori ? 0 : items.toolsMargin | ||||
217 | width: background.hori ? | ||||
218 | background.width * 4 - items.toolsMargin : background.width * 4 | ||||
219 | height: background.hori ? | ||||
220 | background.height * 4 - (bar.height * 1.1) : | ||||
221 | background.height * 4 - (bar.height * 1.1) - items.toolsMargin | ||||
222 | | ||||
223 | PinchArea { | ||||
224 | id: pinchZoom | ||||
225 | anchors.fill: parent | ||||
226 | onPinchFinished: { | ||||
227 | if (pinch.scale < 1) { | ||||
228 | Activity.zoomOut() | ||||
229 | } | ||||
230 | if (pinch.scale > 1) { | ||||
231 | Activity.zoomIn() | ||||
232 | } | ||||
233 | } | ||||
234 | MouseArea { | ||||
235 | id: mousePan | ||||
236 | anchors.fill: parent | ||||
237 | scrollGestureEnabled: false //needed for pinchZoom | ||||
238 | drag.target: playArea | ||||
239 | drag.axis: Drag.XandYAxis | ||||
240 | drag.minimumX: - playArea.width * items.zoomLvl | ||||
241 | drag.maximumX: background.hori ? items.toolsMargin : 0 | ||||
242 | drag.minimumY: - playArea.height * items.zoomLvl | ||||
243 | drag.maximumY: background.hori ? 0 : items.toolsMargin | ||||
244 | onClicked: { | ||||
245 | Activity.deselect() | ||||
246 | availablePieces.hideToolbar() | ||||
247 | } | ||||
248 | } | ||||
249 | } | ||||
250 | } | ||||
251 | | ||||
252 | Rectangle { | ||||
253 | id: inputComponentsContainer | ||||
254 | width: background.hori ? | ||||
255 | items.toolsMargin : | ||||
256 | background.width | ||||
257 | height: background.hori ? | ||||
258 | background.height : | ||||
259 | items.toolsMargin | ||||
260 | color: "#4A3823" | ||||
261 | anchors.left: parent.left | ||||
262 | Image { | ||||
263 | anchors.fill: parent | ||||
264 | anchors.rightMargin: background.hori ? 3 * ApplicationInfo.ratio : 0 | ||||
265 | anchors.bottomMargin: background.hori ? 0 : 3 * ApplicationInfo.ratio | ||||
266 | source: Activity.url + "texture01.png" | ||||
267 | fillMode: Image.Tile | ||||
268 | ListWidget { | ||||
269 | id: availablePieces | ||||
270 | hori: background.hori | ||||
271 | } | ||||
272 | } | ||||
273 | z: 10 | ||||
274 | } | ||||
275 | | ||||
276 | Rectangle { | ||||
277 | id: toolTip | ||||
278 | anchors { | ||||
279 | bottom: bar.top | ||||
280 | bottomMargin: 10 | ||||
281 | left: inputComponentsContainer.left | ||||
282 | leftMargin: 5 | ||||
283 | } | ||||
284 | width: toolTipTxt.width + 10 | ||||
285 | height: toolTipTxt.height + 5 | ||||
286 | color: "#373737" | ||||
287 | opacity: 1 | ||||
288 | radius: 10 | ||||
289 | z: 100 | ||||
290 | border.width: 2 | ||||
291 | border.color: "#F2F2F2" | ||||
292 | property alias text: toolTipTxt.text | ||||
293 | Behavior on opacity { NumberAnimation { duration: 120 } } | ||||
294 | | ||||
295 | function show(newText) { | ||||
296 | if(newText) { | ||||
297 | text = newText | ||||
298 | opacity = 1 | ||||
299 | } else { | ||||
300 | opacity = 0 | ||||
301 | } | ||||
302 | } | ||||
303 | | ||||
304 | GCText { | ||||
305 | id: toolTipTxt | ||||
306 | anchors.centerIn: parent | ||||
307 | fontSize: regularSize | ||||
308 | color: "white" | ||||
309 | horizontalAlignment: Text.AlignHCenter | ||||
310 | wrapMode: TextEdit.WordWrap | ||||
311 | } | ||||
312 | } | ||||
313 | | ||||
314 | DialogActivityConfig { | ||||
315 | id: dialogActivityConfig | ||||
316 | currentActivity: activity | ||||
317 | content: Component { | ||||
318 | Item { | ||||
319 | property alias modesComboBox: modesComboBox | ||||
320 | | ||||
321 | property var availableModes: [ | ||||
322 | { "text": qsTr("Tutorial Mode"), "value": "tutorial" }, | ||||
323 | { "text": qsTr("Free Mode"), "value": "free" }, | ||||
324 | ] | ||||
325 | | ||||
326 | Flow { | ||||
327 | id: flow | ||||
328 | spacing: 5 | ||||
329 | width: dialogActivityConfig.width | ||||
330 | GCComboBox { | ||||
331 | id: modesComboBox | ||||
332 | model: availableModes | ||||
333 | background: dialogActivityConfig | ||||
334 | label: qsTr("Select your Mode") | ||||
335 | } | ||||
336 | } | ||||
337 | } | ||||
338 | } | ||||
339 | | ||||
340 | onClose: home(); | ||||
341 | | ||||
342 | onLoadData: { | ||||
343 | if(dataToSave && dataToSave["modes"]) { | ||||
344 | activity.mode = dataToSave["modes"]; | ||||
345 | } | ||||
346 | } | ||||
347 | | ||||
348 | onSaveData: { | ||||
349 | var newMode = dialogActivityConfig.configItem.availableModes[dialogActivityConfig.configItem.modesComboBox.currentIndex].value; | ||||
350 | if (newMode !== activity.mode) { | ||||
351 | activity.mode = newMode; | ||||
352 | dataToSave = {"modes": activity.mode}; | ||||
353 | Activity.reset() | ||||
354 | } | ||||
355 | } | ||||
356 | | ||||
357 | function setDefaultValues() { | ||||
358 | for(var i = 0 ; i < dialogActivityConfig.configItem.availableModes.length; i ++) { | ||||
359 | if(dialogActivityConfig.configItem.availableModes[i].value === activity.mode) { | ||||
360 | dialogActivityConfig.configItem.modesComboBox.currentIndex = i; | ||||
361 | break; | ||||
362 | } | ||||
363 | } | ||||
364 | } | ||||
365 | } | ||||
366 | | ||||
367 | DialogHelp { | ||||
368 | id: dialogHelp | ||||
369 | onClose: home() | ||||
370 | } | ||||
371 | | ||||
372 | BarButton { | ||||
373 | id: okButton | ||||
374 | visible: activity.isTutorialMode | ||||
375 | anchors { | ||||
376 | bottom: bar.top | ||||
377 | right: parent.right | ||||
378 | rightMargin: 10 * ApplicationInfo.ratio | ||||
379 | bottomMargin: height * 0.5 | ||||
380 | } | ||||
381 | source: "qrc:/gcompris/src/core/resource/bar_ok.svg" | ||||
382 | sourceSize.width: 60 * ApplicationInfo.ratio | ||||
383 | enabled: !tutorialInstruction.visible | ||||
384 | onClicked: Activity.checkAnswer() | ||||
385 | } | ||||
386 | | ||||
387 | Bar { | ||||
388 | id: bar | ||||
389 | content: BarEnumContent { value: help | home | ( activity.isTutorialMode ? level : 0) | reload | config} | ||||
390 | onHelpClicked: {displayDialog(dialogHelp)} | ||||
391 | onPreviousLevelClicked: Activity.previousLevel() | ||||
392 | onNextLevelClicked: Activity.nextLevel() | ||||
393 | onHomeClicked: activity.home() | ||||
394 | onReloadClicked: Activity.reset() | ||||
395 | onConfigClicked: { | ||||
396 | dialogActivityConfig.active = true | ||||
397 | dialogActivityConfig.setDefaultValues() | ||||
398 | displayDialog(dialogActivityConfig) | ||||
399 | } | ||||
400 | } | ||||
401 | | ||||
402 | Bonus { | ||||
403 | id: bonus | ||||
404 | Component.onCompleted: win.connect(Activity.nextLevel) | ||||
405 | } | ||||
406 | } | ||||
407 | | ||||
408 | } |