summaryrefslogtreecommitdiff
path: root/inputmethods/multikey/keyboard.cpp
authorhash <hash>2002-08-22 05:50:34 (UTC)
committer hash <hash>2002-08-22 05:50:34 (UTC)
commit4c02921ddab3dd8b48d7d54a0c09e8f4ca71efb3 (patch) (unidiff)
treeaeada387b0a02e5cbdb409309a47a36649938b95 /inputmethods/multikey/keyboard.cpp
parentea0d66f137984689c4d4ef6da7dd4b7323760e8c (diff)
downloadopie-4c02921ddab3dd8b48d7d54a0c09e8f4ca71efb3.zip
opie-4c02921ddab3dd8b48d7d54a0c09e8f4ca71efb3.tar.gz
opie-4c02921ddab3dd8b48d7d54a0c09e8f4ca71efb3.tar.bz2
added meta key support for maps like german and jumpx
Diffstat (limited to 'inputmethods/multikey/keyboard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp98
1 files changed, 90 insertions, 8 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index 7098a6b..74c99c7 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -20,50 +20,50 @@
20 20
21#include "keyboard.h" 21#include "keyboard.h"
22#include "configdlg.h" 22#include "configdlg.h"
23 23
24#include <qpe/global.h> 24#include <qpe/global.h>
25#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
26 26
27#include <qwindowsystem_qws.h> 27#include <qwindowsystem_qws.h>
28#include <qpainter.h> 28#include <qpainter.h>
29#include <qfontmetrics.h> 29#include <qfontmetrics.h>
30#include <qtimer.h> 30#include <qtimer.h>
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#include <qpe/config.h> 32#include <qpe/config.h>
33#include <ctype.h> 33#include <ctype.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qstringlist.h> 36#include <qstringlist.h>
37#include <iostream.h> 37#include <iostream.h>
38 38
39#include <sys/utsname.h> 39#include <sys/utsname.h>
40 40
41 41
42/* Keyboard::Keyboard {{{1 */ 42/* Keyboard::Keyboard {{{1 */
43Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : 43Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
44 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), 44 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), meta(0),
45 alt(0), useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1), 45 useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1),
46 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), 46 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0),
47 configdlg(0) 47 configdlg(0)
48 48
49{ 49{
50 50
51 // get the default font 51 // get the default font
52 Config *config = new Config( "qpe" ); 52 Config *config = new Config( "qpe" );
53 config->setGroup( "Appearance" ); 53 config->setGroup( "Appearance" );
54 QString familyStr = config->readEntry( "FontFamily", "fixed" ); 54 QString familyStr = config->readEntry( "FontFamily", "fixed" );
55 delete config; 55 delete config;
56 56
57 config = new Config("multikey"); 57 config = new Config("multikey");
58 config->setGroup ("general"); 58 config->setGroup ("general");
59 usePicks = config->readBoolEntry ("usePickboard", "0"); // default closed 59 usePicks = config->readBoolEntry ("usePickboard", "0"); // default closed
60 useRepeat = config->readBoolEntry ("useRepeat", "1"); 60 useRepeat = config->readBoolEntry ("useRepeat", "1");
61 delete config; 61 delete config;
62 62
63 63
64 setFont( QFont( familyStr, 10 ) ); 64 setFont( QFont( familyStr, 10 ) );
65 65
66 picks = new KeyboardPicks( this ); 66 picks = new KeyboardPicks( this );
67 picks->setFont( QFont( familyStr, 10 ) ); 67 picks->setFont( QFont( familyStr, 10 ) );
68 picks->initialise(); 68 picks->initialise();
69 if (usePicks) { 69 if (usePicks) {
@@ -161,95 +161,106 @@ void Keyboard::paintEvent(QPaintEvent* e)
161void Keyboard::drawKeyboard(QPainter &p, int row, int col) 161void Keyboard::drawKeyboard(QPainter &p, int row, int col)
162{ 162{
163 163
164 164
165 if (row != -1 && col != -1) { //just redraw one key 165 if (row != -1 && col != -1) { //just redraw one key
166 166
167 int x = 0; 167 int x = 0;
168 for (int i = 0; i < col; i++) { 168 for (int i = 0; i < col; i++) {
169 169
170 x += keys->width(row, i) * defaultKeyWidth; 170 x += keys->width(row, i) * defaultKeyWidth;
171 } 171 }
172 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 172 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
173 173
174 int keyWidth = keys->width(row, col); 174 int keyWidth = keys->width(row, col);
175 175
176 p.fillRect(x + 1, y + 1, 176 p.fillRect(x + 1, y + 1,
177 keyWidth * defaultKeyWidth - 1, keyHeight - 1, 177 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
178 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); 178 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor);
179 179
180 QPixmap *pix = keys->pix(row,col); 180 QPixmap *pix = keys->pix(row,col);
181 181
182 ushort c = keys->uni(row, col); 182 ushort c = keys->uni(row, col);
183 183
184 p.setPen(textcolor); 184 p.setPen(textcolor);
185 if (!pix) 185 if (!pix) {
186 if (shift || lock)
187 c = keys->shift(c);
188 if (meta) {
189
190 c = keys->meta(c);
191 }
186 p.drawText(x, y, 192 p.drawText(x, y,
187 defaultKeyWidth * keyWidth, keyHeight, 193 defaultKeyWidth * keyWidth + 3, keyHeight,
188 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); 194 AlignCenter, (QChar)c);
195 }
189 else 196 else
190 // center the image in the middle of the key 197 // center the image in the middle of the key
191 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, 198 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2,
192 y + (keyHeight - pix->height())/2 + 1, 199 y + (keyHeight - pix->height())/2 + 1,
193 *pix ); 200 *pix );
194 201
195 // this fixes the problem that the very right end of the board's vertical line 202 // this fixes the problem that the very right end of the board's vertical line
196 // gets painted over, because it's one pixel shorter than all other keys 203 // gets painted over, because it's one pixel shorter than all other keys
197 p.setPen(keycolor_lines); 204 p.setPen(keycolor_lines);
198 p.drawLine(width() - 1, 0, width() - 1, height()); 205 p.drawLine(width() - 1, 0, width() - 1, height());
199 206
200 } else { 207 } else {
201 208
202 209
203 p.fillRect(0, 0, width(), height(), keycolor); 210 p.fillRect(0, 0, width(), height(), keycolor);
204 211
205 for (row = 1; row <= 5; row++) { 212 for (row = 1; row <= 5; row++) {
206 213
207 int x = 0; 214 int x = 0;
208 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 215 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
209 216
210 p.setPen(keycolor_lines); 217 p.setPen(keycolor_lines);
211 p.drawLine(x, y, x + width(), y); 218 p.drawLine(x, y, x + width(), y);
212 219
213 for (int col = 0; col < keys->numKeys(row); col++) { 220 for (int col = 0; col < keys->numKeys(row); col++) {
214 221
215 QPixmap *pix = keys->pix(row, col); 222 QPixmap *pix = keys->pix(row, col);
216 int keyWidth = keys->width(row, col); 223 int keyWidth = keys->width(row, col);
217 224
218 225
219 int keyWidthPix = defaultKeyWidth * keyWidth; 226 int keyWidthPix = defaultKeyWidth * keyWidth;
220 227
221 if (keys->pressed(row, col)) 228 if (keys->pressed(row, col))
222 p.fillRect(x+1, y+1, keyWidthPix - 1, 229 p.fillRect(x+1, y+1, keyWidthPix - 1,
223 keyHeight - 1, keycolor_pressed); 230 keyHeight - 1, keycolor_pressed);
224 231
225 ushort c = keys->uni(row, col); 232 ushort c = keys->uni(row, col);
226 233
227 if (!pix) { 234 if (!pix) {
228 p.setPen(textcolor); 235 if ((shift || lock) && keys->shift(c))
236 c = keys->shift(c);
237 else if (meta && keys->meta(c))
238 c = keys->meta(c);
239
229 p.drawText(x, y, 240 p.drawText(x, y,
230 keyWidthPix, keyHeight, 241 defaultKeyWidth * keyWidth + 3, keyHeight,
231 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); 242 AlignCenter, (QChar)c);
232 } 243 }
233 else { 244 else {
234 // center the image in the middle of the key 245 // center the image in the middle of the key
235 p.drawPixmap( x + (keyWidthPix - pix->width())/2, 246 p.drawPixmap( x + (keyWidthPix - pix->width())/2,
236 y + (keyHeight - pix->height())/2 + 1, 247 y + (keyHeight - pix->height())/2 + 1,
237 QPixmap(*pix) ); 248 QPixmap(*pix) );
238 } 249 }
239 250
240 p.setPen(keycolor_lines); 251 p.setPen(keycolor_lines);
241 p.drawLine(x, y, x, y + keyHeight); 252 p.drawLine(x, y, x, y + keyHeight);
242 253
243 x += keyWidthPix; 254 x += keyWidthPix;
244 } 255 }
245 256
246 257
247 } 258 }
248 p.drawLine(0, height() - 1, width(), height() - 1); 259 p.drawLine(0, height() - 1, width(), height() - 1);
249 p.drawLine(width() - 1, 0, width() - 1, height()); 260 p.drawLine(width() - 1, 0, width() - 1, height());
250 } 261 }
251 262
252} 263}
253 264
254 265
255/* Keyboard::mousePressEvent {{{1 */ 266/* Keyboard::mousePressEvent {{{1 */
@@ -323,72 +334,114 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
323 alt = 0; 334 alt = 0;
324 335
325 } else { 336 } else {
326 337
327 alt = keys->pressedPtr(row, col); 338 alt = keys->pressedPtr(row, col);
328 need_repaint = TRUE; 339 need_repaint = TRUE;
329 *alt = !keys->pressed(row, col); 340 *alt = !keys->pressed(row, col);
330 } 341 }
331 342
332 } else if (qkeycode == Qt::Key_Shift) { 343 } else if (qkeycode == Qt::Key_Shift) {
333 need_repaint = TRUE; 344 need_repaint = TRUE;
334 345
335 if (shift) { 346 if (shift) {
336 *shift = 0; 347 *shift = 0;
337 shift = 0; 348 shift = 0;
338 } 349 }
339 else { 350 else {
340 shift = keys->pressedPtr(row, col); 351 shift = keys->pressedPtr(row, col);
341 *shift = 1; 352 *shift = 1;
342 if (lock) { 353 if (lock) {
343 *lock = 0; 354 *lock = 0;
344 lock = 0; 355 lock = 0;
345 } 356 }
346 } 357 }
358 if (meta) {
359
360 *meta = 0;
361 meta = 0;
362 }
347 363
348 } else if (qkeycode == Qt::Key_CapsLock) { 364 } else if (qkeycode == Qt::Key_CapsLock) {
349 need_repaint = TRUE; 365 need_repaint = TRUE;
350 366
351 if (lock) { 367 if (lock) {
352 *lock = 0; 368 *lock = 0;
353 lock = 0; 369 lock = 0;
354 } 370 }
355 else { 371 else {
356 lock = keys->pressedPtr(row, col);; 372 lock = keys->pressedPtr(row, col);;
357 *lock = 1; 373 *lock = 1;
358 if (shift) { 374 if (shift) {
359 *shift = 0; 375 *shift = 0;
360 shift = 0; 376 shift = 0;
361 } 377 }
362 } 378 }
379 if (meta) {
380
381 *meta = 0;
382 meta = 0;
383 }
384
385 } else if (qkeycode == Qt::Key_Meta) {
386 need_repaint = TRUE;
387
388 if (meta) {
389 *meta = 0;
390 meta = 0;
391
392 } else {
393
394 meta = keys->pressedPtr(row, col);
395 need_repaint = TRUE;
396 *meta = !keys->pressed(row, col);
397 }
398
399 if (shift) {
400
401 *shift = 0;
402 shift = 0;
403
404 }
405 if (lock) {
406
407 *lock = 0;
408 lock = 0;
409
410 }
363 411
412 // dont need to emit this key... acts same as alt
413 qkeycode = 0;
364 } 414 }
365 415
366 } 416 }
367 else { // normal char 417 else { // normal char
368 if ((shift || lock) && keys->shift(unicode)) { 418 if ((shift || lock) && keys->shift(unicode)) {
369 unicode = keys->shift(unicode); 419 unicode = keys->shift(unicode);
370 } 420 }
421 if (meta && keys->meta(unicode)) {
422 unicode = keys->meta(unicode);
423 }
371 } 424 }
372 425
373 // korean parsing 426 // korean parsing
374 if (keys->lang == "ko") { 427 if (keys->lang == "ko") {
375 428
376 unicode = parseKoreanInput(unicode); 429 unicode = parseKoreanInput(unicode);
377 } 430 }
378 431
379 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); 432 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
380 433
381 if ('A' <= unicode && unicode <= 'z' && modifiers) { 434 if ('A' <= unicode && unicode <= 'z' && modifiers) {
382 435
383 qkeycode = QChar(unicode).upper(); 436 qkeycode = QChar(unicode).upper();
384 unicode = qkeycode - '@'; 437 unicode = qkeycode - '@';
385 } 438 }
386 439
387 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); 440 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false);
388 441
389 // pickboard stuff 442 // pickboard stuff
390 if (usePicks) { 443 if (usePicks) {
391 444
392 KeyboardConfig *dc = picks->dc; 445 KeyboardConfig *dc = picks->dc;
393 446
394 if (dc) { 447 if (dc) {
@@ -426,48 +479,53 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
426 if (useRepeat) repeatTimer->start( 800 ); 479 if (useRepeat) repeatTimer->start( 800 );
427 //pressTid = startTimer(80); 480 //pressTid = startTimer(80);
428 481
429} 482}
430 483
431 484
432/* Keyboard::mouseReleaseEvent {{{1 */ 485/* Keyboard::mouseReleaseEvent {{{1 */
433void Keyboard::mouseReleaseEvent(QMouseEvent*) 486void Keyboard::mouseReleaseEvent(QMouseEvent*)
434{ 487{
435 pressed = FALSE; 488 pressed = FALSE;
436 //if ( pressTid == 0 ) 489 //if ( pressTid == 0 )
437#if defined(Q_WS_QWS) || defined(_WS_QWS_) 490#if defined(Q_WS_QWS) || defined(_WS_QWS_)
438 if ( unicode != -1 ) { 491 if ( unicode != -1 ) {
439 emit key( unicode, qkeycode, modifiers, false, false ); 492 emit key( unicode, qkeycode, modifiers, false, false );
440 repeatTimer->stop(); 493 repeatTimer->stop();
441 } 494 }
442#endif 495#endif
443 if (shift && unicode != 0) { 496 if (shift && unicode != 0) {
444 497
445 498
446 *shift = 0; // unpress shift key 499 *shift = 0; // unpress shift key
447 shift = 0; // reset the shift pointer 500 shift = 0; // reset the shift pointer
448 repaint(FALSE); 501 repaint(FALSE);
449 502
503 } else if (meta && unicode != 0) {
504
505 *meta = 0;
506 meta = 0;
507 repaint(FALSE);
450 } 508 }
451 else 509 else
452 510
453 clearHighlight(); 511 clearHighlight();
454} 512}
455 513
456/* Keyboard::timerEvent {{{1 */ 514/* Keyboard::timerEvent {{{1 */
457 515
458/* dont know what this does, but i think it is here so that if your screen 516/* dont know what this does, but i think it is here so that if your screen
459 * sticks (like on an ipaq) then it will stop repeating if you click another 517 * sticks (like on an ipaq) then it will stop repeating if you click another
460 * key... but who knows what anything does in this thing anyway? 518 * key... but who knows what anything does in this thing anyway?
461 519
462 void Keyboard::timerEvent(QTimerEvent* e) 520 void Keyboard::timerEvent(QTimerEvent* e)
463{ 521{
464 if ( e->timerId() == pressTid ) { 522 if ( e->timerId() == pressTid ) {
465 killTimer(pressTid); 523 killTimer(pressTid);
466 pressTid = 0; 524 pressTid = 0;
467 if ( !pressed ) 525 if ( !pressed )
468 cout << "calling clearHighlight from timerEvent\n"; 526 cout << "calling clearHighlight from timerEvent\n";
469 //clearHighlight(); 527 //clearHighlight();
470 } 528 }
471} 529}
472*/ 530*/
473 531
@@ -1025,48 +1083,61 @@ void Keys::setKeysFromFile(const char * filename) {
1025 } 1083 }
1026 if (xpmLineCount) { 1084 if (xpmLineCount) {
1027 1085
1028 xpm2pix = new QPixmap((const char **)xpm); 1086 xpm2pix = new QPixmap((const char **)xpm);
1029 for (int i = 0; i < xpmLineCount; i++) 1087 for (int i = 0; i < xpmLineCount; i++)
1030 1088
1031 delete [] (xpm[i]); 1089 delete [] (xpm[i]);
1032 1090
1033 } 1091 }
1034 setKey(row, qcode, unicode, width, xpm2pix); 1092 setKey(row, qcode, unicode, width, xpm2pix);
1035 } 1093 }
1036 1094
1037 // shift map 1095 // shift map
1038 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1096 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1039 1097
1040 QTextStream tmp (buf, IO_ReadOnly); 1098 QTextStream tmp (buf, IO_ReadOnly);
1041 ushort lower, shift; 1099 ushort lower, shift;
1042 tmp >> lower >> shift; 1100 tmp >> lower >> shift;
1043 1101
1044 shiftMap.insert(lower, shift); 1102 shiftMap.insert(lower, shift);
1045 1103
1046 buf = t.readLine(); 1104 buf = t.readLine();
1047 } 1105 }
1048 1106
1107 // meta key map
1108 else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1109
1110 QTextStream tmp (buf, IO_ReadOnly);
1111 ushort lower, shift;
1112 QChar m;
1113 tmp >> m >> lower >> shift;
1114
1115 metaMap.insert(lower, shift);
1116
1117 buf = t.readLine();
1118 }
1119
1049 // other variables like lang & title 1120 // other variables like lang & title
1050 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { 1121 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) {
1051 1122
1052 QTextStream tmp (buf, IO_ReadOnly); 1123 QTextStream tmp (buf, IO_ReadOnly);
1053 QString name, equals, value; 1124 QString name, equals, value;
1054 1125
1055 tmp >> name >> equals >> value; 1126 tmp >> name >> equals >> value;
1056 1127
1057 if (name == "lang") { 1128 if (name == "lang") {
1058 1129
1059 lang = value; 1130 lang = value;
1060 1131
1061 } 1132 }
1062 1133
1063 buf = t.readLine(); 1134 buf = t.readLine();
1064 } 1135 }
1065 // comments 1136 // comments
1066 else if (buf.contains(QRegExp("^\\s*#"))) { 1137 else if (buf.contains(QRegExp("^\\s*#"))) {
1067 1138
1068 buf = t.readLine(); 1139 buf = t.readLine();
1069 1140
1070 } else { // blank line, or garbage 1141 } else { // blank line, or garbage
1071 1142
1072 buf = t.readLine(); 1143 buf = t.readLine();
@@ -1148,28 +1219,39 @@ bool Keys::pressed(const int row, const int col) {
1148 return *(keys[row].at(col)->pressed); 1219 return *(keys[row].at(col)->pressed);
1149} 1220}
1150 1221
1151int Keys::numKeys(const int row) { 1222int Keys::numKeys(const int row) {
1152 1223
1153 return keys[row].count(); 1224 return keys[row].count();
1154} 1225}
1155 1226
1156void Keys::setPressed(const int row, const int col, const bool pressed) { 1227void Keys::setPressed(const int row, const int col, const bool pressed) {
1157 1228
1158 *(keys[row].at(col)->pressed) = pressed; 1229 *(keys[row].at(col)->pressed) = pressed;
1159} 1230}
1160 1231
1161ushort Keys::shift(const ushort uni) { 1232ushort Keys::shift(const ushort uni) {
1162 1233
1163 if (shiftMap[uni]) { 1234 if (shiftMap[uni]) {
1164 1235
1165 return shiftMap[uni]; 1236 return shiftMap[uni];
1166 } 1237 }
1167 else 1238 else
1168 return 0; 1239 return 0;
1169 1240
1170} 1241}
1171 1242
1243ushort Keys::meta(const ushort uni) {
1244
1245 if (metaMap[uni]) {
1246
1247 return metaMap[uni];
1248 }
1249 else
1250 return 0;
1251
1252}
1253
1172bool *Keys::pressedPtr(const int row, const int col) { 1254bool *Keys::pressedPtr(const int row, const int col) {
1173 1255
1174 return keys[row].at(col)->pressed; 1256 return keys[row].at(col)->pressed;
1175} 1257}