moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / ktouch / src / ktouchleveldata.h
blobf361d6436b881744227a315b790d60f0e6454f8e
1 /***************************************************************************
2 * ktouchleveldata.h *
3 * ----------------- *
4 * Copyright (C) 2000 by Håvard Frøiland, 2003 by Andreas Nicolai *
5 * ghorwin@users.sourceforge.net *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 ***************************************************************************/
13 #ifndef KTOUCHLEVELDATA_H
14 #define KTOUCHLEVELDATA_H
16 #include <qstring.h>
17 #include <qtextstream.h>
18 #include <qvaluevector.h>
19 #include <qdom.h>
21 class QDomDocument;
22 class QDomElement;
24 /// This class contains the data of one level in a lecture and provides
25 /// access to the lines of that level.
26 ///
27 /// A lecture (KTouchLecture) typically contains multiple levels. Each
28 /// level contains a level description, a string with the
29 /// newly introduced characters and several lines of training text.
30 /// There is ALWAYS at least one line of training text in the level!<p>
31 /// During a training session you might want to retrieve a certain line of
32 /// the level. You can use the member function line(lineNumber) to get a
33 /// line of the level.
34 /// The member function count() returns the number of lines in this level.
35 class KTouchLevelData {
36 public:
37 /// Default constructor, creates a default level.
38 KTouchLevelData() { createDefault(); }
39 /// Constructor for creating a new level.
40 KTouchLevelData(const QString& comment, const QString& newChars)
41 : m_comment(comment), m_newChars(newChars) { createDefault(); }
42 /// Returns the level description (comment).
43 const QString& comment() const { return m_comment; };
44 /// Returns the new characters string.
45 const QString& newChars() const { return m_newChars; };
46 /// Returns the line with number 'lineNumber' (0 means first line).
47 ///
48 /// If the line number is out of range, the first line will be returned.
49 const QString& line(unsigned int lineNumber) const;
50 /// Returns the number of lines.
51 unsigned int count() const { return m_lines.size(); };
53 private:
54 /// Creates a default level.
55 void createDefault();
56 /// Reads a level from the input stream.
57 /// @return Returns 'true', when a level could be read successfully, or 'false' otherwise.
58 bool readLevel(QTextStream& in);
59 /// Reads a level from a XML Dom Node.
60 /// @return Returns 'true', when a level could be read successfully, or 'false' otherwise.
61 bool readLevel(QDomNode in);
62 /// Writes the level data into the output stream.
63 void writeLevel(QTextStream& out) const;
64 /// Writes the level data into the output stream.
65 void writeLevel(QDomDocument& doc, QDomElement& root) const;
67 QString m_comment; ///< A comment for the level.
68 QString m_newChars; ///< Contains the newly introduced characters in this level.
69 QValueVector<QString> m_lines; ///< The lines of the level.
71 // so I don't have to allow access to read/write function to everybody :-)
72 friend class KTouchLecture;
73 friend class KTouchLectureEditor;
76 #endif // KTOUCHLEVELDATA_H