-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordsearchdoc.cpp
802 lines (714 loc) · 26.2 KB
/
wordsearchdoc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
/***************************************************************************
* Copyright (C) 2006-2024 M Wellings *
* info@openforeveryone.co.uk *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License version 2 as *
* published by the Free Software Foundation *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QWidget>
#include <QFile>
#include <QDomDocument>
#include <QDebug>
#include "wordsearchdoc.h"
WordSearchDoc::WordSearchDoc(QWidget *parent)
: QObject(parent)
{
WSFont.setFamily("URW Gothic L");
WSFont.setPointSize(20);
WSFont.setWeight(QFont::Light);
creatorLabelFont.setPointSize(8);
ws = new wordsearch;
showanswers=false;
showwords=false;
showCreatorLabel=true;
showGrid=true;
useMask=false;
maskChanged=false;
edited=false;
sortmethod = 2;
gridWidth=0.02;
topMargin = 0.5; leftMargin = 0.5; rightMargin = 0.5; bottomMargin = 0.5; pageHeight = 11.69; pageWidth = 8.26;
filename = "";
wordlistorder=UserDefined;
bgColor=Qt::white;
hlColor=Qt::blue;
hlSolid=true;
showPageNumber = showPageNumberType::PageNumberMultipage;
showPageCount = true;
}
void WordSearchDoc::Create()
{
ws->create();
setEditedState(true);
// update();
}
void WordSearchDoc::setWSFont(QFont WSFont)
{
this->WSFont = WSFont;
setEditedState(true);
// update();
}
uint WordSearchDoc::numwordsplaced()
{
int numwordsplaced = 0;
for (uint i = 0; i < ws->wordlist.size(); i++)
{
if (ws->wordlist[i].used)
numwordsplaced++;
}
return numwordsplaced;
}
void WordSearchDoc::setWSFont()
{
// bool ok;
// QFont font = QFontDialog::getFont(&ok, this->WSFont, this);
// if (ok) {
// this->WSFont = font;
// update();
// }
}
void WordSearchDoc::setTitleFont(QFont TitleFont)
{
this->TitleFont = TitleFont;
setEditedState(true);
//update();
}
void WordSearchDoc::setTitleFont()
{
// bool ok;
// QFont font = QFontDialog::getFont(&ok, this->TitleFont, this);
// if (ok)
// {
// this->TitleFont = font;
//// update();
// }
}
void WordSearchDoc::setWordsFont(QFont WordsFont)
{
this->WordsFont = WordsFont;
setEditedState(true);
// update();
}
void WordSearchDoc::setWordsFont()
{
// bool ok;
// QFont font = QFontDialog::getFont(&ok, this->WordsFont, this);
// if (ok) {
// this->WordsFont = font;
// update();
// }
}
QFont WordSearchDoc::getWordsFont()
{
return WordsFont;
}
QFont WordSearchDoc::getWSFont()
{
return WSFont;
}
QFont WordSearchDoc::getTitleFont()
{
return TitleFont;
}
QFont WordSearchDoc::getCLFont()
{
return creatorLabelFont;
}
void WordSearchDoc::setSize(int x, int y)
{
ws->setXSize(x);
ws->setYSize(y);
setEditedState(true);
//update();
}
void WordSearchDoc::setXSize(int x)
{
if (x!=ws->XSize())
{
ws->setXSize(x);
ws->wordlist.clear();
setEditedState(true);
//update();
}
}
void WordSearchDoc::setYSize(int y)
{
if (y!=ws->YSize())
{
ws->setYSize(y);
ws->wordlist.clear();
setEditedState(true);
//update();
}
}
void WordSearchDoc::setShowAnswers(int showanswers)
{
this->showanswers=showanswers;
setEditedState(true);
//update();
}
void WordSearchDoc::setTitle(QString Title)
{
title=Title;
setEditedState(true);
//update();
}
bool WordSearchDoc::getShowWords()
{
return showwords;
}
bool WordSearchDoc::getShowAnswers()
{
return showanswers;
}
QString WordSearchDoc::getTitle()
{
return title;
}
void WordSearchDoc::setShowWords(int showwords)
{
this->showwords=showwords;
setEditedState(true);
//update();
}
void WordSearchDoc::setEditedState(bool edited)
{
this->edited=edited;
emit EditedStateChanged(edited);
}
void WordSearchDoc::setAutoResize(int autosize)
{
if (autosize>0)
ws->setAutoResize(true);
else
ws->setAutoResize(false);
setEditedState(true);
}
int WordSearchDoc::Open(QString fileName)
{
if (fileName.isEmpty())
return 2;
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
return 2;
int error = OpenFromIO(file);
if (!error)
{
this->filename=fileName;
// qDebug() << "File opened" << filename;
setEditedState(false);
}
return error;
}
int WordSearchDoc::OpenFromIO(QIODevice &file)
{
QDomDocument doc;
if (!doc.setContent(&file))
{
// file.close();
// if (!file.open(QIODevice::ReadOnly))
// return 2;
file.seek(0);
qDebug() << "File is binary";
int numwords;
QDataStream in(&file);
in.setVersion(8);
QString filetype;
in >> filetype;
int fileversion;
if (filetype == "Wordsearch Creator wordsearch")
fileversion = 1;
else if (filetype == "Wordsearch Creator wordsearch 0.9")
fileversion = 2;
else
return 3;
int y = ws->YSize();
int x = ws->XSize();
in >> x >> y;
setYSize(y);
setXSize(x);
for (int b = 0; b < y; b++)
{
for (int a = 0; a < x; a++)
{
QChar tempQChar;
in >> tempQChar;
ws->placeLetter(tempQChar, a, b);
}
}
QFont WSFont, TitleFont, WordsFont;
bool showanswers, showwords, useMask, showGrid;
double gridWidth;
QColor WSColor, titleColor, WLColor, gridColor;
QString title;
in >> WSFont >> TitleFont >> WordsFont >> showanswers >> showwords >> title >> useMask >> showGrid >> WSColor >> titleColor >> WLColor >> gridColor >> gridWidth;
setShowGrid(showGrid);
setWSColor(WSColor);
setTitleColor(titleColor);
setWLColor(WLColor);
setGridColor(gridColor);
setGridWidth(gridWidth);
setWSFont(WSFont);
setWordsFont(WordsFont);
setTitleFont(TitleFont);
setMaskChanged(false);
setUseMask(useMask);
if (useMask)
setMaskChanged(true);
this->setShowAnswers(showanswers);
this->setShowWords(showwords);
setTitle(title);
ws->wordlist.clear();
in >> numwords;
for (int a=0; a < numwords; a++)
{
QString worda;
Word temp;
in >> worda;
temp.word = worda;
ws->wordlist.push_back(temp);
in >> ws->wordlist[a].used >> ws->wordlist[a].xpos >> ws->wordlist[a].ypos >> ws->wordlist[a].expos >> ws->wordlist[a].eypos >> ws->wordlist[a].direction;
if (fileversion == 2)
in >> ws->wordlist[a].listpos;
else
ws->wordlist[a].listpos = a;
ws->wordlist[a].word = worda;
}
for (int b = 0; b < y; b++)
{
for (int a = 0; a < x; a++)
{
bool mc;
in >> mc;
ws->allowLetter(mc, a, b);
}
}
file.close();
}
else
{
file.close();
QDomElement root = doc.documentElement();
if( root.tagName() != "WSCXML" )
{
return 3;
}
QDomElement worksheet = root.firstChild().toElement();
if(worksheet.tagName() != "Worksheet") return 3;
QDomElement wordsearch = worksheet.firstChildElement("Wordsearch");
if(wordsearch.tagName() != "Wordsearch") return 3;
int x = wordsearch.attribute( "xsize","-1").toInt();
int y = wordsearch.attribute( "ysize","-1").toInt();
if (x<1 || x>99 || y<1 || y>99) return 3;
setYSize(y);
setXSize(x);
ws->resetmask();
ws->resetgrid();
QDomElement DEtitle = wordsearch.firstChildElement("Title");
setTitle(DEtitle.text());
ws->Alphabet=wordsearch.firstChildElement("Alphabet").text();
this->setShowAnswers((wordsearch.attribute("ShowAnswers","no").toLower() == "yes" || wordsearch.attribute("ShowAnswers","no").toLower() =="true"));
this->setShowWords((wordsearch.attribute("ShowWords","no").toLower() == "yes" || wordsearch.attribute("ShowWords","no").toLower() =="true"));
QDomElement DEAllowedDirections = wordsearch.firstChildElement("AllowedDirections");
if (!DEAllowedDirections.isNull())
{
for (int x = 0; x < 8; x++)
{
if (DEAllowedDirections.attribute(QString("Direction%1").arg(x)).toLower() == "yes")
ws->setDirectionAllowed(x,true);
else
ws->setDirectionAllowed(x,false);
}
}
QDomElement DEFormat = wordsearch.firstChildElement("Format");
QFont WSFont;
QColor WSColor;
WSFont.fromString(DEFormat.firstChildElement("WSFont").attribute("qtFontDescription"));
WSColor.setNamedColor(DEFormat.firstChildElement("WSFont").attribute("color"));
setWSFont(WSFont);
setWSColor(WSColor);
QFont TitleFont;
QColor TitleColor;
TitleFont.fromString(DEFormat.firstChildElement("TitleFont").attribute("qtFontDescription"));
TitleColor.setNamedColor(DEFormat.firstChildElement("TitleFont").attribute("color"));
setTitleFont(TitleFont);
setTitleColor(TitleColor);
QFont WordsFont;
QColor WordsColor;
WordsFont.fromString(DEFormat.firstChildElement("WordsFont").attribute("qtFontDescription"));
WordsColor.setNamedColor(DEFormat.firstChildElement("WordsFont").attribute("color"));
setWordsFont(WordsFont);
setWordsColor(WordsColor);
QColor BGColor;
BGColor.setNamedColor(DEFormat.firstChildElement("Background").attribute("color", "white"));
setBgColor(BGColor);
QColor HLColor;
HLColor.setNamedColor(DEFormat.firstChildElement("Highlight").attribute("color", "blue"));
setHlSolid(DEFormat.firstChildElement("Highlight").attribute("style", "solid")!="outline");
setHlColor(HLColor);
setShowGrid((DEFormat.firstChildElement("Grid").attribute("Visible","yes").toLower() == "yes" || wordsearch.attribute("Visible","yes").toLower() =="true"));
QColor GridColor;
GridColor.setNamedColor(DEFormat.firstChildElement("Grid").attribute("color","black"));
setGridColor(GridColor);
setGridWidth(DEFormat.firstChildElement("Grid").attribute("Width","0").toDouble());
ws->resetgrid();
QDomElement DELetters = wordsearch.firstChildElement("Letters");
QDomNodeList DELetterList = DELetters.elementsByTagName("Letter");
for (int i = 0; i < DELetterList.count(); i++)
{
int a=DELetterList.at(i).toElement().attribute( "XPos").toInt();
int b=DELetterList.at(i).toElement().attribute( "YPos").toInt();
//A check should be done here
if (DELetterList.at(i).toElement().text().size() > 0)
ws->placeLetter(DELetterList.at(i).toElement().text().at(0), a, b);
}
ws->wordlist.clear();
QStringList orders;
orders.append("UserDefined");
orders.append("Alphabetical");
orders.append( "ReverseAlphabetical");
orders.append( "SizeAsc");
orders.append( "SizeDes");
QStringList wordSpaceLabels;
wordSpaceLabels.append("FillSpace");
wordSpaceLabels.append("RemoveSpace");
wordSpaceLabels.append("KeepSpace");
QDomElement DEWords = wordsearch.firstChildElement("Words");
if (DEWords.attributes().contains("Order"))
wordlistorder = (WordSearchDoc::ordertype)orders.indexOf(DEWords.attribute("Order"));
if (DEWords.attributes().contains("SpaceBehaviour"))
{
QString SpaceBehaviourAttr = DEWords.attribute("SpaceBehaviour");
auto indexof = wordSpaceLabels.indexOf(SpaceBehaviourAttr);
ws->wordSpace = (wordsearch::wordSpaceType)indexof;
}
QDomNodeList DEWordList = DEWords.elementsByTagName("Word");
for (int i = 0; i < DEWordList.count(); i++)
{
//cout <<i<<endl;
Word temp;
temp.word = DEWordList.at(i).toElement().text();
temp.listpos = DEWordList.at(i).toElement().attribute( "ListPos").toInt();
if (DEWordList.at(i).toElement().attribute("Used").toLower()=="yes")
{
temp.used = true;
temp.xpos = DEWordList.at(i).toElement().attribute( "StartXPos").toInt();
temp.ypos = DEWordList.at(i).toElement().attribute( "StartYPos").toInt();
temp.expos = DEWordList.at(i).toElement().attribute( "EndXPos").toInt();
temp.eypos = DEWordList.at(i).toElement().attribute( "EndYPos").toInt();
temp.direction = DEWordList.at(i).toElement().attribute( "Direction").toInt();
if (DEWordList.at(i).toElement().attribute("Answered","false")=="yes"||DEWordList.at(i).toElement().attribute("Answered","false")=="true")
temp.answered = true;
else
temp.answered = false;
}
//cout << temp.word << " " << temp.xpos << " " << temp.ypos << " " << temp.expos << " " << temp.eypos << " " << temp.direction << " " << endl;
ws->wordlist.push_back(temp);
}
QDomElement DEMask = wordsearch.firstChildElement("Mask");
ws->resetmask();
setMaskChanged(false);
setUseMask(false);
if (!DEMask.isNull())
{
setMaskChanged(true);
QDomNodeList DECellList = DEMask.elementsByTagName("Cell");
for (int i = 0; i < DECellList.count(); i++)
{
//cout << DECellList.at(i).toElement().attribute("XPos").toInt() << " " << DECellList.at(i).toElement().attribute("YPos").toInt() << cout;
ws->allowLetter(false, DECellList.at(i).toElement().attribute("XPos").toInt(), DECellList.at(i).toElement().attribute("YPos").toInt());
setUseMask(true);
}
}
QDomElement pagelayout = worksheet.firstChildElement("PageLayout");
leftMargin = pagelayout.attribute( "LeftMargin", "0.5").toDouble();
rightMargin = pagelayout.attribute( "RightMargin", "0.5").toDouble();
topMargin = pagelayout.attribute( "TopMargin", "0.5").toDouble();
bottomMargin = pagelayout.attribute( "BottomMargin", "0.5").toDouble();
pageHeight = pagelayout.attribute( "Height", "11.69").toDouble();
pageWidth = pagelayout.attribute( "Width", "8.26").toDouble();
QDomElement DEfooter = worksheet.firstChildElement("Footer");
footer = DEfooter.text();
QDomElement DEPageNumbers = worksheet.firstChildElement("PageNumbers");
QStringList showPageNumberOptions;
showPageNumberOptions.append("NeverShow");
showPageNumberOptions.append("AlwaysShow");
showPageNumberOptions.append( "ShowWhenMultipage");
QString showPageNumberAttr = DEPageNumbers.attribute("ShowPageNumbers");
if (showPageNumberAttr == "NeverShow")
this->showPageNumber = PageNumberNever;
else if (showPageNumberAttr == "AlwaysShow")
this->showPageNumber = PageNumberAlways;
else
this->showPageNumber = PageNumberMultipage;
QString showPageCountAttr = DEPageNumbers.attribute("ShowPageCount");
this->showPageCount= !(showPageCountAttr == "false");
}
setEditedState(false);
return 0;
}
bool WordSearchDoc::saveToIO(QIODevice &file){
QTextStream out(&file);
out.setCodec("UTF-8");
QDomDocument doc;
QDomElement root = doc.createElement("WSCXML");
doc.appendChild(root);
QDomElement worksheet = doc.createElement("Worksheet");
root.appendChild(worksheet);
QDomElement pagelayout = doc.createElement("PageLayout");
worksheet.appendChild(pagelayout);
pagelayout.setAttribute( "LeftMargin", leftMargin);
pagelayout.setAttribute( "RightMargin", rightMargin);
pagelayout.setAttribute( "TopMargin", topMargin);
pagelayout.setAttribute( "BottomMargin",bottomMargin);
pagelayout.setAttribute( "Height", pageHeight);
pagelayout.setAttribute( "Width", pageWidth);
QDomElement wordsearch = doc.createElement("Wordsearch");
worksheet.appendChild(wordsearch);
wordsearch.setAttribute( "xsize", ws->XSize());
wordsearch.setAttribute( "ysize", ws->YSize());
if (getTitle() != "") {
QDomElement DEtitle = doc.createElement("Title");
wordsearch.appendChild(DEtitle);
QDomText DTtitle = doc.createTextNode(getTitle());
DEtitle.appendChild(DTtitle);}
if (!ws->Alphabet.isNull())
{
QDomElement DEAlphabet = doc.createElement("Alphabet");
wordsearch.appendChild(DEAlphabet);
QDomText DTAlphabet = doc.createTextNode(ws->Alphabet);
DEAlphabet.appendChild(DTAlphabet);
}
if(getShowAnswers())
wordsearch.setAttribute ( "ShowAnswers","yes");
if(getShowWords())
wordsearch.setAttribute ( "ShowWords","yes");
QDomElement DEFormat = doc.createElement("Format");
wordsearch.appendChild(DEFormat);
QDomElement DEGrid = doc.createElement("Grid");
DEFormat.appendChild(DEGrid);
if(!getShowGrid())
DEGrid.setAttribute ("Visible","no");
DEGrid.setAttribute ( "Width",getGridWidth());
DEGrid.setAttribute( "color", getGridColor().name());
QDomElement DEWSFont = doc.createElement("WSFont");
DEFormat.appendChild(DEWSFont);
DEWSFont.setAttribute( "qtFontDescription", getWSFont().toString());
DEWSFont.setAttribute( "color", getWSColor().name());
QDomElement DETitleFont = doc.createElement("TitleFont");
DEFormat.appendChild(DETitleFont);
DETitleFont.setAttribute( "qtFontDescription", getTitleFont().toString());
DETitleFont.setAttribute( "color", getTitleColor().name());
QDomElement DEWordsFont = doc.createElement("WordsFont");
DEFormat.appendChild(DEWordsFont);
DEWordsFont.setAttribute( "qtFontDescription", getWordsFont().toString());
DEWordsFont.setAttribute( "color", getWLColor().name());
QDomElement DEBackground = doc.createElement("Background");
DEFormat.appendChild(DEBackground);
DEBackground.setAttribute( "color", getBGColor().name());
QDomElement DEHighlight = doc.createElement("Highlight");
DEFormat.appendChild(DEHighlight);
DEHighlight.setAttribute( "color", getHLColor().name());
DEHighlight.setAttribute( "style", getHLSolid() ? "solid" : "outline");
QDomElement DEAllowedDirections = doc.createElement("AllowedDirections");
wordsearch.appendChild(DEAllowedDirections);
for (int x = 0; x < 8; x++)
{
DEAllowedDirections.setAttribute(QString("Direction%1").arg(x),ws->DirectionAllowed(x)?"Yes":"No");
}
QDomElement DELetters= doc.createElement("Letters");
wordsearch.appendChild(DELetters);
int y = ws->YSize();
int x = ws->XSize();
QDomElement DELetter[x*y];
QDomText DTLetter[x*y];
for (int b = 0; b < y; b++)
{
for (int a = 0; a < x; a++)
{
if (!ws->Letter(a,b).isNull())
{
DELetter[(a*b)+a] = doc.createElement("Letter");
DELetters.appendChild(DELetter[(a*b)+a]);
DELetter[(a*b)+a].setAttribute( "XPos",a);
DELetter[(a*b)+a].setAttribute( "YPos",b);
DTLetter[(a*b)+a] = doc.createTextNode(ws->Letter(a,b));
//cout << a << " " << b << " " << ws->Letter(a,b).toAscii () << endl;
DELetter[(a*b)+a].appendChild(DTLetter[(a*b)+a]);
}
}
}
QDomElement DEWords = doc.createElement("Words");
wordsearch.appendChild(DEWords);
QStringList orders;
orders.append("UserDefined");
orders.append("Alphabetical");
orders.append( "ReverseAlphabetical");
orders.append( "SizeAsc");
orders.append( "SizeDes");
QStringList wordSpaceLabels;
wordSpaceLabels.append("FillSpace");
wordSpaceLabels.append("RemoveSpace");
wordSpaceLabels.append("KeepSpace");
DEWords.setAttribute("Order", orders.at(wordlistorder));
DEWords.setAttribute("SpaceBehaviour", wordSpaceLabels.at(ws->wordSpace));
QDomElement DEWord[ws->wordlist.size()];
QDomText DTWord[ws->wordlist.size()];
for (uint a=0; a < ws->wordlist.size(); a++)
{
DEWord[a] = doc.createElement("Word");
DEWords.appendChild(DEWord[a]);
if (ws->wordlist[a].used)
{ DEWord[a].setAttribute("Used", "yes");
DEWord[a].setAttribute( "StartXPos",ws->wordlist[a].xpos);
DEWord[a].setAttribute( "StartYPos",ws->wordlist[a].ypos);
DEWord[a].setAttribute( "EndXPos",ws->wordlist[a].expos);
DEWord[a].setAttribute( "EndYPos",ws->wordlist[a].eypos);
DEWord[a].setAttribute( "Direction",ws->wordlist[a].direction);
if (ws->wordlist[a].answered)
DEWord[a].setAttribute("Answered","yes");
}
DEWord[a].setAttribute( "ListPos",ws->wordlist[a].listpos);
DTWord[a]= doc.createTextNode(ws->wordlist[a].word);
DEWord[a].appendChild(DTWord[a]);
}
if (true)//getUseMask())
{
QDomElement DEMask = doc.createElement("Mask");
wordsearch.appendChild(DEMask);
QDomElement DEMaskCell[x*y];
for (int b = 0; b < y; b++)
{
for (int a = 0; a < x; a++)
{
if (!ws->Mask(a+1,b+1))
{
DEMaskCell[(a*b)+a] = doc.createElement("Cell");
DEMaskCell[(a*b)+a].setAttribute( "XPos",a);
DEMaskCell[(a*b)+a].setAttribute( "YPos",b);
DEMask.appendChild(DEMaskCell[(a*b)+a]);
}
}
}
}
if (!this->footer.isNull())
{
QDomElement DEfooter = doc.createElement("Footer");
worksheet.appendChild(DEfooter);
QDomText DTfooter = doc.createTextNode(this->footer);
DEfooter.appendChild(DTfooter);
}
QDomElement pageNumbers = doc.createElement("PageNumbers");
worksheet.appendChild(pageNumbers);
QStringList showPageNumberOptions;
showPageNumberOptions.append("NeverShow");
showPageNumberOptions.append("AlwaysShow");
showPageNumberOptions.append( "ShowWhenMultipage");
pageNumbers.setAttribute( "ShowPageNumbers", showPageNumberOptions.at(getShowPageNumber()));
pageNumbers.setAttribute( "ShowPageCount", getShowPageCount() ? "true" : "false");
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
out << doc.toString();
//qDebug() << doc.toString();
return true;
}
QList<Word> WordSearchDoc::sortedUsedWordList()
{
int a = 0;
QList<Word> sortedwordlist;
while (a < int(ws->wordlist.size()))
{
if (ws->wordlist.at(a).used)
sortedwordlist.append(ws->wordlist.at(a));
a++;
}
a=0;
if (wordlistorder==WordSearchDoc::Alphabetical)
while (a < sortedwordlist.size()-1)
{
if ( QString::localeAwareCompare(sortedwordlist.at(a).word,sortedwordlist.at(a+1).word)>0)
{
sortedwordlist.move(a+1, a);
a=0;
}
else
a++;
}
if (wordlistorder==WordSearchDoc::UserDefined)
while (a < sortedwordlist.size()-1)
{
if ( sortedwordlist.at(a).listpos > sortedwordlist.at(a+1).listpos)
{
sortedwordlist.move(a+1, a);
a=0;
}
else
a++;
}
if (wordlistorder==WordSearchDoc::ReverseAlphabetical)
while (a < sortedwordlist.size()-1)
{
if ( QString::localeAwareCompare(sortedwordlist.at(a).word,sortedwordlist.at(a+1).word)<0)
{
sortedwordlist.move(a+1, a);
a=0;
}
else
a++;
}
if (wordlistorder==WordSearchDoc::SizeDes)
while (a < sortedwordlist.size()-1)
{
if (sortedwordlist.at(a).word.size()>sortedwordlist.at(a+1).word.size())
{
sortedwordlist.move(a+1, a);
a=0;
}
else
a++;
}
return sortedwordlist;
}
QList<Word> WordSearchDoc::fullWordList() {
QList<Word> sortedWordlist;
int a = 0;
while (a < int(ws->wordlist.size()))
{
sortedWordlist.append(ws->wordlist.at(a));
a++;
}
a = 0;
while (a < sortedWordlist.size()-1)
{
if ( sortedWordlist.at(a).listpos > sortedWordlist.at(a+1).listpos)
{
sortedWordlist.move(a+1, a);
a=0;
}
else
a++;
}
return sortedWordlist;
}
void WordSearchDoc::clearAnswers()
{
for(uint i = 0; i < ws->wordlist.size(); i++)
{
ws->wordlist[i].answered=false;
}
EditedStateChanged(true);
}
WordSearchDoc::~WordSearchDoc()
{
delete ws;
}