22 import org.kde.plasma.components 0.1
24 import
"array.js" as MyArray
28 orientationLock: PageOrientation.LockLandscape;
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;
38 id: anagramStatusEnumeration;
40 property int active: 2;
41 property int resolved: 3;
45 if (status == PageStatus.Active && anagramStatus != anagramStatusEnumeration.resolved) {
46 if (rootWindow.languageSelectionChanged ==
true) {
48 if (kanagramEngineHelper.useSounds) {
49 chalkSoundEffect.play();
52 categorySelectionDialog.model = kanagramGame.vocabularyList();
58 if (categorySelectionDialog.selectedIndex >= categorySelectionDialog.model.length) {
59 categorySelectionDialog.selectedIndex = 0;
62 kanagramGame.setCurrentCategory(categorySelectionDialog.selectedIndex);
63 kanagramEngineHelper.saveSettings();
65 kanagramGame.useVocabulary(categorySelectionDialog.selectedIndex);
67 rootWindow.languageSelectionChanged =
false;
70 secondTimer.repeat =
true;
71 secondTimer.restart();
76 target: platformWindow;
79 if (platformWindow.active && status == PageStatus.Active
80 && anagramStatus != anagramStatusEnumeration.resolved) {
81 secondTimer.repeat =
true;
82 secondTimer.restart();
84 anagramHintInfoBanner.hide();
86 secondTimer.repeat =
false;
92 Component.onCompleted: {
93 categorySelectionDialog.selectedIndex = kanagramGame.currentCategory();
97 function pushPage(file) {
98 var component = Qt.createComponent(file)
99 if (component.status == Component.Ready)
100 pageStack.push(component);
102 console.log(
"Error loading component:", component.errorString());
105 function resolveAnagram() {
106 originalWordLetterRepeater.model = kanagramEngineHelper.anagramOriginalWord();
107 currentOriginalWordIndex = originalWordLetterRepeater.model.length;
108 anagramStatus = anagramStatusEnumeration.resolved;
109 anagramHintInfoBanner.hide();
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 = [];
125 id: anagramHintInfoBanner;
126 text: i18n(
"This is an info banner with icon");
127 iconSource:
"dialog-information.png";
137 iconSource:
"help-hint.png";
140 anagramHintInfoBanner.text = kanagramGame.hint();
141 anagramHintInfoBanner.timerShowTime = kanagramEngineHelper.hintHideTime * 1000;
144 anagramHintInfoBanner.show();
149 iconSource:
"games-solve.png";
152 if (kanagramEngineHelper.useSounds) {
153 chalkSoundEffect.play();
158 secondTimer.repeat =
false;
164 text: categorySelectionDialog.model[categorySelectionDialog.selectedIndex];
171 categorySelectionDialog.open();
176 iconSource:
"go-next.png";
179 if (kanagramEngineHelper.useSounds) {
180 chalkSoundEffect.play();
184 secondTimer.repeat =
true;
185 secondTimer.restart();
190 iconSource:
"settings.png";
193 anagramHintInfoBanner.hide();
194 pageStack.push(mainSettingsPage);
196 secondTimer.repeat =
false;
202 tools: mainPageTools;
207 id: categorySelectionDialog;
208 titleText:
"Choose an anagram category"
210 model: kanagramGame.vocabularyList();
212 onSelectedIndexChanged: {
214 if (kanagramEngineHelper.useSounds) {
215 initialized ==
true ? chalkSoundEffect.play() : initialized =
true;
218 kanagramGame.setCurrentCategory(selectedIndex);
219 kanagramEngineHelper.saveSettings();
220 kanagramGame.useVocabulary(selectedIndex);
230 triggeredOnStart:
false;
233 if (kanagramEngineHelper.resolveTime != 0 && --countDownTimerValue == 0) {
235 anagramResultTimer.start();
236 originalWordLetterButtonBackground =
237 "image://theme/meegotouch-button-negative-background";
241 if (kanagramEngineHelper.useSounds) {
242 wrongSoundEffect.play();
249 id: anagramResultTimer;
253 triggeredOnStart:
false;
256 originalWordLetterButtonBackground =
257 "image://theme/meegotouch-button-inverted-background";
260 secondTimer.repeat =
true;
275 letterText: Math.floor(countDownTimerValue / 60 / 10);
276 visible: kanagramEngineHelper.resolveTime == 0 ?
false :
true;
280 letterText: Math.floor(countDownTimerValue / 60 % 10);
281 visible: kanagramEngineHelper.resolveTime == 0 ?
false :
true;
286 visible: kanagramEngineHelper.resolveTime == 0 ?
false :
true;
290 letterText: Math.floor(countDownTimerValue % 60 / 10);
291 visible: kanagramEngineHelper.resolveTime == 0 ?
false :
true;
295 letterText: Math.floor(countDownTimerValue % 60 % 10);
296 visible: kanagramEngineHelper.resolveTime == 0 ?
false :
true;
300 iconSource:
"timer-pause.png";
303 anagramHintInfoBanner.hide();
307 secondTimer.repeat =
false;
317 verticalCenterOffset: 15;
325 horizontalCenter: parent.horizontalCenter;
330 id: originalWordLetterRepeater;
333 id: originalWordLetterId;
334 text: anagramStatus == anagramStatusEnumeration.init ?
"" : modelData;
336 platformStyle: ButtonStyle {
337 background: originalWordLetterButtonBackground;
340 fontCapitalization: Font.AllUppercase;
341 fontWeight: Font.Bold;
342 horizontalAlignment: Text.AlignHCenter;
344 pressedTextColor:
"pink";
345 disabledTextColor:
"gray";
346 checkedTextColor:
"blue";
352 if (index + 1 == currentOriginalWordIndex && currentOriginalWordIndex != 0
353 && anagramStatus != anagramStatusEnumeration.resolved) {
354 if (kanagramEngineHelper.useSounds) {
355 anagramLetterPressSoundEffect.play();
358 var tmpAnagramLetterRepeaterModel = anagramLetterRepeater.model;
359 tmpAnagramLetterRepeaterModel[MyArray.sourceDestinationLetterIndexHash[index]] = originalWordLetterId.text;
360 anagramLetterRepeater.model = tmpAnagramLetterRepeaterModel;
362 MyArray.sourceDestinationLetterIndexHash.pop();
364 originalWordLetterRepeater.model = kanagramEngineHelper.removeInCurrentOriginalWord(index);
365 --currentOriginalWordIndex;
376 fillMode: Image.PreserveAspectFit;
377 source:
"chalk-separator.png";
383 horizontalCenter: parent.horizontalCenter;
388 id: anagramLetterRepeater;
392 text: anagramStatus == anagramStatusEnumeration.resolved ?
"" : modelData;
394 platformStyle: ButtonStyle {
395 background:
"image://theme/meegotouch-button-inverted-background";
398 fontCapitalization: Font.AllUppercase;
399 fontWeight: Font.Bold;
400 horizontalAlignment: Text.AlignHCenter;
402 pressedTextColor:
"pink";
403 disabledTextColor:
"gray";
404 checkedTextColor:
"blue";
410 if (anagramStatus != anagramStatusEnumeration.resolved)
412 if (anagramLetterId.text !=
"")
414 if (kanagramEngineHelper.useSounds) {
415 anagramLetterPressSoundEffect.play();
418 anagramStatus = anagramStatusEnumeration.active;
420 originalWordLetterRepeater.model =
421 kanagramEngineHelper.insertInCurrentOriginalWord(currentOriginalWordIndex, anagramLetterId.text);
423 ++currentOriginalWordIndex;
425 var tmpAnagramLetterRepeaterModel = anagramLetterRepeater.model;
426 tmpAnagramLetterRepeaterModel[[index]] =
"";
427 anagramLetterRepeater.model = tmpAnagramLetterRepeaterModel;
429 MyArray.sourceDestinationLetterIndexHash.push(index);
432 if (currentOriginalWordIndex == originalWordLetterRepeater.model.length)
434 anagramResultTimer.start();
435 anagramStatus = anagramStatusEnumeration.resolved;
436 anagramHintInfoBanner.hide();
437 if (kanagramEngineHelper.compareWords() ==
true)
439 originalWordLetterButtonBackground =
440 "image://theme/meegotouch-button-positive-background";
442 if (kanagramEngineHelper.useSounds) {
443 rightSoundEffect.play();
448 originalWordLetterButtonBackground =
449 "image://theme/meegotouch-button-negative-background";
451 if (kanagramEngineHelper.useSounds) {
452 wrongSoundEffect.play();