moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kwordquiz / src / wqlreader.cpp
blob3e29b1845213e33e25a900ee9f4d6a42407a77d5
1 /***************************************************************************
2 wqlreader.cpp
3 -------------------
4 copyright : (C) 2004 by Peter Hedlund
5 email : peter@peterandlinda.com
6 ***************************************************************************/
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
17 #include <qtextstream.h>
18 #include <qfile.h>
20 #include <kmessagebox.h>
21 #include <klocale.h>
23 #include "wqlreader.h"
25 KWqlDataItem::KWqlDataItem()
30 KWqlDataItem::KWqlDataItem(const QString &front, const QString &back, int height)
32 m_front = front;
33 m_back = back;
34 m_height = height;
37 KWqlDataItem::~KWqlDataItem()
42 /*!
43 \fn WqlReader::WqlReader
45 WqlReader::WqlReader()
50 KWqlDataItemList WqlReader::parse(const QString &fileName)
52 KWqlDataItemList list;
53 QFile file(fileName);
54 file.open(IO_ReadOnly);
55 QTextStream ts(&file);
56 ts.setEncoding(QTextStream::Latin1);
58 QString s = "";
59 s=ts.readLine();
60 if (s != "WordQuiz")
62 KMessageBox::error(0, i18n("This does not appear to be a (K)WordQuiz file") + s);
63 file.close();
64 return list;
66 s = ts.readLine();
67 s = s.left(1);
68 int iFV = s.toInt(0);
69 if (iFV != 5)
71 KMessageBox::error(0, i18n("KWordQuiz can only open files created by WordQuiz 5.x"));
72 file.close();
73 return list;
76 while (ts.readLine() != "[Font Info]");
77 s = ts.readLine();
78 int p = s.find("=", 0);
79 QString fam = s.right(s.length() - (p + 1));
80 fam = fam.mid(1, fam.length() - 2);
81 //g->font().setFamily(s);
83 s = ts.readLine();
84 p = s.find("=", 0);
85 s = s.right(s.length() - (p + 1));
86 int ps = s.toInt(0);
88 s = ts.readLine();
89 p = s.find("=", 0);
90 s = s.right(s.length() - (p + 1));
91 int b = 0;
92 if (s == "1")
94 b = QFont::Bold;
97 s = ts.readLine();
98 p = s.find("=", 0);
99 s = s.right(s.length() - (p + 1));
100 bool it = (s == "1");
102 QFont m_font(fam, ps, b, it);
104 while (ts.readLine() != "[Character Info]");
105 s = ts.readLine();
106 p = s.find("=", 0);
107 m_specialCharacters = s.right(s.length() - (p + 1));
109 while (ts.readLine() != "[Grid Info]");
110 ts.readLine(); //skip value for width of row headers
112 s = ts.readLine();
113 p = s.find("=", 0);
114 s = s.right(s.length() - (p + 1));
115 m_colWidth1 = s.toInt(0, 10);
117 s = ts.readLine();
118 p = s.find("=", 0);
119 s = s.right(s.length() - (p + 1));
120 m_colWidth2 = s.toInt(0, 10);
122 s = ts.readLine();
123 p = s.find("=", 0);
124 s = s.right(s.length() - (p + 1));
125 m_numRows = (s.toInt(0, 10) - 1); //We need to reduce by one since the header is not included
127 // Selection
128 s = ts.readLine();
129 p = s.find("=", 0);
130 s = s.right(s.length() - (p + 1));
131 m_topLeft =s.toInt(0, 10) - 1;
133 s = ts.readLine();
134 p = s.find("=", 0);
135 s = s.right(s.length() - (p + 1));
136 m_topRight =s.toInt(0, 10) - 1;
138 s = ts.readLine();
139 p = s.find("=", 0);
140 s = s.right(s.length() - (p + 1));
141 m_bottomLeft =s.toInt(0, 10) - 1;
143 s = ts.readLine();
144 p = s.find("=", 0);
145 s = s.right(s.length() - (p + 1));
146 m_bottomRight =s.toInt(0, 10) - 1 ;
148 while (ts.readLine() != "[Vocabulary]");
150 s = ts.readLine();
151 p = s.find(" [", 0);
152 s = s.left(p);
153 s = s.stripWhiteSpace();
154 m_language1 = s;
155 m_language2 = ts.readLine();
157 while (!s.isNull())
159 s = ts.readLine();
160 p = s.find("[", 0);
161 QString r = s.mid(p + 1, 10);
162 int h = r.toInt(0, 10);
163 s = s.left(p);
164 s = s.stripWhiteSpace();
166 QString b;
167 b = ts.readLine();
169 KWqlDataItem item(s, b, h /15);
170 list.append(item);
172 file.close();
173 return list;
178 \fn WqlReader::colWidth(int col)
180 int WqlReader::colWidth(int col)
182 if (col == 0)
183 return m_colWidth1;
184 else
185 return m_colWidth2;
190 \fn WqlReader::language(int col)
192 QString WqlReader::language(int col)
194 if (col == 0)
195 return m_language1;
196 else
197 return m_language2;