Changeset View
Changeset View
Standalone View
Standalone View
src/activities/ascending_order/Ascending_order.qml
- This file was added.
1 | /* GCompris - ascending_order.qml | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright (C) 2017 Rudra Nil Basu <rudra.nil.basu.1996@gmail.com> | ||||
4 | * | ||||
5 | * Authors: | ||||
6 | * Rudra Nil Basu <rudra.nil.basu.1996@gmail.com> (Qt Quick port) | ||||
7 | * | ||||
8 | * This program is free software; you can redistribute it and/or modify | ||||
9 | * it under the terms of the GNU General Public License as published by | ||||
10 | * the Free Software Foundation; either version 3 of the License, or | ||||
11 | * (at your option) any later version. | ||||
12 | * | ||||
13 | * This program is distributed in the hope that it will be useful, | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | * GNU General Public License for more details. | ||||
17 | * | ||||
18 | * You should have received a copy of the GNU General Public License | ||||
19 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||||
20 | */ | ||||
21 | import QtQuick 2.6 | ||||
22 | import QtQuick.Controls 1.5 | ||||
23 | import GCompris 1.0 | ||||
24 | | ||||
25 | import "../../core" | ||||
26 | import "ascending_order.js" as Activity | ||||
27 | | ||||
28 | ActivityBase { | ||||
29 | id: activity | ||||
30 | | ||||
31 | property string mode: "number" | ||||
32 | | ||||
33 | onStart: focus = true | ||||
34 | onStop: {} | ||||
35 | | ||||
36 | pageComponent: Image { | ||||
37 | id: background | ||||
38 | anchors.fill: parent | ||||
39 | fillMode: Image.PreserveAspectCrop | ||||
40 | source: "resource/background.svg" | ||||
41 | signal start | ||||
42 | signal stop | ||||
43 | | ||||
44 | Component.onCompleted: { | ||||
45 | dialogActivityConfig.getInitialConfiguration() | ||||
46 | activity.start.connect(start) | ||||
47 | activity.stop.connect(stop) | ||||
48 | } | ||||
49 | | ||||
50 | // Add here the QML items you need to access in javascript | ||||
51 | QtObject { | ||||
52 | id: items | ||||
53 | property Item main: activity.main | ||||
54 | property int orderMode: 0 | ||||
55 | readonly property int modeAscending: 0 | ||||
56 | readonly property int modeDescending: 1 | ||||
57 | property alias background: background | ||||
58 | property alias bar: bar | ||||
59 | property alias bonus: bonus | ||||
60 | property alias boxes: boxes | ||||
61 | property alias flow: flow | ||||
62 | property alias hints: hints | ||||
63 | property alias container: container | ||||
64 | property alias instruction: instruction | ||||
65 | property real ratio: ApplicationInfo.ratio | ||||
66 | property alias score: score | ||||
67 | } | ||||
68 | | ||||
69 | onStart: { Activity.start(items, mode) } | ||||
70 | onStop: { Activity.stop() } | ||||
71 | | ||||
72 | ExclusiveGroup { | ||||
73 | id: configOptions | ||||
74 | } | ||||
75 | | ||||
76 | DialogActivityConfig { | ||||
77 | id: dialogActivityConfig | ||||
78 | currentActivity: activity | ||||
79 | content: Component { | ||||
80 | Item { | ||||
81 | //property alias localeBox: localeBox | ||||
82 | height: column.height | ||||
83 | property alias orderChangeConfigAsc: orderChangeConfigAsc | ||||
84 | property alias orderChangeConfigDesc: orderChangeConfigDesc | ||||
85 | | ||||
86 | //property alias availableLangs: langs.languages | ||||
87 | LanguageList { | ||||
88 | id: langs | ||||
89 | } | ||||
90 | | ||||
91 | Column { | ||||
92 | id: column | ||||
93 | spacing: 10 | ||||
94 | width: dialogActivityConfig.width | ||||
95 | height: dialogActivityConfig.height | ||||
96 | | ||||
97 | GCDialogCheckBox { | ||||
98 | id: orderChangeConfigAsc | ||||
99 | width: column.width - 50 | ||||
100 | text: qsTr("Arrange in Ascending Order") | ||||
101 | checked: (items.orderMode === items.modeAscending) ? true : false | ||||
102 | exclusiveGroup: configOptions | ||||
103 | } | ||||
104 | | ||||
105 | GCDialogCheckBox { | ||||
106 | id: orderChangeConfigDesc | ||||
107 | width: column.width - 50 | ||||
108 | text: qsTr("Arrange in Descending Order") | ||||
109 | checked: (items.orderMode === items.modeDescending) ? true : false | ||||
110 | exclusiveGroup: configOptions | ||||
111 | } | ||||
112 | } | ||||
113 | } | ||||
114 | } | ||||
115 | | ||||
116 | onClose: home() | ||||
117 | onLoadData: { | ||||
118 | if(dataToSave && dataToSave["order"]) { | ||||
119 | items.orderMode = (dataToSave["order"] === "0") ? items.modeAscending : items.modeDescending | ||||
120 | } | ||||
121 | } | ||||
122 | onSaveData: { | ||||
123 | var oldOrder = items.orderMode | ||||
124 | items.orderMode = dialogActivityConfig.loader.item.orderChangeConfigAsc.checked ? items.modeAscending : items.modeDescending | ||||
125 | dataToSave["order"] = items.orderMode | ||||
126 | | ||||
127 | // Restart the activity with new information | ||||
128 | if(oldOrder !== items.orderMode) { | ||||
129 | background.stop(); | ||||
130 | background.start(); | ||||
131 | } | ||||
132 | } | ||||
133 | } | ||||
134 | | ||||
135 | GCText { | ||||
136 | id: instruction | ||||
137 | wrapMode: TextEdit.WordWrap | ||||
138 | fontSize: tinySize | ||||
139 | horizontalAlignment: Text.Center | ||||
140 | anchors.horizontalCenter: parent.horizontalCenter | ||||
141 | width: parent.width * 0.9 | ||||
142 | color: 'white' | ||||
143 | Rectangle { | ||||
144 | z: -1 | ||||
145 | opacity: 0.8 | ||||
146 | gradient: Gradient { | ||||
147 | GradientStop { position: 0.0; color: "#000" } | ||||
148 | GradientStop { position: 0.9; color: "#666" } | ||||
149 | GradientStop { position: 1.0; color: "#AAA" } | ||||
150 | } | ||||
151 | radius: 10 | ||||
152 | border.color: 'black' | ||||
153 | border.width: 1 | ||||
154 | anchors.centerIn: parent | ||||
155 | width: parent.width * 1.1 | ||||
156 | height: parent.contentHeight | ||||
157 | } | ||||
158 | } | ||||
159 | | ||||
160 | GCText { | ||||
161 | id: hints | ||||
162 | wrapMode: TextEdit.WordWrap | ||||
163 | fontSize: tinySize | ||||
164 | horizontalAlignment: Text.Center | ||||
165 | anchors.horizontalCenter: parent.horizontalCenter | ||||
166 | anchors.top: parent.top | ||||
167 | anchors.topMargin: instruction.height * 1.25 | ||||
168 | width: parent.width * 0.5 | ||||
169 | color: 'white' | ||||
170 | visible: false | ||||
171 | text: "" | ||||
172 | Rectangle { | ||||
173 | z: -1 | ||||
174 | opacity: 0.8 | ||||
175 | gradient: Gradient { | ||||
176 | GradientStop { position: 0.0; color: "#000" } | ||||
177 | GradientStop { position: 0.9; color: "#666" } | ||||
178 | GradientStop { position: 1.0; color: "#AAA" } | ||||
179 | } | ||||
180 | radius: 10 | ||||
181 | border.color: 'black' | ||||
182 | border.width: 1 | ||||
183 | anchors.centerIn: parent | ||||
184 | width: parent.width * 1.1 | ||||
185 | height: parent.contentHeight | ||||
186 | } | ||||
187 | } | ||||
188 | | ||||
189 | Rectangle { | ||||
190 | id: container | ||||
191 | color: "transparent" | ||||
192 | width: Math.min(parent.width, ((boxes.itemAt(0)).width*boxes.model)+(boxes.model-1)*flow.spacing) | ||||
193 | height: parent.height/2 | ||||
194 | | ||||
195 | anchors { | ||||
196 | horizontalCenter: parent.horizontalCenter | ||||
197 | verticalCenter: parent.verticalCenter | ||||
198 | } | ||||
199 | | ||||
200 | Flow { | ||||
201 | id: flow | ||||
202 | spacing: 10 | ||||
203 | | ||||
204 | /* | ||||
205 | * Count number of active animations in the activity | ||||
206 | * at this current time | ||||
207 | * (No input will be taken at this time) | ||||
208 | */ | ||||
209 | property int onGoingAnimationCount: 0 | ||||
210 | property bool validMousePress | ||||
211 | anchors { | ||||
212 | fill: parent | ||||
213 | } | ||||
214 | Repeater { | ||||
215 | id: boxes | ||||
216 | model: 6 | ||||
217 | Rectangle { | ||||
218 | id: box | ||||
219 | color: "white" | ||||
220 | z: mouseArea.drag.active || mouseArea.pressed ? 2 : 1 | ||||
221 | property string boxValue | ||||
222 | property point beginDragPosition | ||||
223 | | ||||
224 | width: 65 * ApplicationInfo.ratio | ||||
225 | height: 65 * ApplicationInfo.ratio | ||||
226 | radius: 10 | ||||
227 | border{ | ||||
228 | color: "black" | ||||
229 | width: 3 * ApplicationInfo.ratio | ||||
230 | } | ||||
231 | GCText { | ||||
232 | id: numText | ||||
233 | anchors.centerIn: parent | ||||
234 | text: boxValue | ||||
235 | font.pointSize: 20 * ApplicationInfo.ratio | ||||
236 | } | ||||
237 | MouseArea { | ||||
238 | id: mouseArea | ||||
239 | anchors.fill: parent | ||||
240 | drag.target: parent | ||||
241 | enabled: (flow.onGoingAnimationCount == 0 && flow.validMousePress == true) ? true : false | ||||
242 | onPressed: { | ||||
243 | box.beginDragPosition = Qt.point(box.x, box.y) | ||||
244 | } | ||||
245 | onReleased: { | ||||
246 | Activity.placeBlock(box, box.beginDragPosition); | ||||
247 | } | ||||
248 | } | ||||
249 | Behavior on x { | ||||
250 | PropertyAnimation { | ||||
251 | id: animationX | ||||
252 | duration: 500 | ||||
253 | easing.type: Easing.InOutBack | ||||
254 | onRunningChanged: { | ||||
255 | if(animationX.running) { | ||||
256 | flow.onGoingAnimationCount++ | ||||
257 | } else { | ||||
258 | flow.onGoingAnimationCount-- | ||||
259 | } | ||||
260 | } | ||||
261 | } | ||||
262 | } | ||||
263 | Behavior on y { | ||||
264 | PropertyAnimation { | ||||
265 | id: animationY | ||||
266 | duration: 500 | ||||
267 | easing.type: Easing.InOutBack | ||||
268 | onRunningChanged: { | ||||
269 | if(animationY.running) { | ||||
270 | flow.onGoingAnimationCount++ | ||||
271 | } else { | ||||
272 | flow.onGoingAnimationCount-- | ||||
273 | } | ||||
274 | } | ||||
275 | } | ||||
276 | } | ||||
277 | } | ||||
278 | } | ||||
279 | } | ||||
280 | } | ||||
281 | | ||||
282 | DialogHelp { | ||||
283 | id: dialogHelp | ||||
284 | onClose: home() | ||||
285 | } | ||||
286 | | ||||
287 | BarButton { | ||||
288 | id: ok | ||||
289 | source: "qrc:/gcompris/src/core/resource/bar_ok.svg"; | ||||
290 | sourceSize.width: 75 * ApplicationInfo.ratio | ||||
291 | visible: true | ||||
292 | anchors { | ||||
293 | right: parent.right | ||||
294 | bottom: bar.top | ||||
295 | bottomMargin: 10 * ApplicationInfo.ratio | ||||
296 | rightMargin: 10 * ApplicationInfo.ratio | ||||
297 | } | ||||
298 | onClicked: Activity.checkOrder() | ||||
299 | } | ||||
300 | | ||||
301 | Score { | ||||
302 | id: score | ||||
303 | anchors { | ||||
304 | right: parent.right | ||||
305 | top: instruction.bottom | ||||
306 | bottom: undefined | ||||
307 | } | ||||
308 | } | ||||
309 | | ||||
310 | Bar { | ||||
311 | id: bar | ||||
312 | content: BarEnumContent { value: (mode === 'alphabets') ? help | home | level | hint | config : help | home | level | config } | ||||
313 | onHelpClicked: { | ||||
314 | displayDialog(dialogHelp) | ||||
315 | } | ||||
316 | onPreviousLevelClicked: Activity.previousLevel() | ||||
317 | onNextLevelClicked: Activity.nextLevel() | ||||
318 | onHomeClicked: activity.home() | ||||
319 | onHintClicked: hints.visible = !hints.visible | ||||
320 | onConfigClicked: { | ||||
321 | dialogActivityConfig.active = true | ||||
322 | //dialogActivityConfig.setDefaultValues() | ||||
323 | displayDialog(dialogActivityConfig) | ||||
324 | } | ||||
325 | } | ||||
326 | | ||||
327 | Bonus { | ||||
328 | id: bonus | ||||
329 | Component.onCompleted: win.connect(Activity.nextSubLevel) | ||||
330 | } | ||||
331 | } | ||||
332 | | ||||
333 | } |