-rw-r--r-- | inputmethods/keyboard/keyboard.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/inputmethods/keyboard/keyboard.cpp b/inputmethods/keyboard/keyboard.cpp index 9dd24e4..233f08e 100644 --- a/inputmethods/keyboard/keyboard.cpp +++ b/inputmethods/keyboard/keyboard.cpp | |||
@@ -1,794 +1,809 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "keyboard.h" | 21 | #include "keyboard.h" |
22 | 22 | ||
23 | #include <qpe/global.h> | 23 | #include <qpe/global.h> |
24 | 24 | ||
25 | #include <qwindowsystem_qws.h> | 25 | #include <qwindowsystem_qws.h> |
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qfontmetrics.h> | 27 | #include <qfontmetrics.h> |
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | #include <ctype.h> | 29 | #include <ctype.h> |
30 | 30 | ||
31 | #include <sys/utsname.h> | ||
32 | |||
31 | 33 | ||
32 | #define USE_SMALL_BACKSPACE | 34 | #define USE_SMALL_BACKSPACE |
33 | 35 | ||
34 | Keyboard::Keyboard(QWidget* parent, const char* name, WFlags f) : | 36 | Keyboard::Keyboard(QWidget* parent, const char* name, WFlags f) : |
35 | QFrame(parent, name, f), shift(FALSE), lock(FALSE), ctrl(FALSE), | 37 | QFrame(parent, name, f), shift(FALSE), lock(FALSE), ctrl(FALSE), |
36 | alt(FALSE), useLargeKeys(TRUE), useOptiKeys(0), pressedKey(-1), | 38 | alt(FALSE), useLargeKeys(TRUE), useOptiKeys(0), pressedKey(-1), |
37 | unicode(-1), qkeycode(0), modifiers(0) | 39 | unicode(-1), qkeycode(0), modifiers(0) |
38 | { | 40 | { |
39 | // setPalette(QPalette(QColor(240,240,230))); // Beige! | 41 | // setPalette(QPalette(QColor(240,240,230))); // Beige! |
40 | // setFont( QFont( "Helvetica", 8 ) ); | 42 | // setFont( QFont( "Helvetica", 8 ) ); |
41 | // setPalette(QPalette(QColor(200,200,200))); // Gray | 43 | // setPalette(QPalette(QColor(200,200,200))); // Gray |
42 | setPalette(QPalette(QColor(220,220,220))); // Gray | 44 | setPalette(QPalette(QColor(220,220,220))); // Gray |
43 | 45 | ||
44 | picks = new KeyboardPicks( this ); | 46 | picks = new KeyboardPicks( this ); |
45 | picks->setFont( QFont( "smallsmooth", 9 ) ); | 47 | picks->setFont( QFont( "smallsmooth", 9 ) ); |
46 | setFont( QFont( "smallsmooth", 9 ) ); | 48 | setFont( QFont( "smallsmooth", 9 ) ); |
47 | picks->initialise(); | 49 | picks->initialise(); |
48 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 50 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
49 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 51 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
50 | 52 | ||
51 | repeatTimer = new QTimer( this ); | 53 | repeatTimer = new QTimer( this ); |
52 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | 54 | |
55 | // temporary quick and dirty fix for the "sticky keyboard bug" | ||
56 | // on ipaq. | ||
57 | struct utsname name; | ||
58 | if (uname(&name) != -1) | ||
59 | { | ||
60 | QString release=name.release; | ||
61 | qWarning("System release: %s\n", name.release); | ||
62 | if(release.find("embedix",0,TRUE) !=-1) | ||
63 | { | ||
64 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | ||
65 | } | ||
66 | } | ||
53 | } | 67 | } |
54 | 68 | ||
55 | void Keyboard::resizeEvent(QResizeEvent*) | 69 | void Keyboard::resizeEvent(QResizeEvent*) |
56 | { | 70 | { |
57 | int ph = picks->sizeHint().height(); | 71 | int ph = picks->sizeHint().height(); |
58 | picks->setGeometry( 0, 0, width(), ph ); | 72 | picks->setGeometry( 0, 0, width(), ph ); |
59 | keyHeight = (height()-ph)/5; | 73 | keyHeight = (height()-ph)/5; |
60 | int nk; | 74 | int nk; |
61 | if ( useOptiKeys ) { | 75 | if ( useOptiKeys ) { |
62 | nk = 15; | 76 | nk = 15; |
63 | } else if ( useLargeKeys ) { | 77 | } else if ( useLargeKeys ) { |
64 | nk = 15; | 78 | nk = 15; |
65 | } else { | 79 | } else { |
66 | nk = 19; | 80 | nk = 19; |
67 | } | 81 | } |
68 | defaultKeyWidth = width()/nk; | 82 | defaultKeyWidth = width()/nk; |
69 | xoffs = (width()-defaultKeyWidth*nk)/2; | 83 | xoffs = (width()-defaultKeyWidth*nk)/2; |
70 | } | 84 | } |
71 | 85 | ||
72 | void KeyboardPicks::initialise() | 86 | void KeyboardPicks::initialise() |
73 | { | 87 | { |
74 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 88 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
75 | mode = 0; | 89 | mode = 0; |
76 | dc = new KeyboardConfig(this); | 90 | dc = new KeyboardConfig(this); |
77 | configs.append(dc); | 91 | configs.append(dc); |
78 | } | 92 | } |
79 | 93 | ||
80 | QSize KeyboardPicks::sizeHint() const | 94 | QSize KeyboardPicks::sizeHint() const |
81 | { | 95 | { |
82 | return QSize(240,fontMetrics().lineSpacing()); | 96 | return QSize(240,fontMetrics().lineSpacing()); |
83 | } | 97 | } |
84 | 98 | ||
85 | 99 | ||
86 | void KeyboardConfig::generateText(const QString &s) | 100 | void KeyboardConfig::generateText(const QString &s) |
87 | { | 101 | { |
88 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 102 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
89 | for (int i=0; i<(int)backspaces; i++) { | 103 | for (int i=0; i<(int)backspaces; i++) { |
90 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); | 104 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); |
91 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); | 105 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); |
92 | } | 106 | } |
93 | for (int i=0; i<(int)s.length(); i++) { | 107 | for (int i=0; i<(int)s.length(); i++) { |
94 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); | 108 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); |
95 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); | 109 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); |
96 | } | 110 | } |
97 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); | 111 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); |
98 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); | 112 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); |
99 | backspaces = 0; | 113 | backspaces = 0; |
100 | #endif | 114 | #endif |
101 | } | 115 | } |
102 | 116 | ||
103 | 117 | ||
104 | //PC keyboard layout and scancodes | 118 | //PC keyboard layout and scancodes |
105 | 119 | ||
106 | /* | 120 | /* |
107 | Format: length, code, length, code, ..., 0 | 121 | Format: length, code, length, code, ..., 0 |
108 | 122 | ||
109 | length is measured in half the width of a standard key. | 123 | length is measured in half the width of a standard key. |
110 | If code < 0x80 we have length/2 consecutive standard keys, | 124 | If code < 0x80 we have length/2 consecutive standard keys, |
111 | starting with scancode code. | 125 | starting with scancode code. |
112 | 126 | ||
113 | Special keys are hardcoded, one at a time, with length of key | 127 | Special keys are hardcoded, one at a time, with length of key |
114 | and code >= 0x80, these are NOT standard PC scancodes, but are looked | 128 | and code >= 0x80, these are NOT standard PC scancodes, but are looked |
115 | up in specialM[]. (The special keys are not keymappable.) | 129 | up in specialM[]. (The special keys are not keymappable.) |
116 | 130 | ||
117 | */ | 131 | */ |
118 | 132 | ||
119 | static const uchar * const keyboard_opti[5] = { | 133 | static const uchar * const keyboard_opti[5] = { |
120 | (const uchar *const) "\001\223\003\240\002\20\002\41\002\26\002\62\002\56\002\45\002\54\003\200\001\223\002\226\002\235\002\234\002\236", | 134 | (const uchar *const) "\001\223\003\240\002\20\002\41\002\26\002\62\002\56\002\45\002\54\003\200\001\223\002\226\002\235\002\234\002\236", |
121 | (const uchar *const) "\001\223\003\201\004\207\002\30\002\24\002\43\004\207\003\203\001\223\006\002\002\065", | 135 | (const uchar *const) "\001\223\003\201\004\207\002\30\002\24\002\43\004\207\003\203\001\223\006\002\002\065", |
122 | (const uchar *const) "\001\223\003\202\002\60\002\37\002\23\002\22\002\36\002\21\002\55\003\203\001\223\006\005\002\055", | 136 | (const uchar *const) "\001\223\003\202\002\60\002\37\002\23\002\22\002\36\002\21\002\55\003\203\001\223\006\005\002\055", |
123 | (const uchar *const) "\001\223\003\205\004\207\002\27\002\61\002\40\004\207\003\204\001\223\006\010\002\014", | 137 | (const uchar *const) "\001\223\003\205\004\207\002\27\002\61\002\40\004\207\003\204\001\223\006\010\002\014", |
124 | (const uchar *const) "\001\223\003\206\002\44\002\31\002\57\002\42\002\46\002\25\002\207\003\204\001\223\002\013\002\064\002\015\002\230" | 138 | (const uchar *const) "\001\223\003\206\002\44\002\31\002\57\002\42\002\46\002\25\002\207\003\204\001\223\002\013\002\064\002\015\002\230" |
125 | }; | 139 | }; |
126 | 140 | ||
127 | 141 | ||
128 | static const uchar * const keyboard_standard[5] = { | 142 | static const uchar * const keyboard_standard[5] = { |
129 | 143 | ||
130 | #ifdef USE_SMALL_BACKSPACE | 144 | #ifdef USE_SMALL_BACKSPACE |
131 | (const uchar *const)"\002\240\002`\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\002\200\002\223\002\215\002\216\002\217", | 145 | (const uchar *const)"\002\240\002`\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\002\200\002\223\002\215\002\216\002\217", |
132 | #else | 146 | #else |
133 | (const uchar *const)"\002\051\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\004\200\002\223\002\215\002\216\002\217", | 147 | (const uchar *const)"\002\051\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\004\200\002\223\002\215\002\216\002\217", |
134 | #endif | 148 | #endif |
135 | //~ + 123...+ BACKSPACE //+ INSERT + HOME + PGUP | 149 | //~ + 123...+ BACKSPACE //+ INSERT + HOME + PGUP |
136 | 150 | ||
137 | (const uchar *const)"\003\201\002q\002w\002e\002r\002t\002y\002u\002i\002o\002p\002[\002]\002\\\001\224\002\223\002\221\002\220\002\222", | 151 | (const uchar *const)"\003\201\002q\002w\002e\002r\002t\002y\002u\002i\002o\002p\002[\002]\002\\\001\224\002\223\002\221\002\220\002\222", |
138 | //TAB + qwerty.. + backslash //+ DEL + END + PGDN | 152 | //TAB + qwerty.. + backslash //+ DEL + END + PGDN |
139 | 153 | ||
140 | (const uchar *const)"\004\202\002a\002s\002d\002f\002g\002h\002j\002k\002l\002;\002'\004\203", | 154 | (const uchar *const)"\004\202\002a\002s\002d\002f\002g\002h\002j\002k\002l\002;\002'\004\203", |
141 | //CAPS + asdf.. + RETURN | 155 | //CAPS + asdf.. + RETURN |
142 | 156 | ||
143 | (const uchar *const)"\005\204\002z\002x\002c\002v\002b\002n\002m\002,\002.\002/\005\204\002\223\002\223\002\211", | 157 | (const uchar *const)"\005\204\002z\002x\002c\002v\002b\002n\002m\002,\002.\002/\005\204\002\223\002\223\002\211", |
144 | //SHIFT + zxcv... //+ UP | 158 | //SHIFT + zxcv... //+ UP |
145 | 159 | ||
146 | (const uchar *const)"\003\205\003\206\022\207\003\206\003\205\002\223\002\212\002\213\002\214" | 160 | (const uchar *const)"\003\205\003\206\022\207\003\206\003\205\002\223\002\212\002\213\002\214" |
147 | //CTRL + ALT + SPACE //+ LEFT + DOWN + RIGHT | 161 | //CTRL + ALT + SPACE //+ LEFT + DOWN + RIGHT |
148 | 162 | ||
149 | }; | 163 | }; |
150 | 164 | ||
151 | 165 | ||
152 | struct ShiftMap { | 166 | struct ShiftMap { |
153 | char normal; | 167 | char normal; |
154 | char shifted; | 168 | char shifted; |
155 | }; | 169 | }; |
156 | 170 | ||
157 | 171 | ||
158 | static const ShiftMap shiftMap[] = { | 172 | static const ShiftMap shiftMap[] = { |
159 | { '`', '~' }, | 173 | { '`', '~' }, |
160 | { '1', '!' }, | 174 | { '1', '!' }, |
161 | { '2', '@' }, | 175 | { '2', '@' }, |
162 | { '3', '#' }, | 176 | { '3', '#' }, |
163 | { '4', '$' }, | 177 | { '4', '$' }, |
164 | { '5', '%' }, | 178 | { '5', '%' }, |
165 | { '6', '^' }, | 179 | { '6', '^' }, |
166 | { '7', '&' }, | 180 | { '7', '&' }, |
167 | { '8', '*' }, | 181 | { '8', '*' }, |
168 | { '9', '(' }, | 182 | { '9', '(' }, |
169 | { '0', ')' }, | 183 | { '0', ')' }, |
170 | { '-', '_' }, | 184 | { '-', '_' }, |
171 | { '=', '+' }, | 185 | { '=', '+' }, |
172 | { '\\', '|' }, | 186 | { '\\', '|' }, |
173 | { '[', '{' }, | 187 | { '[', '{' }, |
174 | { ']', '}' }, | 188 | { ']', '}' }, |
175 | { ';', ':' }, | 189 | { ';', ':' }, |
176 | { '\'', '"' }, | 190 | { '\'', '"' }, |
177 | { ',', '<' }, | 191 | { ',', '<' }, |
178 | { '.', '>' }, | 192 | { '.', '>' }, |
179 | { '/', '?' } | 193 | { '/', '?' } |
180 | }; | 194 | }; |
181 | 195 | ||
182 | 196 | ||
183 | /* XPM */ | 197 | /* XPM */ |
184 | static const char * const uparrow_xpm[]={ | 198 | static const char * const uparrow_xpm[]={ |
185 | "9 9 2 1", | 199 | "9 9 2 1", |
186 | "a c #000000", | 200 | "a c #000000", |
187 | ". c None", | 201 | ". c None", |
188 | ".........", | 202 | ".........", |
189 | "....a....", | 203 | "....a....", |
190 | "...aaa...", | 204 | "...aaa...", |
191 | "..aaaaa..", | 205 | "..aaaaa..", |
192 | "....a....", | 206 | "....a....", |
193 | "....a....", | 207 | "....a....", |
194 | "....a....", | 208 | "....a....", |
195 | "....a....", | 209 | "....a....", |
196 | "........."}; | 210 | "........."}; |
197 | /* XPM */ | 211 | /* XPM */ |
198 | static const char * const leftarrow_xpm[]={ | 212 | static const char * const leftarrow_xpm[]={ |
199 | "9 9 2 1", | 213 | "9 9 2 1", |
200 | "a c #000000", | 214 | "a c #000000", |
201 | ". c None", | 215 | ". c None", |
202 | ".........", | 216 | ".........", |
203 | ".........", | 217 | ".........", |
204 | "...a.....", | 218 | "...a.....", |
205 | "..aa.....", | 219 | "..aa.....", |
206 | ".aaaaaaa.", | 220 | ".aaaaaaa.", |
207 | "..aa.....", | 221 | "..aa.....", |
208 | "...a.....", | 222 | "...a.....", |
209 | ".........", | 223 | ".........", |
210 | "........."}; | 224 | "........."}; |
211 | /* XPM */ | 225 | /* XPM */ |
212 | static const char * const downarrow_xpm[]={ | 226 | static const char * const downarrow_xpm[]={ |
213 | "9 9 2 1", | 227 | "9 9 2 1", |
214 | "a c #000000", | 228 | "a c #000000", |
215 | ". c None", | 229 | ". c None", |
216 | ".........", | 230 | ".........", |
217 | "....a....", | 231 | "....a....", |
218 | "....a....", | 232 | "....a....", |
219 | "....a....", | 233 | "....a....", |
220 | "....a....", | 234 | "....a....", |
221 | "..aaaaa..", | 235 | "..aaaaa..", |
222 | "...aaa...", | 236 | "...aaa...", |
223 | "....a....", | 237 | "....a....", |
224 | "........."}; | 238 | "........."}; |
225 | /* XPM */ | 239 | /* XPM */ |
226 | static const char * const rightarrow_xpm[]={ | 240 | static const char * const rightarrow_xpm[]={ |
227 | "9 9 2 1", | 241 | "9 9 2 1", |
228 | "a c #000000", | 242 | "a c #000000", |
229 | ". c None", | 243 | ". c None", |
230 | ".........", | 244 | ".........", |
231 | ".........", | 245 | ".........", |
232 | ".....a...", | 246 | ".....a...", |
233 | ".....aa..", | 247 | ".....aa..", |
234 | ".aaaaaaa.", | 248 | ".aaaaaaa.", |
235 | ".....aa..", | 249 | ".....aa..", |
236 | ".....a...", | 250 | ".....a...", |
237 | ".........", | 251 | ".........", |
238 | "........."}; | 252 | "........."}; |
239 | /* XPM */ | 253 | /* XPM */ |
240 | static const char * const insert_xpm[]={ | 254 | static const char * const insert_xpm[]={ |
241 | "9 9 2 1", | 255 | "9 9 2 1", |
242 | "a c #000000", | 256 | "a c #000000", |
243 | ". c None", | 257 | ". c None", |
244 | ".........", | 258 | ".........", |
245 | "a........", | 259 | "a........", |
246 | "a.aaa.aaa", | 260 | "a.aaa.aaa", |
247 | "a.a.a.a..", | 261 | "a.a.a.a..", |
248 | "a.a.a..a.", | 262 | "a.a.a..a.", |
249 | "a.a.a...a", | 263 | "a.a.a...a", |
250 | "a.a.a.aaa", | 264 | "a.a.a.aaa", |
251 | ".........", | 265 | ".........", |
252 | "........."}; | 266 | "........."}; |
253 | /* XPM */ | 267 | /* XPM */ |
254 | static const char * const delete_xpm[]={ | 268 | static const char * const delete_xpm[]={ |
255 | "9 9 2 1", | 269 | "9 9 2 1", |
256 | "a c #000000", | 270 | "a c #000000", |
257 | ". c None", | 271 | ". c None", |
258 | ".........", | 272 | ".........", |
259 | "aa......a", | 273 | "aa......a", |
260 | "a.a.aaa.a", | 274 | "a.a.aaa.a", |
261 | "a.a.a.a.a", | 275 | "a.a.a.a.a", |
262 | "a.a.aaa.a.", | 276 | "a.a.aaa.a.", |
263 | "a.a.a...a", | 277 | "a.a.a...a", |
264 | "aaa.aaa.a", | 278 | "aaa.aaa.a", |
265 | ".........", | 279 | ".........", |
266 | "........."}; | 280 | "........."}; |
267 | /* XPM */ | 281 | /* XPM */ |
268 | static const char * const home_xpm[]={ | 282 | static const char * const home_xpm[]={ |
269 | "9 9 2 1", | 283 | "9 9 2 1", |
270 | "a c #000000", | 284 | "a c #000000", |
271 | ". c None", | 285 | ". c None", |
272 | "....a....", | 286 | "....a....", |
273 | "...a.a...", | 287 | "...a.a...", |
274 | "..a...a..", | 288 | "..a...a..", |
275 | ".a.....a.", | 289 | ".a.....a.", |
276 | "aa.aaa.aa", | 290 | "aa.aaa.aa", |
277 | ".a.a.a.a.", | 291 | ".a.a.a.a.", |
278 | ".a.a.a.a.", | 292 | ".a.a.a.a.", |
279 | ".aaaaaaa.", | 293 | ".aaaaaaa.", |
280 | "........."}; | 294 | "........."}; |
281 | /* XPM */ | 295 | /* XPM */ |
282 | static const char * const end_xpm[]={ | 296 | static const char * const end_xpm[]={ |
283 | "10 9 2 1", | 297 | "10 9 2 1", |
284 | "a c #000000", | 298 | "a c #000000", |
285 | ". c None", | 299 | ". c None", |
286 | "..........", | 300 | "..........", |
287 | "aa.......a", | 301 | "aa.......a", |
288 | "a..aaa.aaa", | 302 | "a..aaa.aaa", |
289 | "aa.a.a.a.a", | 303 | "aa.a.a.a.a", |
290 | "a..a.a.a.a", | 304 | "a..a.a.a.a", |
291 | "a..a.a.a.a", | 305 | "a..a.a.a.a", |
292 | "aa.a.a.aaa", | 306 | "aa.a.a.aaa", |
293 | "..........", | 307 | "..........", |
294 | ".........."}; | 308 | ".........."}; |
295 | /* XPM */ | 309 | /* XPM */ |
296 | static const char * const pageup_xpm[]={ | 310 | static const char * const pageup_xpm[]={ |
297 | "9 9 2 1", | 311 | "9 9 2 1", |
298 | "a c #000000", | 312 | "a c #000000", |
299 | ". c None", | 313 | ". c None", |
300 | ".aaa.aaa.", | 314 | ".aaa.aaa.", |
301 | ".a.a.a.a.", | 315 | ".a.a.a.a.", |
302 | ".aaa..aa.", | 316 | ".aaa..aa.", |
303 | ".a...aaa.", | 317 | ".a...aaa.", |
304 | ".........", | 318 | ".........", |
305 | ".a.a.aaa.", | 319 | ".a.a.aaa.", |
306 | ".a.a.a.a.", | 320 | ".a.a.a.a.", |
307 | ".aaa.aaa.", | 321 | ".aaa.aaa.", |
308 | ".....a..."}; | 322 | ".....a..."}; |
309 | /* XPM */ | 323 | /* XPM */ |
310 | static const char * const pagedown_xpm[]={ | 324 | static const char * const pagedown_xpm[]={ |
311 | "9 9 2 1", | 325 | "9 9 2 1", |
312 | "a c #000000", | 326 | "a c #000000", |
313 | ". c None", | 327 | ". c None", |
314 | ".aaa.aaa.", | 328 | ".aaa.aaa.", |
315 | ".a.a.a.a.", | 329 | ".a.a.a.a.", |
316 | ".aaa..aa.", | 330 | ".aaa..aa.", |
317 | ".a...aaa.", | 331 | ".a...aaa.", |
318 | ".........", | 332 | ".........", |
319 | "...a.....", | 333 | "...a.....", |
320 | ".aaa.aaa.", | 334 | ".aaa.aaa.", |
321 | ".a.a.a.a.", | 335 | ".a.a.a.a.", |
322 | ".aaa.a.a."}; | 336 | ".aaa.a.a."}; |
323 | /* XPM */ | 337 | /* XPM */ |
324 | static const char * const expand_xpm[]={ | 338 | static const char * const expand_xpm[]={ |
325 | "4 9 2 1", | 339 | "4 9 2 1", |
326 | "a c #408040", | 340 | "a c #408040", |
327 | ". c None", | 341 | ". c None", |
328 | "a...", | 342 | "a...", |
329 | "aa..", | 343 | "aa..", |
330 | "aaa.", | 344 | "aaa.", |
331 | "aaaa", | 345 | "aaaa", |
332 | "aaaa", | 346 | "aaaa", |
333 | "aaaa", | 347 | "aaaa", |
334 | "aaa.", | 348 | "aaa.", |
335 | "aa..", | 349 | "aa..", |
336 | "a..."}; | 350 | "a..."}; |
337 | /* XPM */ | 351 | /* XPM */ |
338 | #ifdef USE_SMALL_BACKSPACE | 352 | #ifdef USE_SMALL_BACKSPACE |
339 | static const char * const backspace_xpm[]={ | 353 | static const char * const backspace_xpm[]={ |
340 | "9 9 2 1", | 354 | "9 9 2 1", |
341 | "a c #000000", | 355 | "a c #000000", |
342 | ". c None", | 356 | ". c None", |
343 | ".........", | 357 | ".........", |
344 | ".........", | 358 | ".........", |
345 | "...a.....", | 359 | "...a.....", |
346 | "..aa.....", | 360 | "..aa.....", |
347 | ".aaaaaaaa", | 361 | ".aaaaaaaa", |
348 | "..aa.....", | 362 | "..aa.....", |
349 | "...a.....", | 363 | "...a.....", |
350 | ".........", | 364 | ".........", |
351 | "........."}; | 365 | "........."}; |
352 | #else | 366 | #else |
353 | static const char * const backspace_xpm[]={ | 367 | static const char * const backspace_xpm[]={ |
354 | "21 9 2 1", | 368 | "21 9 2 1", |
355 | "a c #000000", | 369 | "a c #000000", |
356 | ". c None", | 370 | ". c None", |
357 | ".....................", | 371 | ".....................", |
358 | ".....................", | 372 | ".....................", |
359 | ".....aaa..a..........", | 373 | ".....aaa..a..........", |
360 | ".a...a..a.a.a.aaa.aaa", | 374 | ".a...a..a.a.a.aaa.aaa", |
361 | "aaaa.aaa..aa..aa..a.a", | 375 | "aaaa.aaa..aa..aa..a.a", |
362 | ".a...a..a.aaa..aa.a.a", | 376 | ".a...a..a.aaa..aa.a.a", |
363 | ".....aaaa.a.a.aaa.aa.", | 377 | ".....aaaa.a.a.aaa.aa.", |
364 | "..................a..", | 378 | "..................a..", |
365 | "....................."}; | 379 | "....................."}; |
366 | #endif | 380 | #endif |
367 | /* XPM */ | 381 | /* XPM */ |
368 | static const char * const escape_xpm[]={ | 382 | static const char * const escape_xpm[]={ |
369 | "9 9 2 1", | 383 | "9 9 2 1", |
370 | "a c #000000", | 384 | "a c #000000", |
371 | ". c None", | 385 | ". c None", |
372 | ".........", | 386 | ".........", |
373 | ".........", | 387 | ".........", |
374 | ".aa.aa.aa", | 388 | ".aa.aa.aa", |
375 | ".a..a..a.", | 389 | ".a..a..a.", |
376 | ".aa.aa.a.", | 390 | ".aa.aa.a.", |
377 | ".a...a.a.", | 391 | ".a...a.a.", |
378 | ".aa.aa.aa", | 392 | ".aa.aa.aa", |
379 | ".........", | 393 | ".........", |
380 | "........."}; | 394 | "........."}; |
381 | 395 | ||
382 | 396 | ||
383 | enum { BSCode = 0x80, TabCode, CapsCode, RetCode, | 397 | enum { BSCode = 0x80, TabCode, CapsCode, RetCode, |
384 | ShiftCode, CtrlCode, AltCode, SpaceCode, BackSlash, | 398 | ShiftCode, CtrlCode, AltCode, SpaceCode, BackSlash, |
385 | UpCode, LeftCode, DownCode, RightCode, Blank, Expand, | 399 | UpCode, LeftCode, DownCode, RightCode, Blank, Expand, |
386 | Opti, ResetDict, | 400 | Opti, ResetDict, |
387 | Divide, Multiply, Add, Subtract, Decimal, Equal, | 401 | Divide, Multiply, Add, Subtract, Decimal, Equal, |
388 | Percent, Sqrt, Inverse, Escape }; | 402 | Percent, Sqrt, Inverse, Escape }; |
389 | 403 | ||
390 | typedef struct SpecialMap { | 404 | typedef struct SpecialMap { |
391 | int qcode; | 405 | int qcode; |
392 | ushort unicode; | 406 | ushort unicode; |
393 | const char * label; | 407 | const char * label; |
394 | const char * const * xpm; | 408 | const char * const * xpm; |
395 | }; | 409 | }; |
396 | 410 | ||
397 | 411 | ||
398 | static const SpecialMap specialM[] = { | 412 | static const SpecialMap specialM[] = { |
399 | { Qt::Key_Backspace, 8,"<", backspace_xpm }, | 413 | { Qt::Key_Backspace, 8,"<", backspace_xpm }, |
400 | { Qt::Key_Tab, 9,"Tab", NULL }, | 414 | { Qt::Key_Tab, 9,"Tab", NULL }, |
401 | { Qt::Key_CapsLock, 0,"Caps", NULL }, | 415 | { Qt::Key_CapsLock, 0,"Caps", NULL }, |
402 | { Qt::Key_Return, 13,"Ret", NULL }, | 416 | { Qt::Key_Return, 13,"Ret", NULL }, |
403 | { Qt::Key_Shift, 0,"Shift", NULL }, | 417 | { Qt::Key_Shift, 0,"Shift", NULL }, |
404 | { Qt::Key_Control, 0,"Ctrl", NULL }, | 418 | { Qt::Key_Control, 0,"Ctrl", NULL }, |
405 | { Qt::Key_Alt, 0,"Alt", NULL }, | 419 | { Qt::Key_Alt, 0,"Alt", NULL }, |
406 | { Qt::Key_Space, ' ',"", NULL }, | 420 | { Qt::Key_Space, ' ',"", NULL }, |
407 | { BackSlash, 43,"\\", NULL }, | 421 | { BackSlash, 43,"\\", NULL }, |
408 | 422 | ||
409 | // Need images? | 423 | // Need images? |
410 | { Qt::Key_Up, 0,"^", uparrow_xpm }, | 424 | { Qt::Key_Up, 0,"^", uparrow_xpm }, |
411 | { Qt::Key_Left, 0,"<", leftarrow_xpm }, | 425 | { Qt::Key_Left, 0,"<", leftarrow_xpm }, |
412 | { Qt::Key_Down, 0,"v", downarrow_xpm }, | 426 | { Qt::Key_Down, 0,"v", downarrow_xpm }, |
413 | { Qt::Key_Right, 0,">", rightarrow_xpm }, | 427 | { Qt::Key_Right, 0,">", rightarrow_xpm }, |
414 | { Qt::Key_Insert, 0,"I", insert_xpm }, | 428 | { Qt::Key_Insert, 0,"I", insert_xpm }, |
415 | { Qt::Key_Home, 0,"H", home_xpm }, | 429 | { Qt::Key_Home, 0,"H", home_xpm }, |
416 | { Qt::Key_PageUp, 0,"U", pageup_xpm }, | 430 | { Qt::Key_PageUp, 0,"U", pageup_xpm }, |
417 | { Qt::Key_End, 0,"E", end_xpm }, | 431 | { Qt::Key_End, 0,"E", end_xpm }, |
418 | { Qt::Key_Delete, 0,"X", delete_xpm }, | 432 | { Qt::Key_Delete, 0,"X", delete_xpm }, |
419 | { Qt::Key_PageDown, 0,"D", pagedown_xpm }, | 433 | { Qt::Key_PageDown, 0,"D", pagedown_xpm }, |
420 | { Blank, 0," ", NULL }, | 434 | { Blank, 0," ", NULL }, |
421 | { Expand, 0,"->", expand_xpm }, | 435 | { Expand, 0,"->", expand_xpm }, |
422 | { Opti, 0,"#", NULL }, | 436 | { Opti, 0,"#", NULL }, |
423 | { ResetDict, 0,"R", NULL }, | 437 | { ResetDict, 0,"R", NULL }, |
424 | 438 | ||
425 | // number pad stuff | 439 | // number pad stuff |
426 | { Divide, 0,"/", NULL }, | 440 | { Divide, 0,"/", NULL }, |
427 | { Multiply, 0,"*", NULL }, | 441 | { Multiply, 0,"*", NULL }, |
428 | { Add, 0,"+", NULL }, | 442 | { Add, 0,"+", NULL }, |
429 | { Subtract, 0,"-", NULL }, | 443 | { Subtract, 0,"-", NULL }, |
430 | { Decimal, 0,".", NULL }, | 444 | { Decimal, 0,".", NULL }, |
431 | { Equal, 0,"=", NULL }, | 445 | { Equal, 0,"=", NULL }, |
432 | { Percent, 0,"%", NULL }, | 446 | { Percent, 0,"%", NULL }, |
433 | { Sqrt, 0, "^1/2", NULL }, | 447 | { Sqrt, 0, "^1/2", NULL }, |
434 | { Inverse, 0, "1/x", NULL }, | 448 | { Inverse, 0, "1/x", NULL }, |
435 | 449 | ||
436 | { Escape, 27, "ESC", escape_xpm } | 450 | { Escape, 27, "ESC", escape_xpm } |
437 | }; | 451 | }; |
438 | 452 | ||
439 | 453 | ||
440 | static int keycode( int i2, int j, const uchar **keyboard ) | 454 | static int keycode( int i2, int j, const uchar **keyboard ) |
441 | { | 455 | { |
442 | if ( j <0 || j >= 5 ) | 456 | if ( j <0 || j >= 5 ) |
443 | return 0; | 457 | return 0; |
444 | 458 | ||
445 | const uchar *row = keyboard[j]; | 459 | const uchar *row = keyboard[j]; |
446 | 460 | ||
447 | while ( *row && *row <= i2 ) { | 461 | while ( *row && *row <= i2 ) { |
448 | i2 -= *row; | 462 | i2 -= *row; |
449 | row += 2; | 463 | row += 2; |
450 | } | 464 | } |
451 | 465 | ||
452 | if ( !*row ) return 0; | 466 | if ( !*row ) return 0; |
453 | 467 | ||
454 | int k; | 468 | int k; |
455 | if ( row[1] >= 0x80 ) { | 469 | if ( row[1] >= 0x80 ) { |
456 | k = row[1]; | 470 | k = row[1]; |
457 | } else { | 471 | } else { |
458 | k = row[1]+i2/2; | 472 | k = row[1]+i2/2; |
459 | } | 473 | } |
460 | 474 | ||
461 | return k; | 475 | return k; |
462 | } | 476 | } |
463 | 477 | ||
464 | 478 | ||
465 | /* | 479 | /* |
466 | return scancode and width of first key in row \a j if \a j >= 0, | 480 | return scancode and width of first key in row \a j if \a j >= 0, |
467 | or next key on current row if \a j < 0. | 481 | or next key on current row if \a j < 0. |
468 | 482 | ||
469 | */ | 483 | */ |
470 | 484 | ||
471 | int Keyboard::getKey( int &w, int j ) { | 485 | int Keyboard::getKey( int &w, int j ) { |
472 | static const uchar *row = 0; | 486 | static const uchar *row = 0; |
473 | static int key_i = 0; | 487 | static int key_i = 0; |
474 | static int scancode = 0; | 488 | static int scancode = 0; |
475 | static int half = 0; | 489 | static int half = 0; |
476 | 490 | ||
477 | if ( j >= 0 && j < 5 ) { | 491 | if ( j >= 0 && j < 5 ) { |
478 | if (useOptiKeys) | 492 | if (useOptiKeys) |
479 | row = keyboard_opti[j]; | 493 | row = keyboard_opti[j]; |
480 | else | 494 | else |
481 | row = keyboard_standard[j]; | 495 | row = keyboard_standard[j]; |
482 | half=0; | 496 | half=0; |
483 | } | 497 | } |
484 | 498 | ||
485 | if ( !row || !*row ) { | 499 | if ( !row || !*row ) { |
486 | return 0; | 500 | return 0; |
487 | } else if ( row[1] >= 0x80 ) { | 501 | } else if ( row[1] >= 0x80 ) { |
488 | scancode = row[1]; | 502 | scancode = row[1]; |
489 | w = (row[0] * w + (half++&1)) / 2; | 503 | w = (row[0] * w + (half++&1)) / 2; |
490 | row += 2; | 504 | row += 2; |
491 | return scancode; | 505 | return scancode; |
492 | } else if ( key_i <= 0 ) { | 506 | } else if ( key_i <= 0 ) { |
493 | key_i = row[0]/2; | 507 | key_i = row[0]/2; |
494 | scancode = row[1]; | 508 | scancode = row[1]; |
495 | } | 509 | } |
496 | key_i--; | 510 | key_i--; |
497 | if ( key_i <= 0 ) | 511 | if ( key_i <= 0 ) |
498 | row += 2; | 512 | row += 2; |
499 | return scancode++; | 513 | return scancode++; |
500 | } | 514 | } |
501 | 515 | ||
502 | 516 | ||
503 | void Keyboard::paintEvent(QPaintEvent* e) | 517 | void Keyboard::paintEvent(QPaintEvent* e) |
504 | { | 518 | { |
505 | QPainter painter(this); | 519 | QPainter painter(this); |
506 | painter.setClipRect(e->rect()); | 520 | painter.setClipRect(e->rect()); |
507 | drawKeyboard( painter ); | 521 | drawKeyboard( painter ); |
508 | picks->dc->draw( &painter ); | 522 | picks->dc->draw( &painter ); |
509 | } | 523 | } |
510 | 524 | ||
511 | 525 | ||
512 | /* | 526 | /* |
513 | Draw the keyboard. | 527 | Draw the keyboard. |
514 | 528 | ||
515 | If key >= 0, only the specified key is drawn. | 529 | If key >= 0, only the specified key is drawn. |
516 | */ | 530 | */ |
517 | void Keyboard::drawKeyboard( QPainter &p, int key ) | 531 | void Keyboard::drawKeyboard( QPainter &p, int key ) |
518 | { | 532 | { |
519 | const bool threeD = FALSE; | 533 | const bool threeD = FALSE; |
520 | const QColorGroup& cg = colorGroup(); | 534 | const QColorGroup& cg = colorGroup(); |
521 | QColor keycolor = // cg.background(); | 535 | QColor keycolor = // cg.background(); |
522 | QColor(240,240,230); // Beige! | 536 | QColor(240,240,230); // Beige! |
523 | QColor keycolor_pressed = cg.mid(); | 537 | QColor keycolor_pressed = cg.mid(); |
524 | QColor keycolor_lo = cg.dark(); | 538 | QColor keycolor_lo = cg.dark(); |
525 | QColor keycolor_hi = cg.light(); | 539 | QColor keycolor_hi = cg.light(); |
526 | QColor textcolor = QColor(0,0,0); // cg.text(); | 540 | QColor textcolor = QColor(0,0,0); // cg.text(); |
527 | 541 | ||
528 | int margin = threeD ? 1 : 0; | 542 | int margin = threeD ? 1 : 0; |
529 | 543 | ||
530 | // p.fillRect( 0, , kw-1, keyHeight-2, keycolor_pressed ); | 544 | // p.fillRect( 0, , kw-1, keyHeight-2, keycolor_pressed ); |
531 | 545 | ||
532 | for ( int j = 0; j < 5; j++ ) { | 546 | for ( int j = 0; j < 5; j++ ) { |
533 | int y = j * keyHeight + picks->height() + 1; | 547 | int y = j * keyHeight + picks->height() + 1; |
534 | int x = xoffs; | 548 | int x = xoffs; |
535 | int kw = defaultKeyWidth; | 549 | int kw = defaultKeyWidth; |
536 | int k= getKey( kw, j ); | 550 | int k= getKey( kw, j ); |
537 | while ( k ) { | 551 | while ( k ) { |
538 | if ( key < 0 || k == key ) { | 552 | if ( key < 0 || k == key ) { |
539 | QString s; | 553 | QString s; |
540 | bool pressed = (k == pressedKey); | 554 | bool pressed = (k == pressedKey); |
541 | bool blank = (k == 0223); | 555 | bool blank = (k == 0223); |
542 | const char * const * xpm = NULL; | 556 | const char * const * xpm = NULL; |
543 | 557 | ||
544 | if ( k >= 0x80 ) { | 558 | if ( k >= 0x80 ) { |
545 | s = specialM[k - 0x80].label; | 559 | s = specialM[k - 0x80].label; |
546 | 560 | ||
547 | xpm = specialM[k - 0x80].xpm; | 561 | xpm = specialM[k - 0x80].xpm; |
548 | 562 | ||
549 | if ( k == ShiftCode ) { | 563 | if ( k == ShiftCode ) { |
550 | pressed = shift; | 564 | pressed = shift; |
551 | } else if ( k == CapsCode ) { | 565 | } else if ( k == CapsCode ) { |
552 | pressed = lock; | 566 | pressed = lock; |
553 | } else if ( k == CtrlCode ) { | 567 | } else if ( k == CtrlCode ) { |
554 | pressed = ctrl; | 568 | pressed = ctrl; |
555 | } else if ( k == AltCode ) { | 569 | } else if ( k == AltCode ) { |
556 | pressed = alt; | 570 | pressed = alt; |
557 | } | 571 | } |
558 | } else { | 572 | } else { |
559 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 573 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
560 | /* | 574 | /* |
561 | s = QChar( shift^lock ? QWSServer::keyMap()[k].shift_unicode : | 575 | s = QChar( shift^lock ? QWSServer::keyMap()[k].shift_unicode : |
562 | QWSServer::keyMap()[k].unicode); | 576 | QWSServer::keyMap()[k].unicode); |
563 | */ | 577 | */ |
564 | // ### Fixme, bad code, needs improving, whole thing needs to | 578 | // ### Fixme, bad code, needs improving, whole thing needs to |
565 | // be re-coded to get rid of the way it did things with scancodes etc | 579 | // be re-coded to get rid of the way it did things with scancodes etc |
566 | char shifted = k; | 580 | char shifted = k; |
567 | if ( !isalpha( k ) ) { | 581 | if ( !isalpha( k ) ) { |
568 | for ( unsigned i = 0; i < sizeof(shiftMap)/sizeof(ShiftMap); i++ ) | 582 | for ( unsigned i = 0; i < sizeof(shiftMap)/sizeof(ShiftMap); i++ ) |
569 | if ( shiftMap[i].normal == k ) | 583 | if ( shiftMap[i].normal == k ) |
570 | shifted = shiftMap[i].shifted; | 584 | shifted = shiftMap[i].shifted; |
571 | } else { | 585 | } else { |
572 | shifted = toupper( k ); | 586 | shifted = toupper( k ); |
573 | } | 587 | } |
574 | s = QChar( shift^lock ? shifted : k ); | 588 | s = QChar( shift^lock ? shifted : k ); |
575 | #endif | 589 | #endif |
576 | } | 590 | } |
577 | 591 | ||
578 | if (!blank) { | 592 | if (!blank) { |
579 | if ( pressed ) | 593 | if ( pressed ) |
580 | p.fillRect( x+margin, y+margin, kw-margin, keyHeight-margin-1, keycolor_pressed ); | 594 | p.fillRect( x+margin, y+margin, kw-margin, keyHeight-margin-1, keycolor_pressed ); |
581 | else | 595 | else |
582 | p.fillRect( x+margin, y+margin, kw-margin, keyHeight-margin-1, keycolor ); | 596 | p.fillRect( x+margin, y+margin, kw-margin, keyHeight-margin-1, keycolor ); |
583 | 597 | ||
584 | if ( threeD ) { | 598 | if ( threeD ) { |
585 | p.setPen(pressed ? keycolor_lo : keycolor_hi); | 599 | p.setPen(pressed ? keycolor_lo : keycolor_hi); |
586 | p.drawLine( x, y+1, x, y+keyHeight-2 ); | 600 | p.drawLine( x, y+1, x, y+keyHeight-2 ); |
587 | p.drawLine( x+1, y+1, x+1, y+keyHeight-3 ); | 601 | p.drawLine( x+1, y+1, x+1, y+keyHeight-3 ); |
588 | p.drawLine( x+1, y+1, x+1+kw-2, y+1 ); | 602 | p.drawLine( x+1, y+1, x+1+kw-2, y+1 ); |
589 | } else if ( j == 0 ) { | 603 | } else if ( j == 0 ) { |
590 | p.setPen(pressed ? keycolor_hi : keycolor_lo); | 604 | p.setPen(pressed ? keycolor_hi : keycolor_lo); |
591 | p.drawLine( x, y, x+kw, y ); | 605 | p.drawLine( x, y, x+kw, y ); |
592 | } | 606 | } |
593 | 607 | ||
594 | // right | 608 | // right |
595 | p.setPen(pressed ? keycolor_hi : keycolor_lo); | 609 | p.setPen(pressed ? keycolor_hi : keycolor_lo); |
596 | p.drawLine( x+kw-1, y, x+kw-1, y+keyHeight-2 ); | 610 | p.drawLine( x+kw-1, y, x+kw-1, y+keyHeight-2 ); |
597 | 611 | ||
598 | if ( threeD ) { | 612 | if ( threeD ) { |
599 | p.setPen(keycolor_lo.light()); | 613 | p.setPen(keycolor_lo.light()); |
600 | p.drawLine( x+kw-2, y+keyHeight-2, x+kw-2, y+1 ); | 614 | p.drawLine( x+kw-2, y+keyHeight-2, x+kw-2, y+1 ); |
601 | p.drawLine( x+kw-2, y+keyHeight-2, x+1, y+keyHeight-2 ); | 615 | p.drawLine( x+kw-2, y+keyHeight-2, x+1, y+keyHeight-2 ); |
602 | } | 616 | } |
603 | 617 | ||
604 | if (xpm) { | 618 | if (xpm) { |
605 | p.drawPixmap( x + 1, y + 2, QPixmap((const char**)xpm) ); | 619 | p.drawPixmap( x + 1, y + 2, QPixmap((const char**)xpm) ); |
606 | } else { | 620 | } else { |
607 | p.setPen(textcolor); | 621 | p.setPen(textcolor); |
608 | p.drawText( x - 1, y, kw, keyHeight-2, AlignCenter, s ); | 622 | p.drawText( x - 1, y, kw, keyHeight-2, AlignCenter, s ); |
609 | } | 623 | } |
610 | 624 | ||
611 | if ( threeD ) { | 625 | if ( threeD ) { |
612 | p.setPen(keycolor_hi); | 626 | p.setPen(keycolor_hi); |
613 | p.drawLine( x, y, x+kw-1, y ); | 627 | p.drawLine( x, y, x+kw-1, y ); |
614 | } | 628 | } |
615 | 629 | ||
616 | // bottom | 630 | // bottom |
617 | p.setPen(keycolor_lo); | 631 | p.setPen(keycolor_lo); |
618 | p.drawLine( x, y+keyHeight-1, x+kw-1, y+keyHeight-1 ); | 632 | p.drawLine( x, y+keyHeight-1, x+kw-1, y+keyHeight-1 ); |
619 | 633 | ||
620 | } else { | 634 | } else { |
621 | p.fillRect( x, y, kw, keyHeight, cg.background() ); | 635 | p.fillRect( x, y, kw, keyHeight, cg.background() ); |
622 | } | 636 | } |
623 | } | 637 | } |
624 | 638 | ||
625 | x += kw; | 639 | x += kw; |
626 | kw = defaultKeyWidth; | 640 | kw = defaultKeyWidth; |
627 | k = getKey( kw ); | 641 | k = getKey( kw ); |
628 | } | 642 | } |
629 | } | 643 | } |
630 | } | 644 | } |
631 | 645 | ||
632 | 646 | ||
633 | void Keyboard::mousePressEvent(QMouseEvent *e) | 647 | void Keyboard::mousePressEvent(QMouseEvent *e) |
634 | { | 648 | { |
635 | clearHighlight(); // typing fast? | 649 | clearHighlight(); // typing fast? |
636 | 650 | ||
637 | int i2 = ((e->x() - xoffs) * 2) / defaultKeyWidth; | 651 | int i2 = ((e->x() - xoffs) * 2) / defaultKeyWidth; |
638 | int j = (e->y() - picks->height()) / keyHeight; | 652 | int j = (e->y() - picks->height()) / keyHeight; |
639 | 653 | ||
640 | int k = keycode( i2, j, (const uchar **)((useOptiKeys) ? keyboard_opti : keyboard_standard) ); | 654 | int k = keycode( i2, j, (const uchar **)((useOptiKeys) ? keyboard_opti : keyboard_standard) ); |
641 | bool need_repaint = FALSE; | 655 | bool need_repaint = FALSE; |
642 | unicode = -1; | 656 | unicode = -1; |
643 | qkeycode = 0; | 657 | qkeycode = 0; |
644 | if ( k >= 0x80 ) { | 658 | if ( k >= 0x80 ) { |
645 | if ( k == ShiftCode ) { | 659 | if ( k == ShiftCode ) { |
646 | shift = !shift; | 660 | shift = !shift; |
647 | need_repaint = TRUE; | 661 | need_repaint = TRUE; |
648 | } else if ( k == AltCode ){ | 662 | } else if ( k == AltCode ){ |
649 | alt = !alt; | 663 | alt = !alt; |
650 | need_repaint = TRUE; | 664 | need_repaint = TRUE; |
651 | } else if ( k == CapsCode ) { | 665 | } else if ( k == CapsCode ) { |
652 | lock = !lock; | 666 | lock = !lock; |
653 | need_repaint = TRUE; | 667 | need_repaint = TRUE; |
654 | } else if ( k == CtrlCode ) { | 668 | } else if ( k == CtrlCode ) { |
655 | ctrl = !ctrl; | 669 | ctrl = !ctrl; |
656 | need_repaint = TRUE; | 670 | need_repaint = TRUE; |
657 | } else if ( k == 0224 /* Expand */ ) { | 671 | } else if ( k == 0224 /* Expand */ ) { |
658 | useLargeKeys = !useLargeKeys; | 672 | useLargeKeys = !useLargeKeys; |
659 | resizeEvent(0); | 673 | resizeEvent(0); |
660 | repaint( TRUE ); // need it to clear first | 674 | repaint( TRUE ); // need it to clear first |
661 | } else if ( k == 0225 /* Opti/Toggle */ ) { | 675 | } else if ( k == 0225 /* Opti/Toggle */ ) { |
662 | useOptiKeys = !useOptiKeys; | 676 | useOptiKeys = !useOptiKeys; |
663 | resizeEvent(0); | 677 | resizeEvent(0); |
664 | repaint( TRUE ); // need it to clear first | 678 | repaint( TRUE ); // need it to clear first |
665 | } else { | 679 | } else { |
666 | qkeycode = specialM[ k - 0x80 ].qcode; | 680 | qkeycode = specialM[ k - 0x80 ].qcode; |
667 | unicode = specialM[ k - 0x80 ].unicode; | 681 | unicode = specialM[ k - 0x80 ].unicode; |
668 | } | 682 | } |
669 | } else { | 683 | } else { |
670 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 684 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
671 | /* | 685 | /* |
672 | qk = QWSServer::keyMap()[k].key_code; | 686 | qk = QWSServer::keyMap()[k].key_code; |
673 | if ( qk != Key_unknown ) { | 687 | if ( qk != Key_unknown ) { |
674 | if ( ctrl ) | 688 | if ( ctrl ) |
675 | u = QWSServer::keyMap()[k].ctrl_unicode; | 689 | u = QWSServer::keyMap()[k].ctrl_unicode; |
676 | else if ( shift^lock ) | 690 | else if ( shift^lock ) |
677 | u = QWSServer::keyMap()[k].shift_unicode; | 691 | u = QWSServer::keyMap()[k].shift_unicode; |
678 | else | 692 | else |
679 | u = QWSServer::keyMap()[k].unicode; | 693 | u = QWSServer::keyMap()[k].unicode; |
680 | } | 694 | } |
681 | */ | 695 | */ |
682 | char shifted = k; | 696 | char shifted = k; |
683 | if ( !isalpha( k ) ) { | 697 | if ( !isalpha( k ) ) { |
684 | // ### Fixme, bad code, needs improving, whole thing needs to | 698 | // ### Fixme, bad code, needs improving, whole thing needs to |
685 | // be re-coded to get rid of the way it did things with scancodes etc | 699 | // be re-coded to get rid of the way it did things with scancodes etc |
686 | for ( unsigned i = 0; i < sizeof(shiftMap)/sizeof(ShiftMap); i++ ) | 700 | for ( unsigned i = 0; i < sizeof(shiftMap)/sizeof(ShiftMap); i++ ) |
687 | if ( shiftMap[i].normal == k ) | 701 | if ( shiftMap[i].normal == k ) |
688 | shifted = shiftMap[i].shifted; | 702 | shifted = shiftMap[i].shifted; |
689 | } else { | 703 | } else { |
690 | shifted = toupper( k ); | 704 | shifted = toupper( k ); |
691 | } | 705 | } |
692 | QChar tempChar( shift^lock ? shifted : k ); | 706 | QChar tempChar( shift^lock ? shifted : k ); |
693 | unicode = tempChar.unicode(); | 707 | unicode = tempChar.unicode(); |
694 | #endif | 708 | #endif |
695 | } | 709 | } |
696 | if ( unicode != -1 ) { | 710 | if ( unicode != -1 ) { |
697 | modifiers = (shift ? Qt::ShiftButton : 0) | (ctrl ? Qt::ControlButton : 0) | | 711 | modifiers = (shift ? Qt::ShiftButton : 0) | (ctrl ? Qt::ControlButton : 0) | |
698 | (alt ? Qt::AltButton : 0); | 712 | (alt ? Qt::AltButton : 0); |
699 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 713 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
700 | emit key( unicode, qkeycode, modifiers, true, false ); | 714 | emit key( unicode, qkeycode, modifiers, true, false ); |
701 | repeatTimer->start( 500 ); | 715 | repeatTimer->start( 500 ); |
702 | #endif | 716 | #endif |
703 | need_repaint = shift || alt || ctrl; | 717 | need_repaint = shift || alt || ctrl; |
704 | shift = alt = ctrl = FALSE; | 718 | shift = alt = ctrl = FALSE; |
705 | //qDebug( "pressed %d -> %04x ('%c')", k, u, u&0xffff < 256 ? u&0xff : 0 ); | 719 | //qDebug( "pressed %d -> %04x ('%c')", k, u, u&0xffff < 256 ? u&0xff : 0 ); |
706 | 720 | ||
707 | KeyboardConfig *dc = picks->dc; | 721 | KeyboardConfig *dc = picks->dc; |
708 | 722 | ||
709 | if (dc) { | 723 | if (dc) { |
710 | if (qkeycode == Qt::Key_Backspace) { | 724 | if (qkeycode == Qt::Key_Backspace) { |
711 | dc->input.remove(dc->input.last()); // remove last input | 725 | dc->input.remove(dc->input.last()); // remove last input |
712 | dc->decBackspaces(); | 726 | dc->decBackspaces(); |
713 | } else if ( k == 0226 || qkeycode == Qt::Key_Return || | 727 | } else if ( k == 0226 || qkeycode == Qt::Key_Return || |
714 | qkeycode == Qt::Key_Space || | 728 | qkeycode == Qt::Key_Space || |
715 | QChar(unicode).isPunct() ) { | 729 | QChar(unicode).isPunct() ) { |
716 | dc->input.clear(); | 730 | dc->input.clear(); |
717 | dc->resetBackspaces(); | 731 | dc->resetBackspaces(); |
718 | } else { | 732 | } else { |
719 | dc->add(QString(QChar(unicode))); | 733 | dc->add(QString(QChar(unicode))); |
720 | dc->incBackspaces(); | 734 | dc->incBackspaces(); |
721 | } | 735 | } |
722 | } | 736 | } |
723 | 737 | ||
724 | picks->repaint(); | 738 | picks->repaint(); |
725 | 739 | ||
726 | } | 740 | } |
727 | pressedKey = k; | 741 | pressedKey = k; |
728 | if ( need_repaint ) { | 742 | if ( need_repaint ) { |
729 | repaint( FALSE ); | 743 | repaint( FALSE ); |
730 | } else { | 744 | } else { |
731 | QPainter p(this); | 745 | QPainter p(this); |
732 | drawKeyboard( p, pressedKey ); | 746 | drawKeyboard( p, pressedKey ); |
733 | } | 747 | } |
734 | pressTid = startTimer(80); | 748 | pressTid = startTimer(80); |
735 | pressed = TRUE; | 749 | pressed = TRUE; |
736 | } | 750 | } |
737 | 751 | ||
738 | 752 | ||
739 | void Keyboard::mouseReleaseEvent(QMouseEvent*) | 753 | void Keyboard::mouseReleaseEvent(QMouseEvent*) |
740 | { | 754 | { |
741 | if ( pressTid == 0 ) | 755 | if ( pressTid == 0 ) |
742 | clearHighlight(); | 756 | clearHighlight(); |
743 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 757 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
744 | if ( unicode != -1 ) { | 758 | if ( unicode != -1 ) { |
745 | emit key( unicode, qkeycode, modifiers, false, false ); | 759 | emit key( unicode, qkeycode, modifiers, false, false ); |
746 | repeatTimer->stop(); | 760 | repeatTimer->stop(); |
747 | } | 761 | } |
748 | #endif | 762 | #endif |
749 | pressed = FALSE; | 763 | pressed = FALSE; |
750 | } | 764 | } |
751 | 765 | ||
752 | void Keyboard::timerEvent(QTimerEvent* e) | 766 | void Keyboard::timerEvent(QTimerEvent* e) |
753 | { | 767 | { |
754 | if ( e->timerId() == pressTid ) { | 768 | if ( e->timerId() == pressTid ) { |
755 | killTimer(pressTid); | 769 | killTimer(pressTid); |
756 | pressTid = 0; | 770 | pressTid = 0; |
757 | if ( !pressed ) | 771 | if ( !pressed ) |
758 | clearHighlight(); | 772 | clearHighlight(); |
759 | } | 773 | } |
760 | } | 774 | } |
761 | 775 | ||
762 | void Keyboard::repeat() | 776 | void Keyboard::repeat() |
763 | { | 777 | { |
764 | repeatTimer->start( 150 ); | 778 | |
765 | emit key( unicode, qkeycode, modifiers, true, true ); | 779 | repeatTimer->start( 200 ); |
780 | emit key( unicode, qkeycode, modifiers, true, true ); | ||
766 | } | 781 | } |
767 | 782 | ||
768 | void Keyboard::clearHighlight() | 783 | void Keyboard::clearHighlight() |
769 | { | 784 | { |
770 | if ( pressedKey >= 0 ) { | 785 | if ( pressedKey >= 0 ) { |
771 | int tmp = pressedKey; | 786 | int tmp = pressedKey; |
772 | pressedKey = -1; | 787 | pressedKey = -1; |
773 | QPainter p(this); | 788 | QPainter p(this); |
774 | drawKeyboard( p, tmp ); | 789 | drawKeyboard( p, tmp ); |
775 | } | 790 | } |
776 | } | 791 | } |
777 | 792 | ||
778 | 793 | ||
779 | QSize Keyboard::sizeHint() const | 794 | QSize Keyboard::sizeHint() const |
780 | { | 795 | { |
781 | QFontMetrics fm=fontMetrics(); | 796 | QFontMetrics fm=fontMetrics(); |
782 | int keyHeight = fm.lineSpacing()+2; | 797 | int keyHeight = fm.lineSpacing()+2; |
783 | 798 | ||
784 | if (useOptiKeys) | 799 | if (useOptiKeys) |
785 | keyHeight += 1; | 800 | keyHeight += 1; |
786 | 801 | ||
787 | return QSize( 320, keyHeight * 5 + picks->sizeHint().height() + 1 ); | 802 | return QSize( 320, keyHeight * 5 + picks->sizeHint().height() + 1 ); |
788 | } | 803 | } |
789 | 804 | ||
790 | 805 | ||
791 | void Keyboard::resetState() | 806 | void Keyboard::resetState() |
792 | { | 807 | { |
793 | picks->resetState(); | 808 | picks->resetState(); |
794 | } | 809 | } |