summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp6
1 files changed, 2 insertions, 4 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index d0cfa51..8f4d562 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -1,162 +1,161 @@
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 46 // get the default font
47 Config qpeConfig( "qpe" ); 47 Config qpeConfig( "qpe" );
48 qpeConfig.setGroup( "Appearance" ); 48 qpeConfig.setGroup( "Appearance" );
49 QString familyStr = qpeConfig.readEntry( "FontFamily", "fixed" ); 49 QString familyStr = qpeConfig.readEntry( "FontFamily", "fixed" );
50 50
51 setFont( QFont( familyStr, 8 ) ); 51 setFont( QFont( familyStr, 8 ) );
52 52
53 picks = new KeyboardPicks( this ); 53 picks = new KeyboardPicks( this );
54 picks->setFont( QFont( familyStr, 8 ) ); 54 picks->setFont( QFont( familyStr, 8 ) );
55 picks->initialise(); 55 picks->initialise();
56 if (usePicks) { 56 if (usePicks) {
57 57
58 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 58 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
59 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 59 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
60 60
61 } else picks->hide(); 61 } else picks->hide();
62 62
63 Config config("locale"); 63 Config config("locale");
64 config.setGroup( "Language" ); 64 config.setGroup( "Language" );
65 //LANG = config.readEntry( "Language", "en" ); 65 LANG = config.readEntry( "Language", "en" );
66 LANG = "ko";
67 66
68 repeatTimer = new QTimer( this ); 67 repeatTimer = new QTimer( this );
69 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 68 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
70 69
71} 70}
72 71
73/* Keyboard::resizeEvent {{{1 */ 72/* Keyboard::resizeEvent {{{1 */
74void Keyboard::resizeEvent(QResizeEvent*) 73void Keyboard::resizeEvent(QResizeEvent*)
75{ 74{
76 int ph = picks->sizeHint().height(); 75 int ph = picks->sizeHint().height();
77 picks->setGeometry( 0, 0, width(), ph ); 76 picks->setGeometry( 0, 0, width(), ph );
78 keyHeight = (height()-(usePicks ? ph : 0))/5; 77 keyHeight = (height()-(usePicks ? ph : 0))/5;
79 78
80 int nk; // number of keys? 79 int nk; // number of keys?
81 if ( useLargeKeys ) { 80 if ( useLargeKeys ) {
82 nk = 15; 81 nk = 15;
83 } else { 82 } else {
84 nk = 19; 83 nk = 19;
85 } 84 }
86 defaultKeyWidth = (width()/nk)/2; 85 defaultKeyWidth = (width()/nk)/2;
87 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? 86 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
88 87
89} 88}
90 89
91/* KeyboardPicks::initialize {{{1 */ 90/* KeyboardPicks::initialize {{{1 */
92void KeyboardPicks::initialise() 91void KeyboardPicks::initialise()
93{ 92{
94 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 93 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
95 mode = 0; 94 mode = 0;
96 dc = new KeyboardConfig(this); 95 dc = new KeyboardConfig(this);
97 configs.append(dc); 96 configs.append(dc);
98} 97}
99 98
100/* KeyboardPicks::sizeHint {{{1 */ 99/* KeyboardPicks::sizeHint {{{1 */
101QSize KeyboardPicks::sizeHint() const 100QSize KeyboardPicks::sizeHint() const
102{ 101{
103 return QSize(240,fontMetrics().lineSpacing()); 102 return QSize(240,fontMetrics().lineSpacing());
104} 103}
105 104
106 105
107/* KeyboardConfig::generateText {{{1 */ 106/* KeyboardConfig::generateText {{{1 */
108void KeyboardConfig::generateText(const QString &s) 107void KeyboardConfig::generateText(const QString &s)
109{ 108{
110#if defined(Q_WS_QWS) || defined(_WS_QWS_) 109#if defined(Q_WS_QWS) || defined(_WS_QWS_)
111 for (int i=0; i<(int)backspaces; i++) { 110 for (int i=0; i<(int)backspaces; i++) {
112 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); 111 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );
113 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); 112 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );
114 } 113 }
115 for (int i=0; i<(int)s.length(); i++) { 114 for (int i=0; i<(int)s.length(); i++) {
116 parent->emitKey( s[i].unicode(), 0, 0, true, false ); 115 parent->emitKey( s[i].unicode(), 0, 0, true, false );
117 parent->emitKey( s[i].unicode(), 0, 0, false, false ); 116 parent->emitKey( s[i].unicode(), 0, 0, false, false );
118 } 117 }
119 parent->emitKey( 0, Qt::Key_Space, 0, true, false ); 118 parent->emitKey( 0, Qt::Key_Space, 0, true, false );
120 parent->emitKey( 0, Qt::Key_Space, 0, false, false ); 119 parent->emitKey( 0, Qt::Key_Space, 0, false, false );
121 backspaces = 0; 120 backspaces = 0;
122#endif 121#endif
123} 122}
124 123
125 124
126 125
127 126
128/* Keyboard::paintEvent {{{1 */ 127/* Keyboard::paintEvent {{{1 */
129void Keyboard::paintEvent(QPaintEvent* e) 128void Keyboard::paintEvent(QPaintEvent* e)
130{ 129{
131 QPainter painter(this); 130 QPainter painter(this);
132 painter.setClipRect(e->rect()); 131 painter.setClipRect(e->rect());
133 drawKeyboard( painter ); 132 drawKeyboard( painter );
134 picks->dc->draw( &painter ); 133 picks->dc->draw( &painter );
135} 134}
136 135
137 136
138/* Keyboard::drawKeyboard {{{1 */ 137/* Keyboard::drawKeyboard {{{1 */
139 138
140void Keyboard::drawKeyboard(QPainter &p, int row, int col) 139void Keyboard::drawKeyboard(QPainter &p, int row, int col)
141{ 140{
142 QColor keycolor = 141 QColor keycolor =
143 QColor(240,240,240); 142 QColor(240,240,240);
144 QColor keycolor_pressed = QColor(171,183,198); 143 QColor keycolor_pressed = QColor(171,183,198);
145 QColor keycolor_lines = QColor(138,148,160); 144 QColor keycolor_lines = QColor(138,148,160);
146 QColor textcolor = QColor(43,54,68); 145 QColor textcolor = QColor(43,54,68);
147 146
148 147
149 if (row != -1 && col != -1) { //just redraw one key 148 if (row != -1 && col != -1) { //just redraw one key
150 149
151 int x = 0; 150 int x = 0;
152 for (int i = 0; i < col; i++) { 151 for (int i = 0; i < col; i++) {
153 152
154 x += keys.width(row, i) * defaultKeyWidth; 153 x += keys.width(row, i) * defaultKeyWidth;
155 } 154 }
156 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 155 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
157 156
158 int keyWidth = keys.width(row, col); 157 int keyWidth = keys.width(row, col);
159 158
160 p.fillRect(x + 1, y + 1, 159 p.fillRect(x + 1, y + 1,
161 keyWidth * defaultKeyWidth - 1, keyHeight - 1, 160 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
162 pressed || keys.pressed(row, col) ? keycolor_pressed : keycolor); 161 pressed || keys.pressed(row, col) ? keycolor_pressed : keycolor);
@@ -681,194 +680,193 @@ ushort Keyboard::parseKoreanInput (ushort c) {
681 break; 680 break;
682 } 681 }
683 682
684 emit key( prev, prev, 0, true, false ); 683 emit key( prev, prev, 0, true, false );
685 684
686 mchar = c; echar = 0; 685 mchar = c; echar = 0;
687 686
688 return combineKoreanChars(schar, mchar, 0); 687 return combineKoreanChars(schar, mchar, 0);
689 688
690 } 689 }
691 else { 690 else {
692 schar = 0; mchar = 0; echar = 0; 691 schar = 0; mchar = 0; echar = 0;
693 return c; 692 return c;
694 } 693 }
695 694
696 } 695 }
697 else /*if (c == ' ')*/ return c; 696 else /*if (c == ' ')*/ return c;
698 697
699 698
700 // and now... finally delete previous char, and return new char 699 // and now... finally delete previous char, and return new char
701 emit key( 8, Qt::Key_Backspace, 0, true, false ); 700 emit key( 8, Qt::Key_Backspace, 0, true, false );
702 701
703 702
704 return combineKoreanChars( schar, mchar, echar); 703 return combineKoreanChars( schar, mchar, echar);
705 704
706} 705}
707 706
708ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { 707ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) {
709 708
710 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; 709 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00;
711 710
712} 711}
713 712
714ushort Keyboard::constoe(const ushort c) { 713ushort Keyboard::constoe(const ushort c) {
715 714
716 // converts schars to echars if possible 715 // converts schars to echars if possible
717 716
718 if (0x1100 <= c && c <= 0x1112) { // schar to echar 717 if (0x1100 <= c && c <= 0x1112) { // schar to echar
719 718
720 switch (c) { 719 switch (c) {
721 case 0x1100: return 0x11a8; 720 case 0x1100: return 0x11a8;
722 case 0x1101: return 0x11a9; 721 case 0x1101: return 0x11a9;
723 case 0x1102: return 0x11ab; 722 case 0x1102: return 0x11ab;
724 case 0x1103: return 0x11ae; 723 case 0x1103: return 0x11ae;
725 case 0x1105: return 0x11af; 724 case 0x1105: return 0x11af;
726 case 0x1106: return 0x11b7; 725 case 0x1106: return 0x11b7;
727 case 0x1107: return 0x11b8; 726 case 0x1107: return 0x11b8;
728 case 0x1109: return 0x11ba; 727 case 0x1109: return 0x11ba;
729 case 0x110a: return 0x11bb; 728 case 0x110a: return 0x11bb;
730 case 0x110b: return 0x11bc; 729 case 0x110b: return 0x11bc;
731 case 0x110c: return 0x11bd; 730 case 0x110c: return 0x11bd;
732 case 0x110e: return 0x11be; 731 case 0x110e: return 0x11be;
733 case 0x110f: return 0x11bf; 732 case 0x110f: return 0x11bf;
734 case 0x1110: return 0x11c0; 733 case 0x1110: return 0x11c0;
735 case 0x1111: return 0x11c1; 734 case 0x1111: return 0x11c1;
736 case 0x1112: return 0x11c2; 735 case 0x1112: return 0x11c2;
737 default: return 0; 736 default: return 0;
738 737
739 } 738 }
740 739
741 } else { //echar to schar 740 } else { //echar to schar
742 741
743 switch (c) { 742 switch (c) {
744 case 0x11a8: return 0x1100; 743 case 0x11a8: return 0x1100;
745 case 0x11a9: return 0x1101; 744 case 0x11a9: return 0x1101;
746 case 0x11ab: return 0x1102; 745 case 0x11ab: return 0x1102;
747 case 0x11ae: return 0x1103; 746 case 0x11ae: return 0x1103;
748 case 0x11af: return 0x1105; 747 case 0x11af: return 0x1105;
749 case 0x11b7: return 0x1106; 748 case 0x11b7: return 0x1106;
750 case 0x11b8: return 0x1107; 749 case 0x11b8: return 0x1107;
751 case 0x11ba: return 0x1109; 750 case 0x11ba: return 0x1109;
752 case 0x11bb: return 0x110a; 751 case 0x11bb: return 0x110a;
753 case 0x11bc: return 0x110b; 752 case 0x11bc: return 0x110b;
754 case 0x11bd: return 0x110c; 753 case 0x11bd: return 0x110c;
755 case 0x11be: return 0x110e; 754 case 0x11be: return 0x110e;
756 case 0x11bf: return 0x110f; 755 case 0x11bf: return 0x110f;
757 case 0x11c0: return 0x1110; 756 case 0x11c0: return 0x1110;
758 case 0x11c1: return 0x1111; 757 case 0x11c1: return 0x1111;
759 case 0x11c2: return 0x1112; 758 case 0x11c2: return 0x1112;
760 default: return 0; 759 default: return 0;
761 760
762 } 761 }
763 762
764 } 763 }
765} 764}
766 765
767 766
768// Keys::Keys {{{1 767// Keys::Keys {{{1
769 768
770Keys::Keys() { 769Keys::Keys() {
771 770
772 Config config("locale"); 771 Config config("locale");
773 config.setGroup( "Language" ); 772 config.setGroup( "Language" );
774 QString l = config.readEntry( "Language" , "en" ); 773 QString l = config.readEntry( "Language" , "en" );
775 774
776 QString key_map = QPEApplication::qpeDir() + "/share/multikey/" 775 QString key_map = QPEApplication::qpeDir() + "/share/multikey/"
777 + /* l // testing korean for now */ 776 + l + ".keymap";
778 + "ko.keymap";
779 777
780 setKeysFromFile(key_map); 778 setKeysFromFile(key_map);
781} 779}
782 780
783Keys::Keys(const char * filename) { 781Keys::Keys(const char * filename) {
784 782
785 setKeysFromFile(filename); 783 setKeysFromFile(filename);
786} 784}
787 785
788// Keys::setKeysFromFile {{{2 786// Keys::setKeysFromFile {{{2
789void Keys::setKeysFromFile(const char * filename) { 787void Keys::setKeysFromFile(const char * filename) {
790 788
791 QFile f(filename); 789 QFile f(filename);
792 790
793 if (f.open(IO_ReadOnly)) { 791 if (f.open(IO_ReadOnly)) {
794 792
795 QTextStream t(&f); 793 QTextStream t(&f);
796 int row; 794 int row;
797 int qcode; 795 int qcode;
798 ushort unicode; 796 ushort unicode;
799 int width; 797 int width;
800 QString buf; 798 QString buf;
801 QString comment; 799 QString comment;
802 char * xpm[256]; //couldnt be larger than that... could it? 800 char * xpm[256]; //couldnt be larger than that... could it?
803 QPixmap *xpm2pix = 0; 801 QPixmap *xpm2pix = 0;
804 802
805 buf = t.readLine(); 803 buf = t.readLine();
806 while (buf) { 804 while (buf) {
807 805
808 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { 806 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
809 // no $1 type referencing!!! this implementation of regexp sucks 807 // no $1 type referencing!!! this implementation of regexp sucks
810 808
811 // dont know of any sscanf() type funcs in Qt lib 809 // dont know of any sscanf() type funcs in Qt lib
812 QTextStream tmp (buf, IO_ReadOnly); 810 QTextStream tmp (buf, IO_ReadOnly);
813 tmp >> row >> qcode >> unicode >> width >> comment; 811 tmp >> row >> qcode >> unicode >> width >> comment;
814 812
815 buf = t.readLine(); 813 buf = t.readLine();
816 int xpmLineCount = 0; 814 int xpmLineCount = 0;
817 xpm2pix = 0; 815 xpm2pix = 0;
818 816
819 // erase blank space 817 // erase blank space
820 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); 818 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
821 819
822 while (buf.contains(QRegExp("^\\s*\".*\""))) { 820 while (buf.contains(QRegExp("^\\s*\".*\""))) {
823 821
824 QString xpmBuf = buf.stripWhiteSpace(); 822 QString xpmBuf = buf.stripWhiteSpace();
825 823
826 xpm[xpmLineCount] = new char [xpmBuf.length()]; 824 xpm[xpmLineCount] = new char [xpmBuf.length()];
827 825
828 int j = 0; 826 int j = 0;
829 for (ushort i = 0; i < xpmBuf.length(); i++) { 827 for (ushort i = 0; i < xpmBuf.length(); i++) {
830 if (xpmBuf[i].latin1() != '"') { 828 if (xpmBuf[i].latin1() != '"') {
831 829
832 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); 830 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1();
833 j++; 831 j++;
834 } 832 }
835 833
836 } 834 }
837 // have to close that facker up 835 // have to close that facker up
838 ((char *)xpm[xpmLineCount])[j] = '\0'; 836 ((char *)xpm[xpmLineCount])[j] = '\0';
839 837
840 xpmLineCount++; 838 xpmLineCount++;
841 buf = t.readLine(); 839 buf = t.readLine();
842 } 840 }
843 if (xpmLineCount) { 841 if (xpmLineCount) {
844 842
845 xpm2pix = new QPixmap((const char **)xpm); 843 xpm2pix = new QPixmap((const char **)xpm);
846 for (int i = 0; i < xpmLineCount; i++) 844 for (int i = 0; i < xpmLineCount; i++)
847 845
848 delete [] (xpm[i]); 846 delete [] (xpm[i]);
849 847
850 } 848 }
851 setKey(row, qcode, unicode, width, xpm2pix); 849 setKey(row, qcode, unicode, width, xpm2pix);
852 } 850 }
853 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 851 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
854 852
855 QTextStream tmp (buf, IO_ReadOnly); 853 QTextStream tmp (buf, IO_ReadOnly);
856 ushort lower, shift; 854 ushort lower, shift;
857 tmp >> lower >> shift; 855 tmp >> lower >> shift;
858 856
859 shiftMap.insert(lower, shift); 857 shiftMap.insert(lower, shift);
860 858
861 buf = t.readLine(); 859 buf = t.readLine();
862 } 860 }
863 else if (buf.contains(QRegExp("^\\s*#"))) { 861 else if (buf.contains(QRegExp("^\\s*#"))) {
864 862
865 buf = t.readLine(); 863 buf = t.readLine();
866 864
867 } else { // blank line, or garbage 865 } else { // blank line, or garbage
868 866
869 buf = t.readLine(); 867 buf = t.readLine();
870 868
871 } 869 }
872 870
873 } 871 }
874 f.close(); 872 f.close();