moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / ktouch / src / ktouchkeys.h
blob68a079ef69348d4d687f9a6a7b5c5a1e3835010e
1 /***************************************************************************
2 * ktouchkeys.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 KTOUCHKEYS_H
14 #define KTOUCHKEYS_H
16 #include <qpainter.h>
18 class KTouchFingerKey;
19 class KTouchNormalKey;
20 class KTouchControlKey;
22 /** This is the base class for all keys (KTouchFingerKey, KTouchNormalKey and KTouchControlKey).
23 * Do not create instances of KTouchKey itself or you will get only blank keys. Note that the
24 * KTouchKey class hierarchy contains only the information for painting the keys. The connectivity
25 * is handled using the KTouchKeyConnector.
27 class KTouchKey {
28 public:
29 /// The possible types of the keys
30 enum KeyType { FINGER_KEY, NORMAL_KEY, CONTROL_KEY };
32 /// Constructor
33 KTouchKey(const QChar& keyChar, const QString& keyText, int x, int y, int w, int h)
34 : m_keyChar(keyChar), m_keyText(keyText), m_isActive(false), m_isNextKey(false),
35 m_x(x), m_y(y), m_w(w), m_h(h), m_type(NORMAL_KEY) {};
36 /// Destructor.
37 virtual ~KTouchKey() {};
38 /// Paints the basic key shape using the painter p.
39 virtual void paint(QPainter& p) const;
40 /// Recalculates the scaled position and size properties of the key.
41 void resize(double scale);
42 /// Returns the boundary frame of the key.
43 QRect frame() const { return QRect(m_x, m_y, m_w, m_h); };
44 /// Returns the key type.
45 KeyType type() const { return m_type; };
47 QChar m_keyChar; ///< The character that needs to be pressed to access this char.
48 QString m_keyText; ///< The text on the key (may be a single char only).
49 bool m_isActive; ///< Indicates whether the key is active (finger and control keys).
50 bool m_isNextKey; ///< Indicates whether this is the next to be pressed key (normal and finger keys).
51 QFont m_font;
52 float m_font_scale;
54 protected:
55 int m_x; ///< The x position of the key.
56 int m_y; ///< The y position of the key.
57 int m_w; ///< The width of the key.
58 int m_h; ///< The height of the key.
60 int m_xS; ///< The scaled x position of the key.
61 int m_yS; ///< The scaled y position of the key.
62 int m_wS; ///< The scaled width of the key.
63 int m_hS; ///< The scaled height of the key.
65 KeyType m_type; ///< Stores the type of the key (convenience for saving of the keyboard layout).
67 // ---------------------------------------------------------------------------------------
71 /** This is a normal keyboard key with text.
72 * The background colour of the key will be taken from the current colour scheme using the
73 * colour index (this should be the same colour as used for the corresponding finger key).
75 class KTouchNormalKey : public KTouchKey {
76 public:
77 /// Constructor
78 KTouchNormalKey(const QChar& keyChar, const QString& keyText, int x, int y, int w, int h);
79 /// Destructor
80 virtual ~KTouchNormalKey() {};
81 /// Extends the painting routine of KTouchKey (adds the text).
82 void paint(QPainter& p) const;
83 /// Indicates the colour index in the colour scheme, that has to be used for this key
84 /// and will be set in KTouchKeyboard::updateColors().
85 unsigned int m_colorIndex;
87 // ------------------------------------------------------------------------------------
91 /** This is a key where a finger rests while not typing.
92 * The name is taken from the fact, that there is normally for each finger (not including the
93 * thumbs) a key on a keyboard where the finger rests while it is not "used". A finger key
94 * is basically a normal key with additional stuff in the painting routine to mark it as a
95 * finger key.
97 class KTouchFingerKey : public KTouchNormalKey {
98 public:
99 /// Constructor
100 KTouchFingerKey(const QChar& keyChar, const QString& keyText, int x, int y, int w, int h);
101 /// Destructor
102 ~KTouchFingerKey() { --m_fingerKeyCount; };
103 /// Extends the painting algoritm of KTouchNormalKey when marked.
104 void paint(QPainter& p) const;
106 private:
107 static int m_fingerKeyCount; ///< Contains the number of created finger keys (for colour generation).
109 // ------------------------------------------------------------------------------------
113 /** This is a special or control key.
114 * This key acts as a modifier key to a normal key (for instance a shift key) and has a
115 * different shape and painting routine then the normal keys. Therefore it is directly
116 * derived from KTouchKey.
118 class KTouchControlKey : public KTouchKey {
119 public:
120 /// Constructor
121 KTouchControlKey(const QChar& keyChar, const QString& keyText, int x, int y, int w, int h);
122 /// Extends the parents paint routine (draws the text or other fancy stuff).
123 void paint(QPainter& p) const;
125 // ------------------------------------------------------------------------------------
127 #endif // KTOUCHKEYS_H