summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index 92da8ca..3e43978 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -1,109 +1,114 @@
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 <qpe/qpeapplication.h> 29#include <qpe/qpeapplication.h>
30#include <qpe/config.h> 30#include <qpe/config.h>
31#include <ctype.h> 31#include <ctype.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qtextstream.h> 33#include <qtextstream.h>
34 34
35#include <sys/utsname.h> 35#include <sys/utsname.h>
36 36
37 37
38#define USE_SMALL_BACKSPACE 38#define USE_SMALL_BACKSPACE
39 39
40/* Keyboard::Keyboard {{{1 */ 40/* Keyboard::Keyboard {{{1 */
41Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : 41Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
42 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), 42 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0),
43 alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1), 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) 44 unicode(-1), qkeycode(0), modifiers(0), LANG("ko"), schar(0), mchar(0), echar(0)
45{ 45{
46 // get the default font
47 Config qpeConfig( "qpe" );
48 qpeConfig.setGroup( "Appearance" );
49 QString familyStr = qpeConfig.readEntry( "FontFamily", "fixed" );
50
51 setFont( QFont( familyStr, 8 ) );
46 52
47 picks = new KeyboardPicks( this ); 53 picks = new KeyboardPicks( this );
48 picks->setFont( QFont( "helvetica", 8 ) ); 54 picks->setFont( QFont( familyStr, 8 ) );
49 setFont( QFont( "helvetica", 8 ) );
50 picks->initialise(); 55 picks->initialise();
51 if (usePicks) { 56 if (usePicks) {
52 57
53 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 58 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
54 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 59 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
55 60
56 } else picks->hide(); 61 } else picks->hide();
57 62
58 Config config("locale"); 63 Config config("locale");
59 config.setGroup( "Language" ); 64 config.setGroup( "Language" );
60 LANG = config.readEntry( "Language" ); 65 //LANG = config.readEntry( "Language", "en" );
61 if(LANG.isEmpty()) LANG = "en"; 66 LANG = "ko";
62 67
63 repeatTimer = new QTimer( this ); 68 repeatTimer = new QTimer( this );
64 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 69 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
65 70
66} 71}
67 72
68/* Keyboard::resizeEvent {{{1 */ 73/* Keyboard::resizeEvent {{{1 */
69void Keyboard::resizeEvent(QResizeEvent*) 74void Keyboard::resizeEvent(QResizeEvent*)
70{ 75{
71 int ph = picks->sizeHint().height(); 76 int ph = picks->sizeHint().height();
72 picks->setGeometry( 0, 0, width(), ph ); 77 picks->setGeometry( 0, 0, width(), ph );
73 keyHeight = (height()-(usePicks ? ph : 0))/5; 78 keyHeight = (height()-(usePicks ? ph : 0))/5;
74 79
75 int nk; // number of keys? 80 int nk; // number of keys?
76 if ( useLargeKeys ) { 81 if ( useLargeKeys ) {
77 nk = 15; 82 nk = 15;
78 } else { 83 } else {
79 nk = 19; 84 nk = 19;
80 } 85 }
81 defaultKeyWidth = (width()/nk)/2; 86 defaultKeyWidth = (width()/nk)/2;
82 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? 87 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
83 88
84} 89}
85 90
86/* KeyboardPicks::initialize {{{1 */ 91/* KeyboardPicks::initialize {{{1 */
87void KeyboardPicks::initialise() 92void KeyboardPicks::initialise()
88{ 93{
89 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 94 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
90 mode = 0; 95 mode = 0;
91 dc = new KeyboardConfig(this); 96 dc = new KeyboardConfig(this);
92 configs.append(dc); 97 configs.append(dc);
93} 98}
94 99
95/* KeyboardPicks::sizeHint {{{1 */ 100/* KeyboardPicks::sizeHint {{{1 */
96QSize KeyboardPicks::sizeHint() const 101QSize KeyboardPicks::sizeHint() const
97{ 102{
98 return QSize(240,fontMetrics().lineSpacing()); 103 return QSize(240,fontMetrics().lineSpacing());
99} 104}
100 105
101 106
102/* KeyboardConfig::generateText {{{1 */ 107/* KeyboardConfig::generateText {{{1 */
103void KeyboardConfig::generateText(const QString &s) 108void KeyboardConfig::generateText(const QString &s)
104{ 109{
105#if defined(Q_WS_QWS) || defined(_WS_QWS_) 110#if defined(Q_WS_QWS) || defined(_WS_QWS_)
106 for (int i=0; i<(int)backspaces; i++) { 111 for (int i=0; i<(int)backspaces; i++) {
107 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); 112 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );
108 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); 113 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );
109 } 114 }
@@ -401,97 +406,97 @@ void Keyboard::mouseReleaseEvent(QMouseEvent*)
401 repaint(FALSE); 406 repaint(FALSE);
402 407
403 } 408 }
404 else 409 else
405 410
406 clearHighlight(); 411 clearHighlight();
407} 412}
408 413
409/* Keyboard::timerEvent {{{1 */ 414/* Keyboard::timerEvent {{{1 */
410/* 415/*
411void Keyboard::timerEvent(QTimerEvent* e) 416void Keyboard::timerEvent(QTimerEvent* e)
412{ 417{
413 if ( e->timerId() == pressTid ) { 418 if ( e->timerId() == pressTid ) {
414 killTimer(pressTid); 419 killTimer(pressTid);
415 pressTid = 0; 420 pressTid = 0;
416 if ( !pressed ) 421 if ( !pressed )
417 cout << "calling clearHighlight from timerEvent\n"; 422 cout << "calling clearHighlight from timerEvent\n";
418 clearHighlight(); 423 clearHighlight();
419 } 424 }
420} 425}
421*/ 426*/
422 427
423void Keyboard::repeat() 428void Keyboard::repeat()
424{ 429{
425 430
426 repeatTimer->start( 200 ); 431 repeatTimer->start( 200 );
427 emit key( unicode, 0, modifiers, true, true ); 432 emit key( unicode, 0, modifiers, true, true );
428} 433}
429 434
430void Keyboard::clearHighlight() 435void Keyboard::clearHighlight()
431{ 436{
432 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { 437 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) {
433 int tmpRow = pressedKeyRow; 438 int tmpRow = pressedKeyRow;
434 int tmpCol = pressedKeyCol; 439 int tmpCol = pressedKeyCol;
435 440
436 pressedKeyRow = -1; 441 pressedKeyRow = -1;
437 pressedKeyCol = -1; 442 pressedKeyCol = -1;
438 443
439 QPainter p(this); 444 QPainter p(this);
440 drawKeyboard(p, tmpRow, tmpCol); 445 drawKeyboard(p, tmpRow, tmpCol);
441 } 446 }
442} 447}
443 448
444 449
445/* Keyboard::sizeHint {{{1 */ 450/* Keyboard::sizeHint {{{1 */
446QSize Keyboard::sizeHint() const 451QSize Keyboard::sizeHint() const
447{ 452{
448 QFontMetrics fm=fontMetrics(); 453 QFontMetrics fm=fontMetrics();
449 int keyHeight = fm.lineSpacing()+2; 454 int keyHeight = fm.lineSpacing();
450 455
451 return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); 456 return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1);
452} 457}
453 458
454 459
455void Keyboard::resetState() 460void Keyboard::resetState()
456{ 461{
457 schar = mchar = echar = 0; 462 schar = mchar = echar = 0;
458 picks->resetState(); 463 picks->resetState();
459} 464}
460 465
461/* korean input functions {{{1 466/* korean input functions {{{1
462 * 467 *
463 * TODO 468 * TODO
464 * one major problem with this implementation is that you can't move the 469 * 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 470 * cursor after inputing korean chars, otherwise it will eat up and replace
466 * the char before the cursor you move to. fix that 471 * the char before the cursor you move to. fix that
467 * 472 *
468 * make a kor/eng swaping key 473 * make a kor/eng swaping key
469 * 474 *
470 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 475 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
471 * 476 *
472 * how korean input works 477 * how korean input works
473 * 478 *
474 * all following chars means unicode char value and are in hex 479 * all following chars means unicode char value and are in hex
475 * 480 *
476 * ÃÊÀ½ = schar (start char) 481 * ÃÊÀ½ = schar (start char)
477 * ÁßÀ½ = mchar (middle char) 482 * ÁßÀ½ = mchar (middle char)
478 * ³¡À½ = echar (end char) 483 * ³¡À½ = echar (end char)
479 * 484 *
480 * there are 19 schars. unicode position is at 1100 - 1112 485 * there are 19 schars. unicode position is at 1100 - 1112
481 * there are 21 mchars. unicode position is at 1161 - 1175 486 * there are 21 mchars. unicode position is at 1161 - 1175
482 * there are 27 echars. unicode position is at 11a8 - 11c2 487 * there are 27 echars. unicode position is at 11a8 - 11c2
483 * 488 *
484 * the map with everything combined is at ac00 - d7a3 489 * the map with everything combined is at ac00 - d7a3
485 * 490 *
486 */ 491 */
487 492
488ushort Keyboard::parseKoreanInput (ushort c) { 493ushort Keyboard::parseKoreanInput (ushort c) {
489 494
490 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) 495 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
491 || 496 ||
492 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode 497 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
493 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { 498 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
494 499
495 schar = 0, mchar = 0, echar = 0; 500 schar = 0, mchar = 0, echar = 0;
496 return c; 501 return c;
497 } 502 }
@@ -723,97 +728,99 @@ ushort Keyboard::constoe(const ushort c) {
723 case 0x110a: return 0x11bb; 728 case 0x110a: return 0x11bb;
724 case 0x110b: return 0x11bc; 729 case 0x110b: return 0x11bc;
725 case 0x110c: return 0x11bd; 730 case 0x110c: return 0x11bd;
726 case 0x110e: return 0x11be; 731 case 0x110e: return 0x11be;
727 case 0x110f: return 0x11bf; 732 case 0x110f: return 0x11bf;
728 case 0x1110: return 0x11c0; 733 case 0x1110: return 0x11c0;
729 case 0x1111: return 0x11c1; 734 case 0x1111: return 0x11c1;
730 case 0x1112: return 0x11c2; 735 case 0x1112: return 0x11c2;
731 default: return 0; 736 default: return 0;
732 737
733 } 738 }
734 739
735 } else { //echar to schar 740 } else { //echar to schar
736 741
737 switch (c) { 742 switch (c) {
738 case 0x11a8: return 0x1100; 743 case 0x11a8: return 0x1100;
739 case 0x11a9: return 0x1101; 744 case 0x11a9: return 0x1101;
740 case 0x11ab: return 0x1102; 745 case 0x11ab: return 0x1102;
741 case 0x11ae: return 0x1103; 746 case 0x11ae: return 0x1103;
742 case 0x11af: return 0x1105; 747 case 0x11af: return 0x1105;
743 case 0x11b7: return 0x1106; 748 case 0x11b7: return 0x1106;
744 case 0x11b8: return 0x1107; 749 case 0x11b8: return 0x1107;
745 case 0x11ba: return 0x1109; 750 case 0x11ba: return 0x1109;
746 case 0x11bb: return 0x110a; 751 case 0x11bb: return 0x110a;
747 case 0x11bc: return 0x110b; 752 case 0x11bc: return 0x110b;
748 case 0x11bd: return 0x110c; 753 case 0x11bd: return 0x110c;
749 case 0x11be: return 0x110e; 754 case 0x11be: return 0x110e;
750 case 0x11bf: return 0x110f; 755 case 0x11bf: return 0x110f;
751 case 0x11c0: return 0x1110; 756 case 0x11c0: return 0x1110;
752 case 0x11c1: return 0x1111; 757 case 0x11c1: return 0x1111;
753 case 0x11c2: return 0x1112; 758 case 0x11c2: return 0x1112;
754 default: return 0; 759 default: return 0;
755 760
756 } 761 }
757 762
758 } 763 }
759} 764}
760 765
761 766
762// Keys::Keys {{{1 767// Keys::Keys {{{1
763 768
764Keys::Keys() { 769Keys::Keys() {
765 770
766 Config config("locale"); 771 Config config("locale");
767 config.setGroup( "Language" ); 772 config.setGroup( "Language" );
768 QString l = config.readEntry( "Language" ); 773 QString l = config.readEntry( "Language" );
769 if(l.isEmpty()) l = "en"; 774 if(l.isEmpty()) l = "en";
770 775
771 QString key_map = QPEApplication::qpeDir() + "/i18n/" + l + "/keyboard"; 776 QString key_map = QPEApplication::qpeDir() + "/share/multikey/"
777 + /* l // testing korean for now */
778 + "ko.keymap";
772 779
773 setKeysFromFile(key_map); 780 setKeysFromFile(key_map);
774} 781}
775 782
776Keys::Keys(const char * filename) { 783Keys::Keys(const char * filename) {
777 784
778 setKeysFromFile(filename); 785 setKeysFromFile(filename);
779} 786}
780 787
781// Keys::setKeysFromFile {{{2 788// Keys::setKeysFromFile {{{2
782void Keys::setKeysFromFile(const char * filename) { 789void Keys::setKeysFromFile(const char * filename) {
783 790
784 QFile f(filename); 791 QFile f(filename);
785 792
786 if (f.open(IO_ReadOnly)) { 793 if (f.open(IO_ReadOnly)) {
787 794
788 QTextStream t(&f); 795 QTextStream t(&f);
789 int row; 796 int row;
790 int qcode; 797 int qcode;
791 ushort unicode; 798 ushort unicode;
792 int width; 799 int width;
793 QString buf; 800 QString buf;
794 QString comment; 801 QString comment;
795 char * xpm[256]; //couldnt be larger than that... could it? 802 char * xpm[256]; //couldnt be larger than that... could it?
796 QPixmap *xpm2pix = 0; 803 QPixmap *xpm2pix = 0;
797 804
798 buf = t.readLine(); 805 buf = t.readLine();
799 while (buf) { 806 while (buf) {
800 807
801 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { 808 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
802 // no $1 type referencing!!! this implementation of regexp sucks 809 // no $1 type referencing!!! this implementation of regexp sucks
803 810
804 // dont know of any sscanf() type funcs in Qt lib 811 // dont know of any sscanf() type funcs in Qt lib
805 QTextStream tmp (buf, IO_ReadOnly); 812 QTextStream tmp (buf, IO_ReadOnly);
806 tmp >> row >> qcode >> unicode >> width >> comment; 813 tmp >> row >> qcode >> unicode >> width >> comment;
807 814
808 buf = t.readLine(); 815 buf = t.readLine();
809 int xpmLineCount = 0; 816 int xpmLineCount = 0;
810 xpm2pix = 0; 817 xpm2pix = 0;
811 818
812 // erase blank space 819 // erase blank space
813 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); 820 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
814 821
815 while (buf.contains(QRegExp("^\\s*\".*\""))) { 822 while (buf.contains(QRegExp("^\\s*\".*\""))) {
816 823
817 QString xpmBuf = buf.stripWhiteSpace(); 824 QString xpmBuf = buf.stripWhiteSpace();
818 825
819 xpm[xpmLineCount] = new char [xpmBuf.length()]; 826 xpm[xpmLineCount] = new char [xpmBuf.length()];