summaryrefslogtreecommitdiff
path: root/inputmethods
authorhash <hash>2002-07-28 10:10:35 (UTC)
committer hash <hash>2002-07-28 10:10:35 (UTC)
commitb18897e49eb04eb5d847c8231dde7442eca19fb4 (patch) (unidiff)
tree05f1bebfe62c4fbc9c6ee84fae46d3d781027470 /inputmethods
parentdfa88fddb768b27d6a3c92c25b223b59c84af153 (diff)
downloadopie-b18897e49eb04eb5d847c8231dde7442eca19fb4.zip
opie-b18897e49eb04eb5d847c8231dde7442eca19fb4.tar.gz
opie-b18897e49eb04eb5d847c8231dde7442eca19fb4.tar.bz2
keyboard that changes according to current locale setting
Diffstat (limited to 'inputmethods') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp955
-rw-r--r--inputmethods/multikey/keyboard.h148
-rw-r--r--inputmethods/multikey/keyboard.pro29
-rw-r--r--inputmethods/multikey/keyboardimpl.cpp108
-rw-r--r--inputmethods/multikey/keyboardimpl.h51
-rw-r--r--inputmethods/multikey/opie-keyboard.control9
-rwxr-xr-xinputmethods/multikey/qpe-keyboard.postinst2
-rwxr-xr-xinputmethods/multikey/qpe-keyboard.postrm2
8 files changed, 1304 insertions, 0 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
new file mode 100644
index 0000000..92da8ca
--- a/dev/null
+++ b/inputmethods/multikey/keyboard.cpp
@@ -0,0 +1,955 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "keyboard.h"
22
23#include <qpe/global.h>
24
25#include <qwindowsystem_qws.h>
26#include <qpainter.h>
27#include <qfontmetrics.h>
28#include <qtimer.h>
29#include <qpe/qpeapplication.h>
30#include <qpe/config.h>
31#include <ctype.h>
32#include <qfile.h>
33#include <qtextstream.h>
34
35#include <sys/utsname.h>
36
37
38#define USE_SMALL_BACKSPACE
39
40/* Keyboard::Keyboard {{{1 */
41Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
42 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0),
43 alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1),
44 unicode(-1), qkeycode(0), modifiers(0), LANG("ko"), schar(0), mchar(0), echar(0)
45{
46
47 picks = new KeyboardPicks( this );
48 picks->setFont( QFont( "helvetica", 8 ) );
49 setFont( QFont( "helvetica", 8 ) );
50 picks->initialise();
51 if (usePicks) {
52
53 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
54 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
55
56 } else picks->hide();
57
58 Config config("locale");
59 config.setGroup( "Language" );
60 LANG = config.readEntry( "Language" );
61 if(LANG.isEmpty()) LANG = "en";
62
63 repeatTimer = new QTimer( this );
64 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
65
66}
67
68/* Keyboard::resizeEvent {{{1 */
69void Keyboard::resizeEvent(QResizeEvent*)
70{
71 int ph = picks->sizeHint().height();
72 picks->setGeometry( 0, 0, width(), ph );
73 keyHeight = (height()-(usePicks ? ph : 0))/5;
74
75 int nk; // number of keys?
76 if ( useLargeKeys ) {
77 nk = 15;
78 } else {
79 nk = 19;
80 }
81 defaultKeyWidth = (width()/nk)/2;
82 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
83
84}
85
86/* KeyboardPicks::initialize {{{1 */
87void KeyboardPicks::initialise()
88{
89 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
90 mode = 0;
91 dc = new KeyboardConfig(this);
92 configs.append(dc);
93}
94
95/* KeyboardPicks::sizeHint {{{1 */
96QSize KeyboardPicks::sizeHint() const
97{
98 return QSize(240,fontMetrics().lineSpacing());
99}
100
101
102/* KeyboardConfig::generateText {{{1 */
103void KeyboardConfig::generateText(const QString &s)
104{
105#if defined(Q_WS_QWS) || defined(_WS_QWS_)
106 for (int i=0; i<(int)backspaces; i++) {
107 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );
108 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );
109 }
110 for (int i=0; i<(int)s.length(); i++) {
111 parent->emitKey( s[i].unicode(), 0, 0, true, false );
112 parent->emitKey( s[i].unicode(), 0, 0, false, false );
113 }
114 parent->emitKey( 0, Qt::Key_Space, 0, true, false );
115 parent->emitKey( 0, Qt::Key_Space, 0, false, false );
116 backspaces = 0;
117#endif
118}
119
120
121
122
123/* Keyboard::paintEvent {{{1 */
124void Keyboard::paintEvent(QPaintEvent* e)
125{
126 QPainter painter(this);
127 painter.setClipRect(e->rect());
128 drawKeyboard( painter );
129 picks->dc->draw( &painter );
130}
131
132
133/* Keyboard::drawKeyboard {{{1 */
134
135void Keyboard::drawKeyboard(QPainter &p, int row, int col)
136{
137 QColor keycolor =
138 QColor(240,240,240);
139 QColor keycolor_pressed = QColor(171,183,198);
140 QColor keycolor_lines = QColor(138,148,160);
141 QColor textcolor = QColor(43,54,68);
142
143
144 if (row != -1 && col != -1) { //just redraw one key
145
146 int x = 0;
147 for (int i = 0; i < col; i++) {
148
149 x += keys.width(row, i) * defaultKeyWidth;
150 }
151 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
152
153 int keyWidth = keys.width(row, col);
154
155 p.fillRect(x + 1, y + 1,
156 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
157 pressed || keys.pressed(row, col) ? keycolor_pressed : keycolor);
158
159 QPixmap *pix = keys.pix(row,col);
160
161 ushort c = keys.uni(row, col);
162
163 if (!pix) {
164 p.setPen(textcolor);
165 p.drawText(x, y,
166 defaultKeyWidth * keyWidth, keyHeight,
167 AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c);
168 }
169 else
170 // center the image in the middle of the key
171 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2,
172 y + (keyHeight - pix->height())/2 + 1,
173 *pix );
174
175 // this fixes the problem that the very right end of the board's vertical line
176 // gets painted over, because it's one pixel shorter than all other keys
177 p.setPen(keycolor_lines);
178 p.drawLine(width() - 1, 0, width() - 1, height());
179
180 } else {
181
182
183 p.fillRect(0, 0, width(), height(), keycolor);
184
185 for (row = 1; row <= 5; row++) {
186
187 int x = 0;
188 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
189
190 p.setPen(keycolor_lines);
191 p.drawLine(x, y, x + width(), y);
192
193 for (int col = 0; col < keys.numKeys(row); col++) {
194
195 QPixmap *pix = keys.pix(row, col);
196 int keyWidth = keys.width(row, col);
197
198
199 int keyWidthPix = defaultKeyWidth * keyWidth;
200
201 if (keys.pressed(row, col))
202 p.fillRect(x+1, y+1, keyWidthPix - 1,
203 keyHeight - 1, keycolor_pressed);
204
205 ushort c = keys.uni(row, col);
206
207 if (!pix) {
208 p.setPen(textcolor);
209 p.drawText(x, y,
210 keyWidthPix, keyHeight,
211 AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c);
212 }
213 else {
214 // center the image in the middle of the key
215 p.drawPixmap( x + (keyWidthPix - pix->width())/2,
216 y + (keyHeight - pix->height())/2 + 1,
217 QPixmap(*pix) );
218 }
219
220 p.setPen(keycolor_lines);
221 p.drawLine(x, y, x, y + keyHeight);
222
223 x += keyWidthPix;
224 }
225
226
227 }
228 p.drawLine(0, height() - 1, width(), height() - 1);
229 p.drawLine(width() - 1, 0, width() - 1, height());
230 }
231
232}
233
234
235/* Keyboard::mousePressEvent {{{1 */
236void Keyboard::mousePressEvent(QMouseEvent *e)
237{
238 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
239 if (row > 5) row = 5;
240
241 // figure out the column
242 int col = 0;
243 for (int w = 0; e->x() >= w; col++)
244 if (col < keys.numKeys(row)) // it segfaults if it trys to read past numKeys
245 w += keys.width(row,col) * defaultKeyWidth;
246 else break;
247
248 col --; // rewind one...
249
250 qkeycode = keys.qcode(row, col);
251 unicode = keys.uni(row, col);
252
253 // might need to repaint if two or more of the same keys.
254 // should be faster if just paint one key even though multiple keys exist.
255 bool need_repaint = FALSE;
256
257 if (unicode == 0) { // either Qt char, or nothing
258
259 if (qkeycode == Qt::Key_F1) { // toggle the pickboard
260
261 usePicks = !usePicks;
262 if (usePicks) {
263 picks->show();
264 move(x(), y() - picks->height());
265 adjustSize();
266 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
267 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
268 } else {
269
270 picks->hide();
271 picks->resetState();
272 move(x(), y() + picks->height());
273 adjustSize();
274 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
275 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
276
277 }
278
279 keys.setPressed(row, col, usePicks);
280 need_repaint = TRUE;
281 qkeycode = 0; // don't need to emit Key_F1
282 } else if (qkeycode == Qt::Key_Control) {
283 ctrl = keys.pressedPtr(row, col);
284 need_repaint = TRUE;
285 *ctrl = !keys.pressed(row, col);
286
287 } else if (qkeycode == Qt::Key_Alt) {
288 alt = keys.pressedPtr(row, col);
289 need_repaint = TRUE;
290 *alt = !keys.pressed(row, col);
291
292 } else if (qkeycode == Qt::Key_Shift) {
293 need_repaint = TRUE;
294
295 if (shift) {
296 *shift = 0;
297 shift = 0;
298 }
299 else {
300 shift = keys.pressedPtr(row, col);
301 *shift = 1;
302 if (lock) {
303 *lock = 0;
304 lock = 0;
305 }
306 }
307
308 } else if (qkeycode == Qt::Key_CapsLock) {
309 need_repaint = TRUE;
310
311 if (lock) {
312 *lock = 0;
313 lock = 0;
314 }
315 else {
316 lock = keys.pressedPtr(row, col);;
317 *lock = 1;
318 if (shift) {
319 *shift = 0;
320 shift = 0;
321 }
322 }
323
324 }
325
326 }
327 else { // normal char
328 if ((shift || lock) && keys.shift(unicode)) {
329 unicode = keys.shift(unicode);
330 }
331 }
332
333 // korean parsing
334 if (LANG == "ko") {
335
336 unicode = parseKoreanInput(unicode);
337 }
338
339 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
340
341 emit key(unicode, qkeycode, modifiers, true, false);
342
343 // pickboard stuff
344 if (usePicks) {
345
346 KeyboardConfig *dc = picks->dc;
347
348 if (dc) {
349 if (qkeycode == Qt::Key_Backspace) {
350 dc->input.remove(dc->input.last()); // remove last input
351 dc->decBackspaces();
352 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) {
353 dc->input.clear();
354 dc->resetBackspaces();
355 } else {
356 dc->add(QString(QChar(unicode)));
357 dc->incBackspaces();
358 }
359 }
360 picks->repaint();
361 }
362
363
364 // painting
365 pressed = TRUE;
366
367 pressedKeyRow = row;
368 pressedKeyCol = col;
369
370 if (need_repaint) repaint(FALSE);
371 else { // just paint the one key pressed
372
373
374
375 QPainter p(this);
376 drawKeyboard(p, row, col);
377
378 }
379
380 pressTid = startTimer(80);
381
382}
383
384
385/* Keyboard::mouseReleaseEvent {{{1 */
386void Keyboard::mouseReleaseEvent(QMouseEvent*)
387{
388 pressed = FALSE;
389 if ( pressTid == 0 )
390#if defined(Q_WS_QWS) || defined(_WS_QWS_)
391 if ( unicode != -1 ) {
392 emit key( unicode, qkeycode, modifiers, false, false );
393 repeatTimer->stop();
394 }
395#endif
396 if (shift && unicode != 0) {
397
398
399 *shift = 0; // unpress shift key
400 shift = 0; // reset the shift pointer
401 repaint(FALSE);
402
403 }
404 else
405
406 clearHighlight();
407}
408
409/* Keyboard::timerEvent {{{1 */
410/*
411void Keyboard::timerEvent(QTimerEvent* e)
412{
413 if ( e->timerId() == pressTid ) {
414 killTimer(pressTid);
415 pressTid = 0;
416 if ( !pressed )
417 cout << "calling clearHighlight from timerEvent\n";
418 clearHighlight();
419 }
420}
421*/
422
423void Keyboard::repeat()
424{
425
426 repeatTimer->start( 200 );
427 emit key( unicode, 0, modifiers, true, true );
428}
429
430void Keyboard::clearHighlight()
431{
432 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) {
433 int tmpRow = pressedKeyRow;
434 int tmpCol = pressedKeyCol;
435
436 pressedKeyRow = -1;
437 pressedKeyCol = -1;
438
439 QPainter p(this);
440 drawKeyboard(p, tmpRow, tmpCol);
441 }
442}
443
444
445/* Keyboard::sizeHint {{{1 */
446QSize Keyboard::sizeHint() const
447{
448 QFontMetrics fm=fontMetrics();
449 int keyHeight = fm.lineSpacing()+2;
450
451 return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1);
452}
453
454
455void Keyboard::resetState()
456{
457 schar = mchar = echar = 0;
458 picks->resetState();
459}
460
461/* korean input functions {{{1
462 *
463 * TODO
464 * one major problem with this implementation is that you can't move the
465 * cursor after inputing korean chars, otherwise it will eat up and replace
466 * the char before the cursor you move to. fix that
467 *
468 * make a kor/eng swaping key
469 *
470 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
471 *
472 * how korean input works
473 *
474 * all following chars means unicode char value and are in hex
475 *
476 * ÃÊÀ½ = schar (start char)
477 * ÁßÀ½ = mchar (middle char)
478 * ³¡À½ = echar (end char)
479 *
480 * there are 19 schars. unicode position is at 1100 - 1112
481 * there are 21 mchars. unicode position is at 1161 - 1175
482 * there are 27 echars. unicode position is at 11a8 - 11c2
483 *
484 * the map with everything combined is at ac00 - d7a3
485 *
486 */
487
488ushort Keyboard::parseKoreanInput (ushort c) {
489
490 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
491 ||
492 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
493 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
494
495 schar = 0, mchar = 0, echar = 0;
496 return c;
497 }
498
499 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input
500
501 if (schar == 0 || (schar != 0 && mchar == 0)) {
502 schar = c; mchar = 0; echar = 0;
503 return c;
504 }
505 else if (mchar != 0) {
506
507 if (echar == 0) {
508
509 if (!(echar = constoe(c))) {
510
511 schar = c; mchar = 0; echar = 0;
512 return c;
513 }
514
515 }
516 else { // must figure out what the echar is
517
518 if (echar == 0x11a8) { // ¤¡
519
520 if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡
521 else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ
522 else {
523 schar = c; mchar = 0; echar = 0;
524 return c;
525 }
526
527 } else if (echar == 0x11ab) { // ¤¤
528
529 if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸
530 else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾
531 else {
532 schar = c; mchar = 0; echar = 0;
533 return c;
534 }
535
536 } else if (echar == 0x11af) { // ¤©
537
538 if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡
539 else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤±
540 else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤²
541 else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ
542 else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼
543 else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½
544 else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾
545 else {
546 schar = c; mchar = 0; echar = 0;
547 return c;
548 }
549
550 } else if (echar == 0x11b8) { // ¤²
551
552 if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ
553 else {
554 schar = c; mchar = 0; echar = 0;
555 return c;
556 }
557
558 } else if (echar == 0x11ba) { // ¤µ
559
560 if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ
561 else {
562 schar = c; mchar = 0; echar = 0;
563 return c;
564 }
565
566 } else { // if any other char, cannot combine chars
567
568 schar = c; mchar = 0; echar = 0;
569 return c;
570 }
571
572 unicode = echar;
573 }
574 }
575
576 }
577 else if (0x1161 <= c && c <= 0x1175) { // mchar was input
578
579 if (schar != 0 && mchar == 0) { mchar = c; }
580
581 else if (schar != 0 && mchar != 0 && echar == 0) {
582
583 switch (mchar) {
584 case 0x1169:
585 if (c == 0x1161) mchar = 0x116a;
586 else if (c == 0x1162) mchar = 0x116b;
587 else if (c == 0x1175) mchar = 0x116c;
588 else {
589 schar = 0; mchar = 0; echar = 0;
590 return c;
591 }
592 break;
593 case 0x116e:
594 if (c == 0x1165) mchar = 0x116f;
595 else if (c == 0x1166) mchar = 0x1170;
596 else if (c == 0x1175) mchar = 0x1171;
597 else {
598 schar = 0; mchar = 0; echar = 0;
599 return c;
600 }
601 break;
602 case 0x1173:
603 if (c == 0x1175) mchar = 0x1174;
604 else {
605 schar = 0; mchar = 0; echar = 0;
606 return c;
607 }
608 break;
609 default:
610 schar = 0; mchar = 0; echar = 0;
611 return c;
612 }
613 }
614 else if (schar != 0 && mchar != 0 && echar != 0) {
615
616 emit key( 8, Qt::Key_Backspace, 0, true, false );
617
618 ushort prev = 0;
619 switch (echar) {
620 /*
621 case 0x11a9:
622 prev = combineKoreanChars(schar, mchar, 0x11a8);
623 schar = 0x1100;
624 break;
625 */
626 case 0x11aa:
627 prev = combineKoreanChars(schar, mchar, 0x11a8);
628 schar = 0x1109;
629 break;
630 case 0x11ac:
631 prev = combineKoreanChars(schar, mchar, 0x11ab);
632 schar = 0x110c;
633 break;
634 case 0x11ad:
635 prev = combineKoreanChars(schar, mchar, 0x11ab);
636 schar = 0x1112;
637 break;
638 case 0x11b0:
639 prev = combineKoreanChars(schar, mchar, 0x11af);
640 schar = 0x1100;
641 break;
642 case 0x11b1:
643 prev = combineKoreanChars(schar, mchar, 0x11af);
644 schar = 0x1106;
645 break;
646 case 0x11b2:
647 prev = combineKoreanChars(schar, mchar, 0x11af);
648 schar = 0x1107;
649 break;
650 case 0x11b3:
651 prev = combineKoreanChars(schar, mchar, 0x11af);
652 schar = 0x1109;
653 break;
654 case 0x11b4:
655 prev = combineKoreanChars(schar, mchar, 0x11af);
656 schar = 0x1110;
657 break;
658 case 0x11b9:
659 prev = combineKoreanChars(schar, mchar, 0x11b8);
660 schar = 0x1109;
661 break;
662 /*
663 case 0x11bb:
664 prev = combineKoreanChars(schar, mchar, 0x11ba);
665 schar = 0x1109;
666 break;
667 */
668 default:
669
670 if (constoe(echar)) {
671
672 prev = combineKoreanChars(schar, mchar, 0);
673 schar = constoe(echar);
674 }
675 break;
676 }
677
678 emit key( prev, prev, 0, true, false );
679
680 mchar = c; echar = 0;
681
682 return combineKoreanChars(schar, mchar, 0);
683
684 }
685 else {
686 schar = 0; mchar = 0; echar = 0;
687 return c;
688 }
689
690 }
691 else /*if (c == ' ')*/ return c;
692
693
694 // and now... finally delete previous char, and return new char
695 emit key( 8, Qt::Key_Backspace, 0, true, false );
696
697
698 return combineKoreanChars( schar, mchar, echar);
699
700}
701
702ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) {
703
704 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00;
705
706}
707
708ushort Keyboard::constoe(const ushort c) {
709
710 // converts schars to echars if possible
711
712 if (0x1100 <= c && c <= 0x1112) { // schar to echar
713
714 switch (c) {
715 case 0x1100: return 0x11a8;
716 case 0x1101: return 0x11a9;
717 case 0x1102: return 0x11ab;
718 case 0x1103: return 0x11ae;
719 case 0x1105: return 0x11af;
720 case 0x1106: return 0x11b7;
721 case 0x1107: return 0x11b8;
722 case 0x1109: return 0x11ba;
723 case 0x110a: return 0x11bb;
724 case 0x110b: return 0x11bc;
725 case 0x110c: return 0x11bd;
726 case 0x110e: return 0x11be;
727 case 0x110f: return 0x11bf;
728 case 0x1110: return 0x11c0;
729 case 0x1111: return 0x11c1;
730 case 0x1112: return 0x11c2;
731 default: return 0;
732
733 }
734
735 } else { //echar to schar
736
737 switch (c) {
738 case 0x11a8: return 0x1100;
739 case 0x11a9: return 0x1101;
740 case 0x11ab: return 0x1102;
741 case 0x11ae: return 0x1103;
742 case 0x11af: return 0x1105;
743 case 0x11b7: return 0x1106;
744 case 0x11b8: return 0x1107;
745 case 0x11ba: return 0x1109;
746 case 0x11bb: return 0x110a;
747 case 0x11bc: return 0x110b;
748 case 0x11bd: return 0x110c;
749 case 0x11be: return 0x110e;
750 case 0x11bf: return 0x110f;
751 case 0x11c0: return 0x1110;
752 case 0x11c1: return 0x1111;
753 case 0x11c2: return 0x1112;
754 default: return 0;
755
756 }
757
758 }
759}
760
761
762// Keys::Keys {{{1
763
764Keys::Keys() {
765
766 Config config("locale");
767 config.setGroup( "Language" );
768 QString l = config.readEntry( "Language" );
769 if(l.isEmpty()) l = "en";
770
771 QString key_map = QPEApplication::qpeDir() + "/i18n/" + l + "/keyboard";
772
773 setKeysFromFile(key_map);
774}
775
776Keys::Keys(const char * filename) {
777
778 setKeysFromFile(filename);
779}
780
781// Keys::setKeysFromFile {{{2
782void Keys::setKeysFromFile(const char * filename) {
783
784 QFile f(filename);
785
786 if (f.open(IO_ReadOnly)) {
787
788 QTextStream t(&f);
789 int row;
790 int qcode;
791 ushort unicode;
792 int width;
793 QString buf;
794 QString comment;
795 char * xpm[256]; //couldnt be larger than that... could it?
796 QPixmap *xpm2pix = 0;
797
798 buf = t.readLine();
799 while (buf) {
800
801 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
802 // no $1 type referencing!!! this implementation of regexp sucks
803
804 // dont know of any sscanf() type funcs in Qt lib
805 QTextStream tmp (buf, IO_ReadOnly);
806 tmp >> row >> qcode >> unicode >> width >> comment;
807
808 buf = t.readLine();
809 int xpmLineCount = 0;
810 xpm2pix = 0;
811
812 // erase blank space
813 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
814
815 while (buf.contains(QRegExp("^\\s*\".*\""))) {
816
817 QString xpmBuf = buf.stripWhiteSpace();
818
819 xpm[xpmLineCount] = new char [xpmBuf.length()];
820
821 int j = 0;
822 for (ushort i = 0; i < xpmBuf.length(); i++) {
823 if (xpmBuf[i].latin1() != '"') {
824
825 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1();
826 j++;
827 }
828
829 }
830 // have to close that facker up
831 ((char *)xpm[xpmLineCount])[j] = '\0';
832
833 xpmLineCount++;
834 buf = t.readLine();
835 }
836 if (xpmLineCount) {
837
838 xpm2pix = new QPixmap((const char **)xpm);
839 for (int i = 0; i < xpmLineCount; i++)
840
841 delete [] (xpm[i]);
842
843 }
844 setKey(row, qcode, unicode, width, xpm2pix);
845 }
846 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
847
848 QTextStream tmp (buf, IO_ReadOnly);
849 ushort lower, shift;
850 tmp >> lower >> shift;
851
852 shiftMap.insert(lower, shift);
853
854 buf = t.readLine();
855 }
856 else if (buf.contains(QRegExp("^\\s*#"))) {
857
858 buf = t.readLine();
859
860 } else { // blank line, or garbage
861
862 buf = t.readLine();
863
864 }
865
866 }
867 f.close();
868 }
869
870}
871
872// Keys::setKey {{{2
873void Keys::setKey(const int row, const int qcode, const ushort unicode,
874 const int width, QPixmap *pix) {
875
876 Key * key;
877 key = new Key;
878 key->qcode = qcode;
879 key->unicode = unicode;
880 key->width = width;
881
882 // share key->pressed between same keys
883 bool found = 0;
884 for (int i = 1; i <= 5; i++) {
885 for (unsigned int j = 0; j < keys[i].count(); j++)
886 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) {
887
888 key->pressed = keys[i].at(j)->pressed;
889 found = 1;
890 }
891
892 }
893 if (!found) {
894
895 key->pressed = new bool;
896 *(key->pressed) = 0;
897 }
898
899 key->pix = pix;
900
901
902 keys[row].append(key);
903}
904// Keys:: other functions {{{2
905int Keys::width(const int row, const int col) {
906
907 return keys[row].at(col)->width;
908
909}
910ushort Keys::uni(const int row, const int col) {
911
912 return keys[row].at(col)->unicode;
913
914}
915
916int Keys::qcode(const int row, const int col) {
917
918 return keys[row].at(col)->qcode;
919}
920
921QPixmap *Keys::pix(const int row, const int col) {
922
923 return keys[row].at(col)->pix;
924
925}
926bool Keys::pressed(const int row, const int col) {
927
928 return *(keys[row].at(col)->pressed);
929}
930
931int Keys::numKeys(const int row) {
932
933 return keys[row].count();
934}
935
936void Keys::setPressed(const int row, const int col, const bool pressed) {
937
938 *(keys[row].at(col)->pressed) = pressed;
939}
940
941ushort Keys::shift(const ushort uni) {
942
943 if (shiftMap[uni]) {
944
945 return shiftMap[uni];
946 }
947 else
948 return 0;
949
950}
951
952bool *Keys::pressedPtr(const int row, const int col) {
953
954 return keys[row].at(col)->pressed;
955}
diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h
new file mode 100644
index 0000000..b524195
--- a/dev/null
+++ b/inputmethods/multikey/keyboard.h
@@ -0,0 +1,148 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qframe.h>
21#include <qmap.h>
22#include "../pickboard/pickboardcfg.h"
23#include "../pickboard/pickboardpicks.h"
24
25class QTimer;
26
27class KeyboardConfig : public DictFilterConfig
28{
29public:
30 KeyboardConfig(PickboardPicks* p) : DictFilterConfig(p), backspaces(0) { nrows = 1; }
31 virtual void generateText(const QString &s);
32 void decBackspaces() { if (backspaces) backspaces--; }
33 void incBackspaces() { backspaces++; }
34 void resetBackspaces() { backspaces = 0; }
35private:
36 int backspaces;
37};
38
39
40class KeyboardPicks : public PickboardPicks
41{
42 Q_OBJECT
43public:
44 KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0)
45 : PickboardPicks(parent, name, f) { }
46 void initialise();
47 virtual QSize sizeHint() const;
48 KeyboardConfig *dc;
49};
50
51
52class Keys {
53public:
54
55 Keys();
56 Keys(const char * filename);
57 ushort uni(const int row, const int col);
58 int qcode(const int row, const int col);
59 int width(const int row, const int col);
60 bool pressed(const int row, const int col);
61 bool *pressedPtr(const int row, const int col);
62 ushort shift(const ushort);
63 QPixmap *pix(const int row, const int col);
64 int numKeys(const int row);
65 void setKeysFromFile(const char *filename);
66 void setKey(const int row, const int qcode, const ushort unicode,
67 const int width, QPixmap *pix);
68 void setPressed(const int row, const int col, const bool pressed);
69
70private:
71
72 typedef struct Key {
73 int qcode; // are qt key codes just unicode values?
74 ushort unicode;
75 int width; // not pixels but relative key width. normal key is 2
76
77 // only needed for keys like ctrl that can have multiple keys pressed at once
78 bool *pressed;
79 QPixmap *pix;
80 };
81
82 QList<Key> keys[6];
83 QMap<ushort,ushort> shiftMap;
84
85};
86
87class Keyboard : public QFrame
88{
89 Q_OBJECT
90public:
91 Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 );
92
93 void resetState();
94
95 void mousePressEvent(QMouseEvent*);
96 void mouseReleaseEvent(QMouseEvent*);
97 void resizeEvent(QResizeEvent*);
98 void paintEvent(QPaintEvent* e);
99 //void timerEvent(QTimerEvent* e);
100 void drawKeyboard( QPainter &p, int row = -1, int col = -1);
101
102 QSize sizeHint() const;
103
104signals:
105 void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool );
106
107private slots:
108 void repeat();
109
110private:
111 int getKey( int &w, int j = -1 );
112 void clearHighlight();
113
114 bool *shift;
115 bool *lock;
116 bool *ctrl;
117 bool *alt;
118 uint useLargeKeys:1;
119 uint usePicks:1;
120
121 int pressedKeyRow;
122 int pressedKeyCol;
123
124 KeyboardPicks *picks;
125
126 int keyHeight;
127 int defaultKeyWidth;
128 int xoffs;
129
130 int unicode;
131 int qkeycode;
132 int modifiers;
133
134 int pressTid;
135 bool pressed;
136
137 Keys keys;
138 QString LANG;
139 /* for korean input */
140 ushort schar, mchar, echar;
141 ushort parseKoreanInput(ushort c);
142 ushort combineKoreanChars(const ushort s, const ushort m, const ushort e);
143 ushort constoe(const ushort c);
144
145 QTimer *repeatTimer;
146};
147
148
diff --git a/inputmethods/multikey/keyboard.pro b/inputmethods/multikey/keyboard.pro
new file mode 100644
index 0000000..2e92e06
--- a/dev/null
+++ b/inputmethods/multikey/keyboard.pro
@@ -0,0 +1,29 @@
1 TEMPLATE= lib
2 CONFIG += qt warn_on release
3 HEADERS= keyboard.h \
4 ../pickboard/pickboardcfg.h \
5 ../pickboard/pickboardpicks.h \
6 keyboardimpl.h
7 SOURCES= keyboard.cpp \
8 ../pickboard/pickboardcfg.cpp \
9 ../pickboard/pickboardpicks.cpp \
10 keyboardimpl.cpp
11 TARGET = qmultikey
12 DESTDIR = ../../plugins/inputmethods
13INCLUDEPATH += $(OPIEDIR)/include
14DEPENDPATH += ../$(OPIEDIR)/include ../../launcher
15LIBS += -lqpe
16 VERSION = 1.0.0
17
18TRANSLATIONS = ../../i18n/pt_BR/libqmultikey.ts
19TRANSLATIONS += ../../i18n/de/libqmultikey.ts
20TRANSLATIONS += ../../i18n/en/libqmultikey.ts
21TRANSLATIONS += ../../i18n/hu/libqmultikey.ts
22TRANSLATIONS += ../../i18n/sl/libqmultikey.ts
23TRANSLATIONS += ../../i18n/ja/libqmultikey.ts
24TRANSLATIONS += ../../i18n/ko/libqmultikey.ts
25TRANSLATIONS += ../../i18n/pl/libqmultikey.ts
26TRANSLATIONS += ../../i18n/no/libqmultikey.ts
27TRANSLATIONS += ../../i18n/zh_CN/libqmultikey.ts
28TRANSLATIONS += ../../i18n/zh_TW/libqmultikey.ts
29TRANSLATIONS += ../../i18n/fr/libqmultikey.ts
diff --git a/inputmethods/multikey/keyboardimpl.cpp b/inputmethods/multikey/keyboardimpl.cpp
new file mode 100644
index 0000000..2bcb0fa
--- a/dev/null
+++ b/inputmethods/multikey/keyboardimpl.cpp
@@ -0,0 +1,108 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qapplication.h>
21#include <qpixmap.h>
22#include "keyboard.h"
23#include "keyboardimpl.h"
24
25/* XPM */
26static const char * kb_xpm[] = {
27"28 13 4 1",
28" c None",
29". c #4C4C4C",
30"+ c #FFF7DD",
31"@ c #D6CFBA",
32" .......................... ",
33" .+++.+++.+++.+++.+++.++++. ",
34" .+@@.+@@.+@@.+@@.+@@.+@@@. ",
35" .......................... ",
36" .+++++.+++.+++.+++.++++++. ",
37" .+@@@@.+@@.+@@.+@@.+@@@@@. ",
38" .......................... ",
39" .++++++.+++.+++.+++.+++++. ",
40" .+@@@@@.+@@.+@@.+@@.+@@@@. ",
41" .......................... ",
42" .++++.++++++++++++++.++++. ",
43" .+@@@.+@@@@@@@@@@@@@.+@@@. ",
44" .......................... "};
45
46
47KeyboardImpl::KeyboardImpl()
48 : input(0), icn(0), ref(0)
49{
50}
51
52KeyboardImpl::~KeyboardImpl()
53{
54 delete input;
55 delete icn;
56}
57
58QWidget *KeyboardImpl::inputMethod( QWidget *parent, Qt::WFlags f )
59{
60 if ( !input )
61 input = new Keyboard( parent, "Keyboard", f );
62 return input;
63}
64
65void KeyboardImpl::resetState()
66{
67 if ( input )
68 input->resetState();
69}
70
71QPixmap *KeyboardImpl::icon()
72{
73 if ( !icn )
74 icn = new QPixmap( (const char **)kb_xpm );
75 return icn;
76}
77
78QString KeyboardImpl::name()
79{
80 return qApp->translate( "InputMethods", "Multikey" );
81// return qApp->translate( "InputMethods", "Opti" );
82}
83
84void KeyboardImpl::onKeyPress( QObject *receiver, const char *slot )
85{
86 if ( input )
87 QObject::connect( input, SIGNAL(key(ushort,ushort,ushort,bool,bool)), receiver, slot );
88}
89
90#ifndef QT_NO_COMPONENT
91QRESULT KeyboardImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
92{
93 *iface = 0;
94 if ( uuid == IID_QUnknown )
95 *iface = this;
96 else if ( uuid == IID_InputMethod )
97 *iface = this;
98
99 if ( *iface )
100 (*iface)->addRef();
101 return QS_OK;
102}
103
104Q_EXPORT_INTERFACE()
105{
106 Q_CREATE_INSTANCE( KeyboardImpl )
107}
108#endif
diff --git a/inputmethods/multikey/keyboardimpl.h b/inputmethods/multikey/keyboardimpl.h
new file mode 100644
index 0000000..e756364
--- a/dev/null
+++ b/inputmethods/multikey/keyboardimpl.h
@@ -0,0 +1,51 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef KEYBOARDIMPL_H
21#define KEYBOARDIMPL_H
22
23#include <qpe/inputmethodinterface.h>
24
25class Keyboard;
26class QPixmap;
27
28class KeyboardImpl : public InputMethodInterface
29{
30public:
31 KeyboardImpl();
32 virtual ~KeyboardImpl();
33
34#ifndef QT_NO_COMPONENT
35 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
36 Q_REFCOUNT
37#endif
38
39 virtual QWidget *inputMethod( QWidget *parent, Qt::WFlags f );
40 virtual void resetState();
41 virtual QPixmap *icon();
42 virtual QString name();
43 virtual void onKeyPress( QObject *receiver, const char *slot );
44
45private:
46 Keyboard *input;
47 QPixmap *icn;
48 ulong ref;
49};
50
51#endif
diff --git a/inputmethods/multikey/opie-keyboard.control b/inputmethods/multikey/opie-keyboard.control
new file mode 100644
index 0000000..42df4cd
--- a/dev/null
+++ b/inputmethods/multikey/opie-keyboard.control
@@ -0,0 +1,9 @@
1Files: plugins/inputmethods/libqmultikey.so*
2Priority: optional
3Section: opie/inputmethods
4Maintainer: Jake Richardson (jake@asdfnews.org)
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION)
8Description: Multiple language keyboard
9 Keyboard for inputing multiple languages in the OPIE environment.
diff --git a/inputmethods/multikey/qpe-keyboard.postinst b/inputmethods/multikey/qpe-keyboard.postinst
new file mode 100755
index 0000000..c254b01
--- a/dev/null
+++ b/inputmethods/multikey/qpe-keyboard.postinst
@@ -0,0 +1,2 @@
1#!/bin/sh
2/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadInputMethods()"
diff --git a/inputmethods/multikey/qpe-keyboard.postrm b/inputmethods/multikey/qpe-keyboard.postrm
new file mode 100755
index 0000000..c254b01
--- a/dev/null
+++ b/inputmethods/multikey/qpe-keyboard.postrm
@@ -0,0 +1,2 @@
1#!/bin/sh
2/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadInputMethods()"