moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / ktouch / src / ktouch.h
blob22a42ae40d429ac071147dd1efe620110973f731
1 /***************************************************************************
2 * ktouch.cpp *
3 * ---------- *
4 * Copyright (C) 2000 by Håvard Frøiland, 2004 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 _KTOUCH_H_
14 #define _KTOUCH_H_
16 #ifdef HAVE_CONFIG_H
17 #include <config.h>
18 #endif
20 #include <kmainwindow.h>
21 #include <kapplication.h>
22 #include <kurl.h>
23 #include <qcolor.h>
24 #include <qstringlist.h>
25 #include <qvaluevector.h>
27 class QLabel;
28 class KToggleAction;
29 class KActionMenu;
30 class KSelectAction;
32 class KTouchStatus;
33 class KTouchSlideLine;
34 class KTouchKeyboard;
35 class KTouchTrainer;
37 class KTouchPrefTrainingLayout;
38 class KTouchPrefKeyboardLayout;
39 class KTouchPrefGeneralLayout;
41 #include "ktouchlecture.h"
42 #include "ktouchcolorscheme.h"
44 /// This is the main window of KTouch.
45 ///
46 /// It handles the lecture, training data, status and all other widgets that are
47 /// needed to get the program running. Since all special tasks are delegated to the
48 /// appropriate widgets and classes, the remaining code in KTouch is basically the
49 /// startup and KAction stuff.<p>
50 /// A word about dialogs. Although we have only one preferences and one editor dialogs
51 /// we don't create them by default. Instead they are create "on first use". This
52 /// saves memory (because we don't need them always) and the startup speed increases.<p>
53 /// One central function - the keyPressEvent() - is responsable for getting the actual
54 /// typed char. But it does nothing else then delegating the character to the trainer
55 /// (KTouchTrainer), which will then process it. So the heavy work lies in the trainer
56 /// object and all the widgets.
57 class KTouch : public KMainWindow {
58 Q_OBJECT
59 public:
60 /// Constructor, creates the KTouch proggy.
61 KTouch();
62 /// Destructor, releases memory of KTouch trainer.
63 ~KTouch();
65 /// Returns the current color scheme
66 const QValueVector<KTouchColorScheme>& colorSchemes() const { return m_colorSchemes; }
67 /// Returns the available lecture files
68 const QStringList& lectureFiles() const { return m_lectureFiles; }
70 public slots:
71 /// Will be called when the "Apply"-button has been pressed in the preferences
72 /// dialog or when the user accepted the changes using the "OK"-button.
73 void applyPreferences();
74 /// Accepts a typed char.
75 void keyPressEvent(QKeyEvent *keyEvent);
77 /// Called from the configuration dialog.
78 void configOverrideLectureFontToggled(bool on);
79 /// Called from the configuration dialog.
80 void configOverrideKeyboardFontToggled(bool on);
81 /// Called from the configuration dialog.
82 void configAutoLevelChangeToggled(bool on);
84 protected:
85 /// Reimplementated to ask user whether he/she wants to abort the test
86 bool queryClose();
87 /// Reimplementated to save preferences and
88 bool queryExit();
90 public slots:
91 void fileOpenLecture(); ///< The action File->Open lecture...
92 void fileEditLecture(); ///< The action File->Edit lecture...
93 void fileQuit(); ///< The action File->Quit
94 void trainingNewSession(); ///< The action Training->Start new training session...
95 void trainingContinue(); ///< The action Training->Continue training
96 void trainingPause(); ///< The action Training->Pause training
97 void trainingStatistics(); ///< The action Training->Show training statistics...
98 void optionsPreferences(); ///< The action Settings->Configure KTouch...
100 /// Updates the status bar text.
101 void changeStatusbarMessage(const QString& text);
102 /// Updates the status bar statistics.
103 void changeStatusbarStats(unsigned int correctChars, unsigned int totalChars, unsigned int words);
104 /// Quick-changes the keyboard layout (called from menu).
105 void changeKeyboard(int num);
106 /// Quick-changes the colour scheme used on the keyboard (called from menu).
107 void changeColor(int num);
108 /// Quick-changes the current training lecture file (called from menu).
109 void changeLecture(int num);
111 private:
112 // *** BEGIN - Session management ***
113 /// Will be called when this app is restored due to session management.
114 void readProperties(KConfig *config);
115 /// Will be called when the app should save its state for session management purposes.
116 void saveProperties(KConfig *config);
117 // *** END - Session management ***
119 /// Initialises the program during a normal startup
120 void init();
121 /// Creates the layout and GUI setup for a practice session
122 void initTrainingSession();
123 /// Creates the (standard) actions and entries in the menu.
124 void setupActions();
125 /// This function updates the font used in the sliding line of a font suggestions was
126 /// made for the current lecture.
127 /// Call this function whenever you have read a new lecture file to update
128 /// the slide line widget.
129 void updateFontFromLecture();
130 /// This function populates the file lists with the installed training, keyboard and
131 /// examination files.
132 void updateFileLists();
133 /// Creates some default color schemes.
134 void createDefaultColorSchemes();
135 /// Updates the check mark in the lecture-quick-selection menu depending on the
136 /// lecture in Prefs::currentLectureFile().
137 void updateLectureActionCheck();
139 // *** Public member variables ***
140 KAction *m_trainingContinue; ///< Action for "continue training session".
141 KAction *m_trainingPause; ///< Action for "pause training session".
143 KSelectAction *m_keyboardLayoutAction;
144 KSelectAction *m_keyboardColorAction;
145 KSelectAction *m_defaultLectureAction;
147 KTouchStatus *m_statusWidget; ///< Pointer to the status widget on top of the main widget.
148 KTouchSlideLine *m_slideLineWidget; ///< Pointer to the sliding line widget.
149 KTouchKeyboard *m_keyboardWidget; ///< Pointer to the keyboard widget.
150 KTouchTrainer *m_trainer; ///< The training 'master' (runs the training).
151 KTouchLecture m_lecture; ///< The lecture data.
153 KTouchPrefGeneralLayout * m_pageGeneral; ///< The general configuration page.
154 KTouchPrefTrainingLayout * m_pageTraining; ///< The training configuration page.
155 KTouchPrefKeyboardLayout * m_pageKeyboard; ///< The keyboard configuration page.
157 QLabel *m_barStatsLabel; ///< The textlabel in the status bar displaying the correct number of typed chars.
159 QStringList m_lectureFiles; ///< A list of all default lecture files.
160 QStringList m_lectureTitles; ///< A list of the titles of all default lecture files.
162 QStringList m_examinationFiles; ///< A list of all default examination files.
163 QStringList m_examinationTitles; ///< A list of the titles of all default examination files.
165 QStringList m_keyboardFiles; ///< A list of all default keyboard layout files.
166 QStringList m_keyboardTitles; ///< A list of the titles of all default keyboard layout files.
168 QValueVector<KTouchColorScheme> m_colorSchemes; ///< Contains all colour schemes.
171 /// A global pointer to the main widget (actually only used to retrieve some data).
172 extern KTouch * KTouchPtr;
174 #endif // _KTOUCH_H_