moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / ktouch / src / ktouchtrainer.h
blob14e77ab614c416b0e693e7013827f074ee782ff8
1 /***************************************************************************
2 * ktouchtrainer.h *
3 * --------------- *
4 * Copyright (C) 2000 by H�ard Friland, 2003 by Andreas Nicolai *
5 * haavard@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 KTOUCHTRAINER_H
14 #define KTOUCHTRAINER_H
16 #include <qobject.h>
18 #include "ktouchtrainingsession.h"
20 class QTimer;
22 class KTouchStatus;
23 class KTouchSlideLine;
24 class KTouchKeyboard;
25 class KTouchLecture;
27 /** This is the master trainer and does all the heavy work.
28 * The training object gets the already sorted "new key pressed" events from the main window
29 * and processes them. It manages the level and line adjustments, starts, stops, pauses and restarts
30 * a training, updates the widgets and and and...<p>
31 * Whether in training or not the user may switch levels using the level change buttons (if enabled)
32 * or change the lecture. Apart from the slots levelUp(), levelDown() the member functions goFirstLine()
33 * and goFirstLevel() are called (and basically they do what they are named after).<p>
34 * There is always a current training session. On a typical program start the training session is paused.
35 * When a training session is paused the timer is stopped and typed characters won't be accepted.
36 * When the user continues the training session we first wait for his first keypress (that's why we need
37 * the flag m_waiting) and after that we start the timer.<p>
38 * When the user starts a new training session the current session data will be added to the session history
39 * and the current session will be reset.<p>
40 * When the user quits the program his current training session is stored. During next startup this
42 class KTouchTrainer : public QObject {
43 Q_OBJECT
44 public:
45 /// Constructor.
46 KTouchTrainer(KTouchStatus *status, KTouchSlideLine *slideLine, KTouchKeyboard *keyboard, KTouchLecture *lecture);
47 /// Destructor
48 virtual ~KTouchTrainer();
49 /// Jumps to the first line in the current level (m_level) (Note: has no effect on the training session).
50 void goFirstLine();
51 /// Jumps to the first level, line 1 ((Note: has no effect on the training session).
52 void goFirstLevel() { m_level=0; goFirstLine(); }
53 /** Processes the character 'key', recalculates the variables and updates the widgets.
54 * If the training session was started and in waiting state the timer is started and the actuall training begins.
56 void keyPressed(QChar key);
57 /// Will be called when a character has been removed and recalculates the variables and updates the widgets.
58 void backspacePressed();
59 /// Will be called when "enter" has been pressed (displays next line).
60 void enterPressed();
61 /// Will be called whenever the student text has changed and updates the slide line widget,
62 /// the status widget and shows the next to be pressed key on the keyboard
63 void updateWidgets();
64 /// Reads the training session history.
65 void readSessionHistory();
66 /// Saves the training session history.
67 void writeSessionHistory();
69 unsigned int m_level; ///< Current level number (zero based).
70 unsigned int m_line; ///< Current line number (zero based).
72 QString m_teacherText; ///< The currently displayed teacher text.
73 QString m_studentText; ///< The currently typed student text.
75 bool m_waiting; ///< Indicates when we are waiting for the first keypress after session start.
76 bool m_trainingPaused; ///< Indicates whether we have paused the training session or not.
77 QTimer *m_trainingTimer; ///< The timer responsable for updating the speed LCD widget.
79 KTouchTrainingSession m_session; ///< The current training session.
80 QValueList<KTouchTrainingSession> m_sessionHistory; ///< Contains the previous sessions.
82 signals:
83 /// Will be emitted when the statusbar message changes.
84 void statusbarMessageChanged(const QString& text);
85 /// Will be emitted whenever a char has been pressed.
86 void statusbarStatsChanged(unsigned int correctChars, unsigned int totalChars, unsigned int words);
88 public slots:
89 /// Will be called when the level is increased.
90 void levelUp();
91 /// Will be called when the level is decreased.
92 void levelDown();
93 /// Starts a new training session.
94 void startNewTrainingSession(bool keepLevel);
95 /// Pauses the current training session.
96 void pauseTraining();
97 /// Continues the current training session.
98 void continueTraining();
100 private slots:
101 /// Will be called regularly by the training timer, increases the elapsed time and updates the speed LCD widget.
102 void timerTick();
104 private:
105 /// Sets up a new teacher line (depending on m_level and m_line).
106 void newLine();
107 /// Checks whether a training session is paused and doesn't accept typed chars (returns 'false' in this case).
108 bool typingAllowed();
110 KTouchStatus *m_statusWidget; ///< Pointer to the status widget on top of the main window.
111 KTouchSlideLine *m_slideLineWidget; ///< Pointer to the sliding line widget.
112 KTouchKeyboard *m_keyboardWidget; ///< Pointer to the keyboard widget.
113 KTouchLecture *m_lecture; ///< Pointer to the lecture data.
115 QString m_levelUpSound; ///< URL of the level up sound.
116 QString m_levelDownSound; ///< URL of the level down sound.
117 QString m_typeWriterSound; ///< URL of the typing sound.
120 #endif // KTOUCHTRAINER_H