• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kanagram

  • sources
  • kde-4.12
  • kdeedu
  • kanagram
  • src
  • harmattan
harmattan/GamePage.qml
Go to the documentation of this file.
1 /******************************************************************************
2  * This file is part of the Kanagram project
3  * Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 import QtQuick 1.1
21 import com.nokia.meego 1.0
22 import com.nokia.extras 1.0
23 
24 import "array.js" as MyArray
25 
26 Page {
27 
28  orientationLock: PageOrientation.LockLandscape;
29 
30  property variant anagram: kanagramEngineHelper.createNextAnagram();
31  property int anagramStatus: anagramStatusEnumeration.init;
32  property int currentOriginalWordIndex: 0;
33  property string originalWordLetterButtonBackground: "image://theme/meegotouch-button-inverted-background";
34  property int countDownTimerValue: kanagramEngineHelper.resolveTime;
35  property bool initialized: false;
36 
37  QtObject { // status enum hackery :)
38  id: anagramStatusEnumeration;
39  property int init: 1;
40  property int active: 2;
41  property int resolved: 3;
42  }
43 
44  onStatusChanged: {
45  if (status == PageStatus.Active && anagramStatus != anagramStatusEnumeration.resolved) {
46  if (rootWindow.languageSelectionChanged == true) {
47 
48  if (kanagramEngineHelper.useSounds) {
49  chalkSoundEffect.play();
50  }
51 
52  categorySelectionDialog.model = kanagramGame.vocabularyList();
53 
54  // Sanitize the selected index, if the translation is not
55  // available for the previously selected index in a different
56  // language.
57 
58  if (categorySelectionDialog.selectedIndex >= categorySelectionDialog.model.length) {
59  categorySelectionDialog.selectedIndex = 0;
60  }
61 
62  kanagramGame.setCurrentCategory(categorySelectionDialog.selectedIndex);
63  kanagramEngineHelper.saveSettings();
64 
65  kanagramGame.useVocabulary(categorySelectionDialog.selectedIndex);
66  nextAnagram();
67  rootWindow.languageSelectionChanged = false;
68  }
69 
70  secondTimer.repeat = true;
71  secondTimer.restart();
72  }
73  }
74 
75  Connections {
76  target: platformWindow;
77 
78  onActiveChanged: {
79  if (platformWindow.active && status == PageStatus.Active
80  && anagramStatus != anagramStatusEnumeration.resolved) {
81  secondTimer.repeat = true;
82  secondTimer.restart();
83  } else {
84  anagramHintInfoBanner.hide();
85 
86  secondTimer.repeat = false;
87  secondTimer.stop();
88  }
89  }
90  }
91 
92  Component.onCompleted: {
93  categorySelectionDialog.selectedIndex = kanagramGame.currentCategory();
94  }
95 
96 
97  function pushPage(file) {
98  var component = Qt.createComponent(file)
99  if (component.status == Component.Ready)
100  pageStack.push(component);
101  else
102  console.log("Error loading component:", component.errorString());
103  }
104 
105  function resolveAnagram() {
106  originalWordLetterRepeater.model = kanagramEngineHelper.anagramOriginalWord();
107  currentOriginalWordIndex = originalWordLetterRepeater.model.length;
108  anagramStatus = anagramStatusEnumeration.resolved;
109  anagramHintInfoBanner.hide();
110  }
111 
112  function nextAnagram() {
113  anagramHintInfoBanner.hide();
114  anagramStatus = anagramStatusEnumeration.init;
115  anagram = kanagramEngineHelper.createNextAnagram();
116  anagramLetterRepeater.model = anagram;
117  originalWordLetterRepeater.model = anagram;
118  currentOriginalWordIndex = 0;
119  countDownTimerValue = kanagramEngineHelper.resolveTime;
120  MyArray.sourceDestinationLetterIndexHash = [];
121  }
122 
123  // Create an info banner with icon
124  InfoBanner {
125  id: anagramHintInfoBanner;
126  text: i18n("No hint available");
127  iconSource: "dialog-information.png";
128  }
129 
130  // These tools are available for the main page by assigning the
131  // id to the main page's tools property
132  ToolBarLayout {
133  id: mainPageTools;
134  visible: false;
135 
136  ToolIcon {
137  iconSource: "help-hint.png";
138 
139  onClicked: {
140  anagramHintInfoBanner.text = kanagramGame.hint();
141  anagramHintInfoBanner.timerShowTime = kanagramEngineHelper.hintHideTime * 1000;
142 
143  // Display the info banner
144  anagramHintInfoBanner.show();
145  }
146  }
147 
148  ToolIcon {
149  iconSource: "games-solve.png";
150 
151  onClicked: {
152  if (kanagramEngineHelper.useSounds) {
153  chalkSoundEffect.play();
154  }
155 
156  resolveAnagram();
157 
158  secondTimer.repeat = false;
159  secondTimer.stop();
160  }
161  }
162 
163  ToolButton {
164  text: categorySelectionDialog.model[categorySelectionDialog.selectedIndex];
165 
166  anchors {
167  centerIn: parent;
168  }
169 
170  onClicked: {
171  categorySelectionDialog.open();
172  }
173  }
174 
175  ToolIcon {
176  iconSource: "go-next.png";
177 
178  onClicked: {
179  if (kanagramEngineHelper.useSounds) {
180  chalkSoundEffect.play();
181  }
182 
183  nextAnagram();
184  secondTimer.repeat = true;
185  secondTimer.restart();
186  }
187  }
188 
189  ToolIcon {
190  iconSource: "settings.png";
191 
192  onClicked: {
193  anagramHintInfoBanner.hide();
194  pageStack.push(mainSettingsPage);
195 
196  secondTimer.repeat = false;
197  secondTimer.stop();
198  }
199  }
200  }
201 
202  tools: mainPageTools;
203 
204  // Create a selection dialog with the vocabulary titles to choose from.
205  MySelectionDialog {
206  id: categorySelectionDialog;
207  titleText: "Choose an anagram category"
208 
209  model: kanagramGame.vocabularyList();
210 
211  onSelectedIndexChanged: {
212 
213  if (kanagramEngineHelper.useSounds) {
214  initialized == true ? chalkSoundEffect.play() : initialized = true;
215  }
216 
217  kanagramGame.setCurrentCategory(selectedIndex);
218  kanagramEngineHelper.saveSettings();
219  kanagramGame.useVocabulary(selectedIndex);
220  nextAnagram();
221  }
222  }
223 
224  Timer {
225  id: secondTimer;
226  interval: 1000;
227  repeat: true;
228  running: false;
229  triggeredOnStart: false;
230 
231  onTriggered: {
232  if (kanagramEngineHelper.resolveTime != 0 && --countDownTimerValue == 0) {
233  stop();
234  anagramResultTimer.start();
235  originalWordLetterButtonBackground =
236  "image://theme/meegotouch-button-negative-background";
237 
238  resolveAnagram();
239 
240  if (kanagramEngineHelper.useSounds) {
241  wrongSoundEffect.play();
242  }
243  }
244  }
245  }
246 
247  Timer {
248  id: anagramResultTimer;
249  interval: 1000;
250  repeat: false;
251  running: false;
252  triggeredOnStart: false;
253 
254  onTriggered: {
255  originalWordLetterButtonBackground =
256  "image://theme/meegotouch-button-inverted-background";
257  nextAnagram();
258 
259  secondTimer.repeat = true;
260  secondTimer.start();
261  }
262  }
263 
264  Row {
265  spacing: 0;
266 
267  anchors {
268  right: parent.right;
269  top: parent.top;
270  topMargin: 15;
271  }
272 
273  LetterElement {
274  letterText: Math.floor(countDownTimerValue / 60 / 10);
275  visible: kanagramEngineHelper.resolveTime == 0 ? false : true;
276  }
277 
278  LetterElement {
279  letterText: Math.floor(countDownTimerValue / 60 % 10);
280  visible: kanagramEngineHelper.resolveTime == 0 ? false : true;
281  }
282 
283  LetterElement {
284  letterText: ":";
285  visible: kanagramEngineHelper.resolveTime == 0 ? false : true;
286  }
287 
288  LetterElement {
289  letterText: Math.floor(countDownTimerValue % 60 / 10);
290  visible: kanagramEngineHelper.resolveTime == 0 ? false : true;
291  }
292 
293  LetterElement {
294  letterText: Math.floor(countDownTimerValue % 60 % 10);
295  visible: kanagramEngineHelper.resolveTime == 0 ? false : true;
296  }
297 
298  ToolIcon {
299  iconSource: "timer-pause.png";
300 
301  onClicked: {
302  anagramHintInfoBanner.hide();
303 
304  pageStack.pop();
305 
306  secondTimer.repeat = false;
307  secondTimer.stop();
308 
309  }
310  }
311  }
312 
313  Column {
314  anchors {
315  centerIn: parent;
316  verticalCenterOffset: 15;
317  }
318 
319  spacing: 30;
320 
321  Row {
322  id: originalWordRow;
323  anchors {
324  horizontalCenter: parent.horizontalCenter;
325  }
326 
327  spacing: 8;
328  Repeater {
329  id: originalWordLetterRepeater;
330  model: anagram;
331  Button {
332  id: originalWordLetterId;
333  text: anagramStatus == anagramStatusEnumeration.init ? "" : modelData;
334 
335  platformStyle: ButtonStyle {
336  background: originalWordLetterButtonBackground;
337  fontFamily: "Arial";
338  fontPixelSize: 40;
339  fontCapitalization: Font.AllUppercase;
340  fontWeight: Font.Bold;
341  horizontalAlignment: Text.AlignHCenter;
342  textColor: "white";
343  pressedTextColor: "pink";
344  disabledTextColor: "gray";
345  checkedTextColor: "blue";
346  buttonWidth: 45;
347  buttonHeight: 60;
348  }
349 
350  onClicked: {
351  if (index + 1 == currentOriginalWordIndex && currentOriginalWordIndex != 0
352  && anagramStatus != anagramStatusEnumeration.resolved) {
353  if (kanagramEngineHelper.useSounds) {
354  anagramLetterPressSoundEffect.play();
355  }
356 
357  var tmpAnagramLetterRepeaterModel = anagramLetterRepeater.model;
358  tmpAnagramLetterRepeaterModel[MyArray.sourceDestinationLetterIndexHash[index]] = originalWordLetterId.text;
359  anagramLetterRepeater.model = tmpAnagramLetterRepeaterModel;
360 
361  MyArray.sourceDestinationLetterIndexHash.pop();
362 
363  originalWordLetterRepeater.model = kanagramEngineHelper.removeInCurrentOriginalWord(index);
364  --currentOriginalWordIndex;
365  }
366  }
367  }
368  }
369  }
370 
371  Image {
372  id: chalkSeparator;
373  width: parent.width;
374  height: 5;
375  fillMode: Image.PreserveAspectFit;
376  source: "chalk-separator.png";
377  }
378 
379  Row {
380  id: anagramRow;
381  anchors {
382  horizontalCenter: parent.horizontalCenter;
383  }
384 
385  spacing: 8;
386  Repeater {
387  id: anagramLetterRepeater;
388  model: anagram;
389  Button {
390  id: anagramLetterId;
391  text: anagramStatus == anagramStatusEnumeration.resolved ? "" : modelData;
392 
393  platformStyle: ButtonStyle {
394  background: "image://theme/meegotouch-button-inverted-background";
395  fontFamily: "Arial";
396  fontPixelSize: 40;
397  fontCapitalization: Font.AllUppercase;
398  fontWeight: Font.Bold;
399  horizontalAlignment: Text.AlignHCenter;
400  textColor: "white";
401  pressedTextColor: "pink";
402  disabledTextColor: "gray";
403  checkedTextColor: "blue";
404  buttonWidth: 45;
405  buttonHeight: 60;
406  }
407 
408  onClicked: {
409  if (anagramStatus != anagramStatusEnumeration.resolved)
410  {
411  if (anagramLetterId.text != "")
412  {
413  if (kanagramEngineHelper.useSounds) {
414  anagramLetterPressSoundEffect.play();
415  }
416 
417  anagramStatus = anagramStatusEnumeration.active;
418 
419  originalWordLetterRepeater.model =
420  kanagramEngineHelper.insertInCurrentOriginalWord(currentOriginalWordIndex, anagramLetterId.text);
421 
422  ++currentOriginalWordIndex;
423 
424  var tmpAnagramLetterRepeaterModel = anagramLetterRepeater.model;
425  tmpAnagramLetterRepeaterModel[[index]] = "";
426  anagramLetterRepeater.model = tmpAnagramLetterRepeaterModel;
427 
428  MyArray.sourceDestinationLetterIndexHash.push(index);
429  }
430 
431  if (currentOriginalWordIndex == originalWordLetterRepeater.model.length)
432  {
433  anagramResultTimer.start();
434  anagramStatus = anagramStatusEnumeration.resolved;
435  anagramHintInfoBanner.hide();
436  if (kanagramEngineHelper.compareWords() == true)
437  {
438  originalWordLetterButtonBackground =
439  "image://theme/meegotouch-button-positive-background";
440 
441  if (kanagramEngineHelper.useSounds) {
442  rightSoundEffect.play();
443  }
444  }
445  else
446  {
447  originalWordLetterButtonBackground =
448  "image://theme/meegotouch-button-negative-background";
449 
450  if (kanagramEngineHelper.useSounds) {
451  wrongSoundEffect.play();
452  }
453  }
454  }
455  }
456  }
457  }
458  }
459  }
460  }
461 }
LetterElement
Definition: LetterElement.qml:20
MySelectionDialog
Definition: MySelectionDialog.qml:42
Page
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kanagram

Skip menu "kanagram"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal