summaryrefslogtreecommitdiffstats
path: root/ktouch/src/ktouchkeys.h
blob: df19b56dfd1452b0da25495c8eaae0ef6b008d60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/***************************************************************************
 *   ktouchkeys.h                                                          *
 *   ------------                                                          *
 *   Copyright (C) 2000 by Håvard Frøiland, 2003 by Andreas Nicolai        *
 *   ghorwin@users.sourceforge.net                                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef KTOUCHKEYS_H
#define KTOUCHKEYS_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <tqpainter.h>

class KTouchFingerKey;
class KTouchNormalKey;
class KTouchControlKey;

/** This is the base class for all keys (KTouchFingerKey, KTouchNormalKey and KTouchControlKey).
 *  Do not create instances of KTouchKey itself or you will get only blank keys. Note that the
 *  KTouchKey class hierarchy contains only the information for painting the keys. The connectivity
 *  is handled using the KTouchKeyConnector.
 */
class KTouchBaseKey {
  public:
    /// The possible types of the keys
    enum KeyType { FINGER_KEY, NORMAL_KEY, CONTROL_KEY };

    /// Constructor
    KTouchBaseKey(const TQChar& keyChar, const TQString& keyText, int x, int y, int w, int h)
      : m_keyChar(keyChar), m_keyText(keyText), m_isActive(false), m_isNextKey(false),
        m_x(x), m_y(y), m_w(w), m_h(h), m_type(NORMAL_KEY) {}
    /// Destructor.
    virtual ~KTouchBaseKey() {}
    /// Paints the basic key tqshape using the painter p.
    virtual void paint(TQPainter& p) const;
    /// Recalculates the scaled position and size properties of the key.
    void resize(double scale);
    /// Returns the boundary frame of the key.
    TQRect frame()  const { return TQRect(m_x, m_y, m_w, m_h); }
    /// Returns the key type.
    KeyType type() const { return m_type; }

    TQChar   m_keyChar;      ///< The character that needs to be pressed to access this char.
    TQString m_keyText;      ///< The text on the key (may be a single char only).
    bool    m_isActive;     ///< Indicates whether the key is active (finger and control keys).
    bool    m_isNextKey;    ///< Indicates whether this is the next to be pressed key (normal and finger keys).
	TQFont   m_font;
	float   m_font_scale;
    
  protected:
    int     m_x;        ///< The x position of the key.
    int     m_y;        ///< The y position of the key.
    int     m_w;        ///< The width of the key.
    int     m_h;        ///< The height of the key.

    int     m_xS;       ///< The scaled x position of the key.
    int     m_yS;       ///< The scaled y position of the key.
    int     m_wS;       ///< The scaled width of the key.
    int     m_hS;       ///< The scaled height of the key.

    KeyType m_type;     ///< Stores the type of the key (convenience for saving of the keyboard tqlayout).
};
// ---------------------------------------------------------------------------------------



/** This is a normal keyboard key with text.
 *  The background colour of the key will be taken from the current colour scheme using the
 *  colour index (this should be the same colour as used for the corresponding finger key).
 */
class KTouchNormalKey : public KTouchBaseKey {
  public:
    /// Constructor
    KTouchNormalKey(const TQChar& keyChar, const TQString& keyText, int x, int y, int w, int h);
    /// Destructor
    virtual ~KTouchNormalKey() {}
    /// Extends the painting routine of KTouchKey (adds the text).
    void paint(TQPainter& p) const;
    /// Indicates the colour index in the colour scheme, that has to be used for this key
    /// and will be set in KTouchKeyboard::updateColors().
    unsigned int m_colorIndex;
};
// ------------------------------------------------------------------------------------



/** This is a key where a finger rests while not typing.
 *  The name is taken from the fact, that there is normally for each finger (not including the
 *  thumbs) a key on a keyboard where the finger rests while it is not "used". A finger key
 *  is basically a normal key with additional stuff in the painting routine to mark it as a
 *  finger key.
 */
class KTouchFingerKey : public KTouchNormalKey {
  public:
    /// Constructor
    KTouchFingerKey(const TQChar& keyChar, const TQString& keyText, int x, int y, int w, int h);
    /// Destructor
    ~KTouchFingerKey() { --m_fingerKeyCount; }
    /// Extends the painting algoritm of KTouchNormalKey when marked.
    void paint(TQPainter& p) const;

  private:
    static int m_fingerKeyCount;    ///< Contains the number of created finger keys (for colour generation).
};
// ------------------------------------------------------------------------------------



/** This is a special or control key.
 *  This key acts as a modifier key to a normal key (for instance a shift key) and has a
 *  different tqshape and painting routine then the normal keys. Therefore it is directly
 *  derived from KTouchKey.
 */
class KTouchControlKey : public KTouchBaseKey {
  public:
    /// Constructor
    KTouchControlKey(const TQChar& keyChar, const TQString& keyText, int x, int y, int w, int h);
    /// Extends the parents paint routine (draws the text or other fancy stuff).
    void paint(TQPainter& p) const;
};
// ------------------------------------------------------------------------------------


/// This is the key connector which represents a key or key combination that can be pressed.
 /// It associates a character with a target key and optionally a finger and/or control key.
class KTouchKeyConnection {
  public:
    /// Default constructor
    KTouchKeyConnection() : m_keyChar(0), m_targetKeyChar(0), m_fingerKeyChar(0), m_controlKeyChar(0) {}
    /// Constructor provided for convenience.
    KTouchKeyConnection(const TQChar& keyChar, const TQChar& targetKeyChar, const TQChar& fingerKeyChar,
                       const TQChar& controlKeyChar)
      : m_keyChar(keyChar), m_targetKeyChar(targetKeyChar), m_fingerKeyChar(fingerKeyChar), m_controlKeyChar(controlKeyChar) {}

    /// This is the character that has to be pressed to access this key.
    TQChar               m_keyChar;

    TQChar               m_targetKeyChar;    ///< The target character (the key the user has to press).
    TQChar               m_fingerKeyChar;    ///< The finger key (where the used finger normally rests).
    TQChar               m_controlKeyChar;   ///< The modifier key the user has to press also (for example LeftShift).
};

#endif  // KTOUCHKEYS_H