summaryrefslogtreecommitdiffstats
path: root/ktouch/src/ktouchkeys.cpp
blob: 6f45d40a6d461fb32e36c540172211dc9269a716 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/***************************************************************************
 *   ktouchkeys.cpp                                                        *
 *   --------------                                                        *
 *   Copyright (C) 2000 by Håvard Frøiland, 2004 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.                                   *
 ***************************************************************************/

#include "ktouchkeys.h"
#include <kdebug.h>
#include <algorithm>  // for std::min

//#include "ktouch.h"
#include "prefs.h"
#include "ktouchcolorscheme.h"

// Initialisation of static variables
int KTouchFingerKey::m_fingerKeyCount = 0;
// -----------------------------------------------------------------------------


// ***** Implementation of class KTouchKey ****

void KTouchBaseKey::paint(TQPainter& p) const {
    // We simply paint the key using the current brush and pen, so the derived classes
    // will have to care about that
    p.fillRect(m_xS, m_yS, m_wS, m_hS, p.brush());
    p.drawRect(m_xS, m_yS, m_wS, m_hS);
}

void KTouchBaseKey::resize(double scale) {
    m_xS = static_cast<int>(scale*m_x);
    m_yS = static_cast<int>(scale*m_y);
    m_wS = static_cast<int>(scale*m_w);
    m_hS = static_cast<int>(scale*m_h);
	// we set the font from the keyboard widget
    m_font=Prefs::keyboardFont();
    m_font.setPointSize( static_cast<int>(std::min(m_wS,m_hS)/m_font_scale) );
}
// -----------------------------------------------------------------------------



// **** Implementation of class KTouchNormalKey ****

KTouchNormalKey::KTouchNormalKey(const TQChar& keyChar, const TQString& keyText, int x, int y, int w, int h)
  : KTouchBaseKey(keyChar, keyText, x, y, w, h), m_colorIndex(0)
{
    m_type = NORMAL_KEY;
    m_font_scale =2;
}

void KTouchNormalKey::paint(TQPainter& p) const {
	const KTouchColorScheme& colorScheme = KTouchColorScheme::m_colorSchemes[Prefs::currentColorScheme()];
    TQColor textColor;
    if (m_isNextKey) {
        // mark the key as "next"
        p.setBrush( colorScheme.m_backgroundH );
        p.setPen( colorScheme.m_frame );
        textColor = colorScheme.m_textH;
    }
    else {
        p.setBrush( colorScheme.m_background[m_colorIndex] );
        p.setPen( colorScheme.m_frame );
        textColor = colorScheme.m_text;
    };
    KTouchBaseKey::paint(p);  // call the tqparents paint() function
    p.setPen(textColor);
   
    p.setFont( m_font );
    p.drawText(m_xS, m_yS, m_wS, m_hS, TQPainter::AlignCenter, m_keyText);
}
// --------------------------------------------------------------



// **** Implementation of class KTouchFingerKey ****

KTouchFingerKey::KTouchFingerKey(const TQChar& keyChar, const TQString& keyText, int x, int y, int w, int h)
  : KTouchNormalKey(keyChar, keyText, x, y, w, h)
{
    m_colorIndex = m_fingerKeyCount++;
    if (m_colorIndex>=8) {
        kdDebug() << "[KTouchFingerKey::KTouchFingerKey]  Number of finger keys = "
                  << m_colorIndex << "! Setting colour index to 0" << endl;
        m_colorIndex=0;
    };
    m_type = FINGER_KEY;
    m_font_scale =2;
}

void KTouchFingerKey::paint(TQPainter& p) const {
	const KTouchColorScheme& colorScheme = KTouchColorScheme::m_colorSchemes[Prefs::currentColorScheme()];
	p.setFont( m_font );
    if (m_isActive) {
        p.setBrush( colorScheme.m_background[m_colorIndex] );
        p.setPen( colorScheme.m_frame );
        KTouchBaseKey::paint(p);                                                    // draw background and frame
        p.setPen( TQPen(colorScheme.m_frame,3) );
        p.drawRect(m_xS+2, m_yS+2, m_wS-4, m_hS-4);                             // mark it as "active"
        p.setPen( colorScheme.m_text );
        p.drawText(m_xS, m_yS, m_wS, m_hS, TQPainter::AlignCenter, m_keyText);
    }
    else if (m_isNextKey) {
        p.setBrush( colorScheme.m_backgroundH );
        p.setPen( colorScheme.m_frame );
        KTouchBaseKey::paint(p);
        p.setPen( colorScheme.m_textH );
        p.drawText(m_xS, m_yS, m_wS, m_hS, TQPainter::AlignCenter, m_keyText);
    }
    else {
        p.setBrush( colorScheme.m_background[m_colorIndex] );
        p.setPen( colorScheme.m_frame );
        KTouchBaseKey::paint(p);
        p.drawRoundRect(m_xS+2, m_yS+2, m_wS-4, m_hS-4);
        p.setPen( colorScheme.m_text );
        p.drawText(m_xS, m_yS, m_wS, m_hS, TQPainter::AlignCenter, m_keyText);
    };
}
// --------------------------------------------------------------



// **** Implementation of class KTouchControlKey ****

KTouchControlKey::KTouchControlKey(const TQChar& keyChar, const TQString& keyText, int x, int y, int w, int h)
  : KTouchBaseKey(keyChar, keyText, x, y, w, h)
{
    m_type = CONTROL_KEY;
    m_font_scale = 4;
}

void KTouchControlKey::paint(TQPainter& p) const {
	const KTouchColorScheme& colorScheme = KTouchColorScheme::m_colorSchemes[Prefs::currentColorScheme()];
    p.setFont( m_font );
    TQColor textColor;
    if (m_isActive) {
        p.setBrush( colorScheme.m_cBackgroundH );
        p.setPen( colorScheme.m_frame );
        textColor = colorScheme.m_cTextH;
    }
    else if (m_isNextKey) {
        p.setBrush( colorScheme.m_backgroundH );
        p.setPen( colorScheme.m_frame );
        textColor = colorScheme.m_textH;
    }
    else {
        p.setBrush( colorScheme.m_cBackground );
        p.setPen( colorScheme.m_frame );
        textColor = colorScheme.m_cText;
    };
    KTouchBaseKey::paint(p);
    p.setPen( textColor );
    int h = std::min(m_wS, m_hS);
    int ch = static_cast<int>(h*0.5);   // the height for the special chars
    if (m_keyText=="Shift") {
        int x = m_xS+h/2;
        int y = m_yS+m_hS/2;
        p.moveTo(x-ch/2, y);
        p.lineTo(x-ch/4, y);
        p.lineTo(x-ch/4, y+ch/2);
        p.lineTo(x+ch/4, y+ch/2);
        p.lineTo(x+ch/4, y);
        p.lineTo(x+ch/2, y);
        p.lineTo(x, y-ch/2);
        p.lineTo(x-ch/2, y);
    }
    else if (m_keyText=="CapsLock") {
        int x = m_xS+h/2;
        int y = m_yS+m_hS/2;
        p.moveTo(x-ch/2, y);
        p.lineTo(x-ch/4, y);
        p.lineTo(x-ch/4, y-ch/2);
        p.lineTo(x+ch/4, y-ch/2);
        p.lineTo(x+ch/4, y);
        p.lineTo(x+ch/2, y);
        p.lineTo(x, y+ch/2);
        p.lineTo(x-ch/2, y);
    }
    else if (m_keyText=="Tab") {
        int xleft = m_xS+h/2-ch/2;
        int xright = m_xS + std::min(m_wS-h/2+ch/2,h);
        int y = m_yS+m_hS/2;
        p.drawLine(xleft, y,xleft, y-ch/2);
        p.drawLine(xleft, y-ch/4, xright, y-ch/4);
        p.drawLine(xleft, y-ch/4, xleft+ch/2, y-static_cast<int>(ch*0.10));
        p.drawLine(xleft, y-ch/4, xleft+ch/2, y-static_cast<int>(ch*0.40));
        p.drawLine(xright, y, xright, y+ch/2);
        p.drawLine(xleft,  y+ch/4, xright, y+ch/4);
        p.drawLine(xright, y+ch/4, xright-ch/2, y+static_cast<int>(ch*0.10));
        p.drawLine(xright, y+ch/4, xright-ch/2, y+static_cast<int>(ch*0.40));

    }
    else if (m_keyText=="BackSpace") {
        int xleft = m_xS+h/2-ch/2;
        int xright = m_xS + std::min(m_wS-h/2+ch/2,h);
        int y = m_yS+m_hS/2;
        p.drawLine(xleft, y,xright, y);
        p.drawLine(xleft, y, xleft+ch/2, y-static_cast<int>(ch*0.15));
        p.drawLine(xleft, y, xleft+ch/2, y+static_cast<int>(ch*0.15));
    }
    else if (m_keyText=="Enter") {
        int xleft = m_xS+h/2-ch/2;
        int xright = m_xS + std::min(m_wS-h/2+ch/2,h);
        int y = m_yS+m_hS/2;
        p.drawLine(xright, y-ch/2,xright, y);
        p.drawLine(xleft, y,xright, y);
        p.drawLine(xleft, y, xleft+ch/3, y-static_cast<int>(ch*0.15));
        p.drawLine(xleft, y, xleft+ch/3, y+static_cast<int>(ch*0.15));
    }
    else if (m_keyText=="AltGr") {
        p.drawText(m_xS, m_yS, m_wS, m_hS, TQPainter::AlignCenter | TQPainter::AlignVCenter, "Alt Gr");
    }
    else
        p.drawText(m_xS, m_yS, m_wS, m_hS, TQPainter::AlignCenter | TQPainter::AlignVCenter, m_keyText);
}