1 /***************************************************************************
4 * Copyright (C) 2000 by Håvard Frøiland, 2004 by Andreas Nicolai *
5 * ghorwin@users.sourceforge.net *
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 #include "ktouchkeys.h"
15 #include <algorithm> // for std::min
20 // Initialisation of static variables
21 int KTouchFingerKey::m_fingerKeyCount
= 0;
22 // -----------------------------------------------------------------------------
25 // ***** Implementation of class KTouchKey ****
27 void KTouchKey::paint(QPainter
& p
) const {
28 // We simply paint the key using the current brush and pen, so the derived classes
29 // will have to care about that
30 p
.fillRect(m_xS
, m_yS
, m_wS
, m_hS
, p
.brush());
31 p
.drawRect(m_xS
, m_yS
, m_wS
, m_hS
);
34 void KTouchKey::resize(double scale
) {
35 m_xS
= static_cast<int>(scale
*m_x
);
36 m_yS
= static_cast<int>(scale
*m_y
);
37 m_wS
= static_cast<int>(scale
*m_w
);
38 m_hS
= static_cast<int>(scale
*m_h
);
39 // we set the font from the keyboard widget
40 m_font
=Prefs::keyboardFont();
41 m_font
.setPointSize( static_cast<int>(std::min(m_wS
,m_hS
)/m_font_scale
) );
43 // -----------------------------------------------------------------------------
47 // **** Implementation of class KTouchNormalKey ****
49 KTouchNormalKey::KTouchNormalKey(const QChar
& keyChar
, const QString
& keyText
, int x
, int y
, int w
, int h
)
50 : KTouchKey(keyChar
, keyText
, x
, y
, w
, h
), m_colorIndex(0)
56 void KTouchNormalKey::paint(QPainter
& p
) const {
57 const KTouchColorScheme
& colorScheme
= KTouchPtr
->colorSchemes()[Prefs::colorScheme()];
60 // mark the key as "next"
61 p
.setBrush( colorScheme
.m_backgroundH
);
62 p
.setPen( colorScheme
.m_frame
);
63 textColor
= colorScheme
.m_textH
;
66 p
.setBrush( colorScheme
.m_background
[m_colorIndex
] );
67 p
.setPen( colorScheme
.m_frame
);
68 textColor
= colorScheme
.m_text
;
70 KTouchKey::paint(p
); // call the parents paint() function
74 p
.drawText(m_xS
, m_yS
, m_wS
, m_hS
, QPainter::AlignCenter
, m_keyText
);
76 // --------------------------------------------------------------
80 // **** Implementation of class KTouchFingerKey ****
82 KTouchFingerKey::KTouchFingerKey(const QChar
& keyChar
, const QString
& keyText
, int x
, int y
, int w
, int h
)
83 : KTouchNormalKey(keyChar
, keyText
, x
, y
, w
, h
)
85 m_colorIndex
= m_fingerKeyCount
++;
86 if (m_colorIndex
>=8) {
87 kdDebug() << "[KTouchFingerKey::KTouchFingerKey] Number of finger keys = "
88 << m_colorIndex
<< "! Setting colour index to 0" << endl
;
95 void KTouchFingerKey::paint(QPainter
& p
) const {
96 const KTouchColorScheme
& colorScheme
= KTouchPtr
->colorSchemes()[Prefs::colorScheme()];
99 p
.setBrush( colorScheme
.m_background
[m_colorIndex
] );
100 p
.setPen( colorScheme
.m_frame
);
101 KTouchKey::paint(p
); // draw background and frame
102 p
.setPen( QPen(colorScheme
.m_frame
,3) );
103 p
.drawRect(m_xS
+2, m_yS
+2, m_wS
-4, m_hS
-4); // mark it as "active"
104 p
.setPen( colorScheme
.m_text
);
105 p
.drawText(m_xS
, m_yS
, m_wS
, m_hS
, QPainter::AlignCenter
, m_keyText
);
107 else if (m_isNextKey
) {
108 p
.setBrush( colorScheme
.m_backgroundH
);
109 p
.setPen( colorScheme
.m_frame
);
111 p
.setPen( colorScheme
.m_textH
);
112 p
.drawText(m_xS
, m_yS
, m_wS
, m_hS
, QPainter::AlignCenter
, m_keyText
);
115 p
.setBrush( colorScheme
.m_background
[m_colorIndex
] );
116 p
.setPen( colorScheme
.m_frame
);
118 p
.drawRoundRect(m_xS
+2, m_yS
+2, m_wS
-4, m_hS
-4);
119 p
.setPen( colorScheme
.m_text
);
120 p
.drawText(m_xS
, m_yS
, m_wS
, m_hS
, QPainter::AlignCenter
, m_keyText
);
123 // --------------------------------------------------------------
127 // **** Implementation of class KTouchControlKey ****
129 KTouchControlKey::KTouchControlKey(const QChar
& keyChar
, const QString
& keyText
, int x
, int y
, int w
, int h
)
130 : KTouchKey(keyChar
, keyText
, x
, y
, w
, h
)
132 m_type
= CONTROL_KEY
;
136 void KTouchControlKey::paint(QPainter
& p
) const {
137 const KTouchColorScheme
& colorScheme
= KTouchPtr
->colorSchemes()[Prefs::colorScheme()];
141 p
.setBrush( colorScheme
.m_cBackgroundH
);
142 p
.setPen( colorScheme
.m_frame
);
143 textColor
= colorScheme
.m_cTextH
;
145 else if (m_isNextKey
) {
146 p
.setBrush( colorScheme
.m_backgroundH
);
147 p
.setPen( colorScheme
.m_frame
);
148 textColor
= colorScheme
.m_textH
;
151 p
.setBrush( colorScheme
.m_cBackground
);
152 p
.setPen( colorScheme
.m_frame
);
153 textColor
= colorScheme
.m_cText
;
156 p
.setPen( textColor
);
157 int h
= std::min(m_wS
, m_hS
);
158 int ch
= static_cast<int>(h
*0.5); // the height for the special chars
159 if (m_keyText
=="Shift") {
164 p
.lineTo(x
-ch
/4, y
+ch
/2);
165 p
.lineTo(x
+ch
/4, y
+ch
/2);
171 else if (m_keyText
=="CapsLock") {
176 p
.lineTo(x
-ch
/4, y
-ch
/2);
177 p
.lineTo(x
+ch
/4, y
-ch
/2);
183 else if (m_keyText
=="Tab") {
184 int xleft
= m_xS
+h
/2-ch
/2;
185 int xright
= m_xS
+ std::min(m_wS
-h
/2+ch
/2,h
);
187 p
.drawLine(xleft
, y
,xleft
, y
-ch
/2);
188 p
.drawLine(xleft
, y
-ch
/4, xright
, y
-ch
/4);
189 p
.drawLine(xleft
, y
-ch
/4, xleft
+ch
/2, y
-static_cast<int>(ch
*0.10));
190 p
.drawLine(xleft
, y
-ch
/4, xleft
+ch
/2, y
-static_cast<int>(ch
*0.40));
191 p
.drawLine(xright
, y
, xright
, y
+ch
/2);
192 p
.drawLine(xleft
, y
+ch
/4, xright
, y
+ch
/4);
193 p
.drawLine(xright
, y
+ch
/4, xright
-ch
/2, y
+static_cast<int>(ch
*0.10));
194 p
.drawLine(xright
, y
+ch
/4, xright
-ch
/2, y
+static_cast<int>(ch
*0.40));
197 else if (m_keyText
=="BackSpace") {
198 int xleft
= m_xS
+h
/2-ch
/2;
199 int xright
= m_xS
+ std::min(m_wS
-h
/2+ch
/2,h
);
201 p
.drawLine(xleft
, y
,xright
, y
);
202 p
.drawLine(xleft
, y
, xleft
+ch
/2, y
-static_cast<int>(ch
*0.15));
203 p
.drawLine(xleft
, y
, xleft
+ch
/2, y
+static_cast<int>(ch
*0.15));
205 else if (m_keyText
=="Enter") {
206 int xleft
= m_xS
+h
/2-ch
/2;
207 int xright
= m_xS
+ std::min(m_wS
-h
/2+ch
/2,h
);
209 p
.drawLine(xright
, y
-ch
/2,xright
, y
);
210 p
.drawLine(xleft
, y
,xright
, y
);
211 p
.drawLine(xleft
, y
, xleft
+ch
/3, y
-static_cast<int>(ch
*0.15));
212 p
.drawLine(xleft
, y
, xleft
+ch
/3, y
+static_cast<int>(ch
*0.15));
214 else if (m_keyText
=="AltGr") {
215 p
.drawText(m_xS
, m_yS
, m_wS
, m_hS
, QPainter::AlignCenter
| QPainter::AlignVCenter
, "Alt Gr");
218 p
.drawText(m_xS
, m_yS
, m_wS
, m_hS
, QPainter::AlignCenter
| QPainter::AlignVCenter
, m_keyText
);