author | hash <hash> | 2002-08-21 18:12:55 (UTC) |
---|---|---|
committer | hash <hash> | 2002-08-21 18:12:55 (UTC) |
commit | 33fb38da29cfb4b29eff08928742b8d6918eb852 (patch) (unidiff) | |
tree | db63fcd49acf5ce9067289ae1a8aac101d43bc11 | |
parent | 0a61be3b42b4b152468a5ef2def4a18baeda9b4f (diff) | |
download | opie-33fb38da29cfb4b29eff08928742b8d6918eb852.zip opie-33fb38da29cfb4b29eff08928742b8d6918eb852.tar.gz opie-33fb38da29cfb4b29eff08928742b8d6918eb852.tar.bz2 |
fixed segfault when no keymap is installed
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index 949164a..d5a7afd 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -1,779 +1,781 @@ | |||
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 | #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 */ |
43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : | 43 | Keyboard::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), |
45 | alt(0), useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1), | 45 | alt(0), 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) { |
70 | 70 | ||
71 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 71 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
72 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 72 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
73 | 73 | ||
74 | } else picks->hide(); | 74 | } else picks->hide(); |
75 | 75 | ||
76 | loadKeyboardColors(); | 76 | loadKeyboardColors(); |
77 | 77 | ||
78 | keys = new Keys(); | 78 | keys = new Keys(); |
79 | 79 | ||
80 | repeatTimer = new QTimer( this ); | 80 | repeatTimer = new QTimer( this ); |
81 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | 81 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); |
82 | 82 | ||
83 | } | 83 | } |
84 | 84 | ||
85 | Keyboard::~Keyboard() { | 85 | Keyboard::~Keyboard() { |
86 | 86 | ||
87 | if ( configdlg ) { | 87 | if ( configdlg ) { |
88 | delete (ConfigDlg *) configdlg; | 88 | delete (ConfigDlg *) configdlg; |
89 | configdlg = 0; | 89 | configdlg = 0; |
90 | } | 90 | } |
91 | 91 | ||
92 | } | 92 | } |
93 | 93 | ||
94 | /* Keyboard::resizeEvent {{{1 */ | 94 | /* Keyboard::resizeEvent {{{1 */ |
95 | void Keyboard::resizeEvent(QResizeEvent*) | 95 | void Keyboard::resizeEvent(QResizeEvent*) |
96 | { | 96 | { |
97 | int ph = picks->sizeHint().height(); | 97 | int ph = picks->sizeHint().height(); |
98 | picks->setGeometry( 0, 0, width(), ph ); | 98 | picks->setGeometry( 0, 0, width(), ph ); |
99 | keyHeight = (height()-(usePicks ? ph : 0))/5; | 99 | keyHeight = (height()-(usePicks ? ph : 0))/5; |
100 | 100 | ||
101 | int nk; // number of keys? | 101 | int nk; // number of keys? |
102 | if ( useLargeKeys ) { | 102 | if ( useLargeKeys ) { |
103 | nk = 15; | 103 | nk = 15; |
104 | } else { | 104 | } else { |
105 | nk = 19; | 105 | nk = 19; |
106 | } | 106 | } |
107 | defaultKeyWidth = (width()/nk)/2; | 107 | defaultKeyWidth = (width()/nk)/2; |
108 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? | 108 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? |
109 | 109 | ||
110 | } | 110 | } |
111 | 111 | ||
112 | /* KeyboardPicks::initialize {{{1 */ | 112 | /* KeyboardPicks::initialize {{{1 */ |
113 | void KeyboardPicks::initialise() | 113 | void KeyboardPicks::initialise() |
114 | { | 114 | { |
115 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 115 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
116 | mode = 0; | 116 | mode = 0; |
117 | dc = new KeyboardConfig(this); | 117 | dc = new KeyboardConfig(this); |
118 | configs.append(dc); | 118 | configs.append(dc); |
119 | } | 119 | } |
120 | 120 | ||
121 | /* KeyboardPicks::sizeHint {{{1 */ | 121 | /* KeyboardPicks::sizeHint {{{1 */ |
122 | QSize KeyboardPicks::sizeHint() const | 122 | QSize KeyboardPicks::sizeHint() const |
123 | { | 123 | { |
124 | return QSize(240,fontMetrics().lineSpacing()); | 124 | return QSize(240,fontMetrics().lineSpacing()); |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | /* KeyboardConfig::generateText {{{1 */ | 128 | /* KeyboardConfig::generateText {{{1 */ |
129 | void KeyboardConfig::generateText(const QString &s) | 129 | void KeyboardConfig::generateText(const QString &s) |
130 | { | 130 | { |
131 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 131 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
132 | for (int i=0; i<(int)backspaces; i++) { | 132 | for (int i=0; i<(int)backspaces; i++) { |
133 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); | 133 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); |
134 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); | 134 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); |
135 | } | 135 | } |
136 | for (int i=0; i<(int)s.length(); i++) { | 136 | for (int i=0; i<(int)s.length(); i++) { |
137 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); | 137 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); |
138 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); | 138 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); |
139 | } | 139 | } |
140 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); | 140 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); |
141 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); | 141 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); |
142 | backspaces = 0; | 142 | backspaces = 0; |
143 | #endif | 143 | #endif |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | /* Keyboard::paintEvent {{{1 */ | 149 | /* Keyboard::paintEvent {{{1 */ |
150 | void Keyboard::paintEvent(QPaintEvent* e) | 150 | void Keyboard::paintEvent(QPaintEvent* e) |
151 | { | 151 | { |
152 | QPainter painter(this); | 152 | QPainter painter(this); |
153 | painter.setClipRect(e->rect()); | 153 | painter.setClipRect(e->rect()); |
154 | drawKeyboard( painter ); | 154 | drawKeyboard( painter ); |
155 | picks->dc->draw( &painter ); | 155 | picks->dc->draw( &painter ); |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | /* Keyboard::drawKeyboard {{{1 */ | 159 | /* Keyboard::drawKeyboard {{{1 */ |
160 | 160 | ||
161 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) | 161 | void 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 | p.drawText(x, y, | 186 | p.drawText(x, y, |
187 | defaultKeyWidth * keyWidth, keyHeight, | 187 | defaultKeyWidth * keyWidth, keyHeight, |
188 | AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); | 188 | AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); |
189 | else | 189 | else |
190 | // center the image in the middle of the key | 190 | // center the image in the middle of the key |
191 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, | 191 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, |
192 | y + (keyHeight - pix->height())/2 + 1, | 192 | y + (keyHeight - pix->height())/2 + 1, |
193 | *pix ); | 193 | *pix ); |
194 | 194 | ||
195 | // this fixes the problem that the very right end of the board's vertical line | 195 | // 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 | 196 | // gets painted over, because it's one pixel shorter than all other keys |
197 | p.setPen(keycolor_lines); | 197 | p.setPen(keycolor_lines); |
198 | p.drawLine(width() - 1, 0, width() - 1, height()); | 198 | p.drawLine(width() - 1, 0, width() - 1, height()); |
199 | 199 | ||
200 | } else { | 200 | } else { |
201 | 201 | ||
202 | 202 | ||
203 | p.fillRect(0, 0, width(), height(), keycolor); | 203 | p.fillRect(0, 0, width(), height(), keycolor); |
204 | 204 | ||
205 | for (row = 1; row <= 5; row++) { | 205 | for (row = 1; row <= 5; row++) { |
206 | 206 | ||
207 | int x = 0; | 207 | int x = 0; |
208 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 208 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
209 | 209 | ||
210 | p.setPen(keycolor_lines); | 210 | p.setPen(keycolor_lines); |
211 | p.drawLine(x, y, x + width(), y); | 211 | p.drawLine(x, y, x + width(), y); |
212 | 212 | ||
213 | for (int col = 0; col < keys->numKeys(row); col++) { | 213 | for (int col = 0; col < keys->numKeys(row); col++) { |
214 | 214 | ||
215 | QPixmap *pix = keys->pix(row, col); | 215 | QPixmap *pix = keys->pix(row, col); |
216 | int keyWidth = keys->width(row, col); | 216 | int keyWidth = keys->width(row, col); |
217 | 217 | ||
218 | 218 | ||
219 | int keyWidthPix = defaultKeyWidth * keyWidth; | 219 | int keyWidthPix = defaultKeyWidth * keyWidth; |
220 | 220 | ||
221 | if (keys->pressed(row, col)) | 221 | if (keys->pressed(row, col)) |
222 | p.fillRect(x+1, y+1, keyWidthPix - 1, | 222 | p.fillRect(x+1, y+1, keyWidthPix - 1, |
223 | keyHeight - 1, keycolor_pressed); | 223 | keyHeight - 1, keycolor_pressed); |
224 | 224 | ||
225 | ushort c = keys->uni(row, col); | 225 | ushort c = keys->uni(row, col); |
226 | 226 | ||
227 | if (!pix) { | 227 | if (!pix) { |
228 | p.setPen(textcolor); | 228 | p.setPen(textcolor); |
229 | p.drawText(x, y, | 229 | p.drawText(x, y, |
230 | keyWidthPix, keyHeight, | 230 | keyWidthPix, keyHeight, |
231 | AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); | 231 | AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); |
232 | } | 232 | } |
233 | else { | 233 | else { |
234 | // center the image in the middle of the key | 234 | // center the image in the middle of the key |
235 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, | 235 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, |
236 | y + (keyHeight - pix->height())/2 + 1, | 236 | y + (keyHeight - pix->height())/2 + 1, |
237 | QPixmap(*pix) ); | 237 | QPixmap(*pix) ); |
238 | } | 238 | } |
239 | 239 | ||
240 | p.setPen(keycolor_lines); | 240 | p.setPen(keycolor_lines); |
241 | p.drawLine(x, y, x, y + keyHeight); | 241 | p.drawLine(x, y, x, y + keyHeight); |
242 | 242 | ||
243 | x += keyWidthPix; | 243 | x += keyWidthPix; |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | } | 247 | } |
248 | p.drawLine(0, height() - 1, width(), height() - 1); | 248 | p.drawLine(0, height() - 1, width(), height() - 1); |
249 | p.drawLine(width() - 1, 0, width() - 1, height()); | 249 | p.drawLine(width() - 1, 0, width() - 1, height()); |
250 | } | 250 | } |
251 | 251 | ||
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
255 | /* Keyboard::mousePressEvent {{{1 */ | 255 | /* Keyboard::mousePressEvent {{{1 */ |
256 | void Keyboard::mousePressEvent(QMouseEvent *e) | 256 | void Keyboard::mousePressEvent(QMouseEvent *e) |
257 | { | 257 | { |
258 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; | 258 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; |
259 | if (row > 5) row = 5; | 259 | if (row > 5) row = 5; |
260 | 260 | ||
261 | // figure out the column | 261 | // figure out the column |
262 | int col = 0; | 262 | int col = 0; |
263 | for (int w = 0; e->x() >= w; col++) | 263 | for (int w = 0; e->x() >= w; col++) |
264 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys | 264 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys |
265 | w += keys->width(row,col) * defaultKeyWidth; | 265 | w += keys->width(row,col) * defaultKeyWidth; |
266 | else break; | 266 | else break; |
267 | 267 | ||
268 | if (col <= 0) return; | ||
269 | |||
268 | col --; // rewind one... | 270 | col --; // rewind one... |
269 | 271 | ||
270 | qkeycode = keys->qcode(row, col); | 272 | qkeycode = keys->qcode(row, col); |
271 | unicode = keys->uni(row, col); | 273 | unicode = keys->uni(row, col); |
272 | 274 | ||
273 | // might need to repaint if two or more of the same keys. | 275 | // might need to repaint if two or more of the same keys. |
274 | // should be faster if just paint one key even though multiple keys exist. | 276 | // should be faster if just paint one key even though multiple keys exist. |
275 | bool need_repaint = FALSE; | 277 | bool need_repaint = FALSE; |
276 | 278 | ||
277 | if (unicode == 0) { // either Qt char, or nothing | 279 | if (unicode == 0) { // either Qt char, or nothing |
278 | 280 | ||
279 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard | 281 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard |
280 | 282 | ||
281 | if ( configdlg ) { | 283 | if ( configdlg ) { |
282 | delete (ConfigDlg *) configdlg; | 284 | delete (ConfigDlg *) configdlg; |
283 | configdlg = 0; | 285 | configdlg = 0; |
284 | } | 286 | } |
285 | else { | 287 | else { |
286 | configdlg = new ConfigDlg (); | 288 | configdlg = new ConfigDlg (); |
287 | connect(configdlg, SIGNAL(setMapToDefault()), | 289 | connect(configdlg, SIGNAL(setMapToDefault()), |
288 | this, SLOT(setMapToDefault())); | 290 | this, SLOT(setMapToDefault())); |
289 | connect(configdlg, SIGNAL(setMapToFile(QString)), | 291 | connect(configdlg, SIGNAL(setMapToFile(QString)), |
290 | this, SLOT(setMapToFile(QString))); | 292 | this, SLOT(setMapToFile(QString))); |
291 | connect(configdlg, SIGNAL(pickboardToggled(bool)), | 293 | connect(configdlg, SIGNAL(pickboardToggled(bool)), |
292 | this, SLOT(togglePickboard(bool))); | 294 | this, SLOT(togglePickboard(bool))); |
293 | connect(configdlg, SIGNAL(repeatToggled(bool)), | 295 | connect(configdlg, SIGNAL(repeatToggled(bool)), |
294 | this, SLOT(toggleRepeat(bool))); | 296 | this, SLOT(toggleRepeat(bool))); |
295 | connect(configdlg, SIGNAL(reloadKeyboard()), | 297 | connect(configdlg, SIGNAL(reloadKeyboard()), |
296 | this, SLOT(reloadKeyboard())); | 298 | this, SLOT(reloadKeyboard())); |
297 | configdlg->showMaximized(); | 299 | configdlg->showMaximized(); |
298 | configdlg->show(); | 300 | configdlg->show(); |
299 | configdlg->raise(); | 301 | configdlg->raise(); |
300 | } | 302 | } |
301 | 303 | ||
302 | } else if (qkeycode == Qt::Key_Control) { | 304 | } else if (qkeycode == Qt::Key_Control) { |
303 | ctrl = keys->pressedPtr(row, col); | 305 | ctrl = keys->pressedPtr(row, col); |
304 | need_repaint = TRUE; | 306 | need_repaint = TRUE; |
305 | *ctrl = !keys->pressed(row, col); | 307 | *ctrl = !keys->pressed(row, col); |
306 | 308 | ||
307 | } else if (qkeycode == Qt::Key_Alt) { | 309 | } else if (qkeycode == Qt::Key_Alt) { |
308 | alt = keys->pressedPtr(row, col); | 310 | alt = keys->pressedPtr(row, col); |
309 | need_repaint = TRUE; | 311 | need_repaint = TRUE; |
310 | *alt = !keys->pressed(row, col); | 312 | *alt = !keys->pressed(row, col); |
311 | 313 | ||
312 | } else if (qkeycode == Qt::Key_Shift) { | 314 | } else if (qkeycode == Qt::Key_Shift) { |
313 | need_repaint = TRUE; | 315 | need_repaint = TRUE; |
314 | 316 | ||
315 | if (shift) { | 317 | if (shift) { |
316 | *shift = 0; | 318 | *shift = 0; |
317 | shift = 0; | 319 | shift = 0; |
318 | } | 320 | } |
319 | else { | 321 | else { |
320 | shift = keys->pressedPtr(row, col); | 322 | shift = keys->pressedPtr(row, col); |
321 | *shift = 1; | 323 | *shift = 1; |
322 | if (lock) { | 324 | if (lock) { |
323 | *lock = 0; | 325 | *lock = 0; |
324 | lock = 0; | 326 | lock = 0; |
325 | } | 327 | } |
326 | } | 328 | } |
327 | 329 | ||
328 | } else if (qkeycode == Qt::Key_CapsLock) { | 330 | } else if (qkeycode == Qt::Key_CapsLock) { |
329 | need_repaint = TRUE; | 331 | need_repaint = TRUE; |
330 | 332 | ||
331 | if (lock) { | 333 | if (lock) { |
332 | *lock = 0; | 334 | *lock = 0; |
333 | lock = 0; | 335 | lock = 0; |
334 | } | 336 | } |
335 | else { | 337 | else { |
336 | lock = keys->pressedPtr(row, col);; | 338 | lock = keys->pressedPtr(row, col);; |
337 | *lock = 1; | 339 | *lock = 1; |
338 | if (shift) { | 340 | if (shift) { |
339 | *shift = 0; | 341 | *shift = 0; |
340 | shift = 0; | 342 | shift = 0; |
341 | } | 343 | } |
342 | } | 344 | } |
343 | 345 | ||
344 | } | 346 | } |
345 | 347 | ||
346 | } | 348 | } |
347 | else { // normal char | 349 | else { // normal char |
348 | if ((shift || lock) && keys->shift(unicode)) { | 350 | if ((shift || lock) && keys->shift(unicode)) { |
349 | unicode = keys->shift(unicode); | 351 | unicode = keys->shift(unicode); |
350 | } | 352 | } |
351 | } | 353 | } |
352 | 354 | ||
353 | // korean parsing | 355 | // korean parsing |
354 | if (keys->lang == "ko") { | 356 | if (keys->lang == "ko") { |
355 | 357 | ||
356 | unicode = parseKoreanInput(unicode); | 358 | unicode = parseKoreanInput(unicode); |
357 | } | 359 | } |
358 | 360 | ||
359 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); | 361 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); |
360 | 362 | ||
361 | if ('A' <= unicode && unicode <= 'z' && modifiers) { | 363 | if ('A' <= unicode && unicode <= 'z' && modifiers) { |
362 | 364 | ||
363 | qkeycode = QChar(unicode).upper(); | 365 | qkeycode = QChar(unicode).upper(); |
364 | unicode = qkeycode - '@'; | 366 | unicode = qkeycode - '@'; |
365 | } | 367 | } |
366 | 368 | ||
367 | QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); | 369 | QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); |
368 | 370 | ||
369 | // pickboard stuff | 371 | // pickboard stuff |
370 | if (usePicks) { | 372 | if (usePicks) { |
371 | 373 | ||
372 | KeyboardConfig *dc = picks->dc; | 374 | KeyboardConfig *dc = picks->dc; |
373 | 375 | ||
374 | if (dc) { | 376 | if (dc) { |
375 | if (qkeycode == Qt::Key_Backspace) { | 377 | if (qkeycode == Qt::Key_Backspace) { |
376 | dc->input.remove(dc->input.last()); // remove last input | 378 | dc->input.remove(dc->input.last()); // remove last input |
377 | dc->decBackspaces(); | 379 | dc->decBackspaces(); |
378 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { | 380 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { |
379 | dc->input.clear(); | 381 | dc->input.clear(); |
380 | dc->resetBackspaces(); | 382 | dc->resetBackspaces(); |
381 | } else { | 383 | } else { |
382 | dc->add(QString(QChar(unicode))); | 384 | dc->add(QString(QChar(unicode))); |
383 | dc->incBackspaces(); | 385 | dc->incBackspaces(); |
384 | } | 386 | } |
385 | } | 387 | } |
386 | picks->repaint(); | 388 | picks->repaint(); |
387 | } | 389 | } |
388 | 390 | ||
389 | 391 | ||
390 | // painting | 392 | // painting |
391 | pressed = TRUE; | 393 | pressed = TRUE; |
392 | 394 | ||
393 | pressedKeyRow = row; | 395 | pressedKeyRow = row; |
394 | pressedKeyCol = col; | 396 | pressedKeyCol = col; |
395 | 397 | ||
396 | if (need_repaint) repaint(FALSE); | 398 | if (need_repaint) repaint(FALSE); |
397 | else { // just paint the one key pressed | 399 | else { // just paint the one key pressed |
398 | 400 | ||
399 | 401 | ||
400 | 402 | ||
401 | QPainter p(this); | 403 | QPainter p(this); |
402 | drawKeyboard(p, row, col); | 404 | drawKeyboard(p, row, col); |
403 | 405 | ||
404 | } | 406 | } |
405 | 407 | ||
406 | if (useRepeat) repeatTimer->start( 800 ); | 408 | if (useRepeat) repeatTimer->start( 800 ); |
407 | //pressTid = startTimer(80); | 409 | //pressTid = startTimer(80); |
408 | 410 | ||
409 | } | 411 | } |
410 | 412 | ||
411 | 413 | ||
412 | /* Keyboard::mouseReleaseEvent {{{1 */ | 414 | /* Keyboard::mouseReleaseEvent {{{1 */ |
413 | void Keyboard::mouseReleaseEvent(QMouseEvent*) | 415 | void Keyboard::mouseReleaseEvent(QMouseEvent*) |
414 | { | 416 | { |
415 | pressed = FALSE; | 417 | pressed = FALSE; |
416 | //if ( pressTid == 0 ) | 418 | //if ( pressTid == 0 ) |
417 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 419 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
418 | if ( unicode != -1 ) { | 420 | if ( unicode != -1 ) { |
419 | emit key( unicode, qkeycode, modifiers, false, false ); | 421 | emit key( unicode, qkeycode, modifiers, false, false ); |
420 | repeatTimer->stop(); | 422 | repeatTimer->stop(); |
421 | } | 423 | } |
422 | #endif | 424 | #endif |
423 | if (shift && unicode != 0) { | 425 | if (shift && unicode != 0) { |
424 | 426 | ||
425 | 427 | ||
426 | *shift = 0; // unpress shift key | 428 | *shift = 0; // unpress shift key |
427 | shift = 0; // reset the shift pointer | 429 | shift = 0; // reset the shift pointer |
428 | repaint(FALSE); | 430 | repaint(FALSE); |
429 | 431 | ||
430 | } | 432 | } |
431 | else | 433 | else |
432 | 434 | ||
433 | clearHighlight(); | 435 | clearHighlight(); |
434 | } | 436 | } |
435 | 437 | ||
436 | /* Keyboard::timerEvent {{{1 */ | 438 | /* Keyboard::timerEvent {{{1 */ |
437 | 439 | ||
438 | /* dont know what this does, but i think it is here so that if your screen | 440 | /* dont know what this does, but i think it is here so that if your screen |
439 | * sticks (like on an ipaq) then it will stop repeating if you click another | 441 | * sticks (like on an ipaq) then it will stop repeating if you click another |
440 | * key... but who knows what anything does in this thing anyway? | 442 | * key... but who knows what anything does in this thing anyway? |
441 | 443 | ||
442 | void Keyboard::timerEvent(QTimerEvent* e) | 444 | void Keyboard::timerEvent(QTimerEvent* e) |
443 | { | 445 | { |
444 | if ( e->timerId() == pressTid ) { | 446 | if ( e->timerId() == pressTid ) { |
445 | killTimer(pressTid); | 447 | killTimer(pressTid); |
446 | pressTid = 0; | 448 | pressTid = 0; |
447 | if ( !pressed ) | 449 | if ( !pressed ) |
448 | cout << "calling clearHighlight from timerEvent\n"; | 450 | cout << "calling clearHighlight from timerEvent\n"; |
449 | //clearHighlight(); | 451 | //clearHighlight(); |
450 | } | 452 | } |
451 | } | 453 | } |
452 | */ | 454 | */ |
453 | 455 | ||
454 | void Keyboard::repeat() | 456 | void Keyboard::repeat() |
455 | { | 457 | { |
456 | 458 | ||
457 | repeatTimer->start( 200 ); | 459 | repeatTimer->start( 200 ); |
458 | emit key( unicode, qkeycode, modifiers, true, true ); | 460 | emit key( unicode, qkeycode, modifiers, true, true ); |
459 | } | 461 | } |
460 | 462 | ||
461 | void Keyboard::clearHighlight() | 463 | void Keyboard::clearHighlight() |
462 | { | 464 | { |
463 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { | 465 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { |
464 | int tmpRow = pressedKeyRow; | 466 | int tmpRow = pressedKeyRow; |
465 | int tmpCol = pressedKeyCol; | 467 | int tmpCol = pressedKeyCol; |
466 | 468 | ||
467 | pressedKeyRow = -1; | 469 | pressedKeyRow = -1; |
468 | pressedKeyCol = -1; | 470 | pressedKeyCol = -1; |
469 | 471 | ||
470 | QPainter p(this); | 472 | QPainter p(this); |
471 | drawKeyboard(p, tmpRow, tmpCol); | 473 | drawKeyboard(p, tmpRow, tmpCol); |
472 | } | 474 | } |
473 | } | 475 | } |
474 | 476 | ||
475 | 477 | ||
476 | /* Keyboard::sizeHint {{{1 */ | 478 | /* Keyboard::sizeHint {{{1 */ |
477 | QSize Keyboard::sizeHint() const | 479 | QSize Keyboard::sizeHint() const |
478 | { | 480 | { |
479 | QFontMetrics fm=fontMetrics(); | 481 | QFontMetrics fm=fontMetrics(); |
480 | int keyHeight = fm.lineSpacing() + 2; | 482 | int keyHeight = fm.lineSpacing() + 2; |
481 | 483 | ||
482 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); | 484 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); |
483 | } | 485 | } |
484 | 486 | ||
485 | 487 | ||
486 | void Keyboard::resetState() | 488 | void Keyboard::resetState() |
487 | { | 489 | { |
488 | schar = mchar = echar = 0; | 490 | schar = mchar = echar = 0; |
489 | picks->resetState(); | 491 | picks->resetState(); |
490 | } | 492 | } |
491 | 493 | ||
492 | /* Keyboard::togglePickboard {{{1 */ | 494 | /* Keyboard::togglePickboard {{{1 */ |
493 | void Keyboard::togglePickboard(bool on_off) | 495 | void Keyboard::togglePickboard(bool on_off) |
494 | { | 496 | { |
495 | usePicks = on_off; | 497 | usePicks = on_off; |
496 | if (usePicks) { | 498 | if (usePicks) { |
497 | picks->show(); | 499 | picks->show(); |
498 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send | 500 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send |
499 | //adjustSize(); | 501 | //adjustSize(); |
500 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 502 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
501 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 503 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
502 | } else { | 504 | } else { |
503 | 505 | ||
504 | picks->hide(); | 506 | picks->hide(); |
505 | picks->resetState(); | 507 | picks->resetState(); |
506 | //move(x(), y() + picks->height()); | 508 | //move(x(), y() + picks->height()); |
507 | //adjustSize(); | 509 | //adjustSize(); |
508 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 510 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
509 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 511 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
510 | 512 | ||
511 | } | 513 | } |
512 | /* | 514 | /* |
513 | * this closes && opens the input method | 515 | * this closes && opens the input method |
514 | */ | 516 | */ |
515 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); | 517 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); |
516 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); | 518 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); |
517 | } | 519 | } |
518 | 520 | ||
519 | void Keyboard::toggleRepeat(bool on) { | 521 | void Keyboard::toggleRepeat(bool on) { |
520 | 522 | ||
521 | useRepeat = on; | 523 | useRepeat = on; |
522 | cout << "setting useRepeat to: " << useRepeat << "\n"; | 524 | cout << "setting useRepeat to: " << useRepeat << "\n"; |
523 | } | 525 | } |
524 | 526 | ||
525 | /* Keyboard::setMapTo ... {{{1 */ | 527 | /* Keyboard::setMapTo ... {{{1 */ |
526 | void Keyboard::setMapToDefault() { | 528 | void Keyboard::setMapToDefault() { |
527 | 529 | ||
528 | 530 | ||
529 | /* load current locale language map */ | 531 | /* load current locale language map */ |
530 | Config *config = new Config("locale"); | 532 | Config *config = new Config("locale"); |
531 | config->setGroup( "Language" ); | 533 | config->setGroup( "Language" ); |
532 | QString l = config->readEntry( "Language" , "en" ); | 534 | QString l = config->readEntry( "Language" , "en" ); |
533 | delete config; | 535 | delete config; |
534 | 536 | ||
535 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" | 537 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" |
536 | + l + ".keymap"; | 538 | + l + ".keymap"; |
537 | 539 | ||
538 | /* save change to multikey config file */ | 540 | /* save change to multikey config file */ |
539 | config = new Config("multikey"); | 541 | config = new Config("multikey"); |
540 | config->setGroup ("keymaps"); | 542 | config->setGroup ("keymaps"); |
541 | config->writeEntry ("current", key_map); // default closed | 543 | config->writeEntry ("current", key_map); // default closed |
542 | delete config; | 544 | delete config; |
543 | 545 | ||
544 | delete keys; | 546 | delete keys; |
545 | keys = new Keys(key_map); | 547 | keys = new Keys(key_map); |
546 | 548 | ||
547 | // have to repaint the keyboard | 549 | // have to repaint the keyboard |
548 | repaint(FALSE); | 550 | repaint(FALSE); |
549 | } | 551 | } |
550 | 552 | ||
551 | void Keyboard::setMapToFile(QString map) { | 553 | void Keyboard::setMapToFile(QString map) { |
552 | 554 | ||
553 | /* save change to multikey config file */ | 555 | /* save change to multikey config file */ |
554 | Config *config = new Config("multikey"); | 556 | Config *config = new Config("multikey"); |
555 | config->setGroup ("keymaps"); | 557 | config->setGroup ("keymaps"); |
556 | config->writeEntry ("current", map); // default closed | 558 | config->writeEntry ("current", map); // default closed |
557 | 559 | ||
558 | delete config; | 560 | delete config; |
559 | 561 | ||
560 | delete keys; | 562 | delete keys; |
561 | if (QFile(map).exists()) | 563 | if (QFile(map).exists()) |
562 | keys = new Keys(map); | 564 | keys = new Keys(map); |
563 | else | 565 | else |
564 | keys = new Keys(); | 566 | keys = new Keys(); |
565 | 567 | ||
566 | repaint(FALSE); | 568 | repaint(FALSE); |
567 | 569 | ||
568 | } | 570 | } |
569 | 571 | ||
570 | /* Keybaord::reloadKeyboard {{{1 */ | 572 | /* Keybaord::reloadKeyboard {{{1 */ |
571 | void Keyboard::reloadKeyboard() { | 573 | void Keyboard::reloadKeyboard() { |
572 | 574 | ||
573 | // reload colors and redraw | 575 | // reload colors and redraw |
574 | loadKeyboardColors(); | 576 | loadKeyboardColors(); |
575 | repaint(); | 577 | repaint(); |
576 | 578 | ||
577 | } | 579 | } |
578 | 580 | ||
579 | void Keyboard::loadKeyboardColors() { | 581 | void Keyboard::loadKeyboardColors() { |
580 | 582 | ||
581 | Config config ("multikey"); | 583 | Config config ("multikey"); |
582 | config.setGroup("colors"); | 584 | config.setGroup("colors"); |
583 | 585 | ||
584 | QStringList color; | 586 | QStringList color; |
585 | color = config.readListEntry("keycolor", QChar(',')); | 587 | color = config.readListEntry("keycolor", QChar(',')); |
586 | if (color.isEmpty()) { | 588 | if (color.isEmpty()) { |
587 | color = QStringList::split(",", "240,240,240"); | 589 | color = QStringList::split(",", "240,240,240"); |
588 | config.writeEntry("keycolor", color.join(",")); | 590 | config.writeEntry("keycolor", color.join(",")); |
589 | 591 | ||
590 | } | 592 | } |
591 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 593 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
592 | 594 | ||
593 | color = config.readListEntry("keycolor_pressed", QChar(',')); | 595 | color = config.readListEntry("keycolor_pressed", QChar(',')); |
594 | if (color.isEmpty()) { | 596 | if (color.isEmpty()) { |
595 | color = QStringList::split(",", "171,183,198"); | 597 | color = QStringList::split(",", "171,183,198"); |
596 | config.writeEntry("keycolor_pressed", color.join(",")); | 598 | config.writeEntry("keycolor_pressed", color.join(",")); |
597 | 599 | ||
598 | } | 600 | } |
599 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 601 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
600 | 602 | ||
601 | color = config.readListEntry("keycolor_lines", QChar(',')); | 603 | color = config.readListEntry("keycolor_lines", QChar(',')); |
602 | if (color.isEmpty()) { | 604 | if (color.isEmpty()) { |
603 | color = QStringList::split(",", "138,148,160"); | 605 | color = QStringList::split(",", "138,148,160"); |
604 | config.writeEntry("keycolor_lines", color.join(",")); | 606 | config.writeEntry("keycolor_lines", color.join(",")); |
605 | 607 | ||
606 | } | 608 | } |
607 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 609 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
608 | 610 | ||
609 | color = config.readListEntry("textcolor", QChar(',')); | 611 | color = config.readListEntry("textcolor", QChar(',')); |
610 | if (color.isEmpty()) { | 612 | if (color.isEmpty()) { |
611 | color = QStringList::split(",", "43,54,68"); | 613 | color = QStringList::split(",", "43,54,68"); |
612 | config.writeEntry("textcolor", color.join(",")); | 614 | config.writeEntry("textcolor", color.join(",")); |
613 | 615 | ||
614 | } | 616 | } |
615 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 617 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
616 | 618 | ||
617 | } | 619 | } |
618 | 620 | ||
619 | /* korean input functions {{{1 | 621 | /* korean input functions {{{1 |
620 | * | 622 | * |
621 | * TODO | 623 | * TODO |
622 | * one major problem with this implementation is that you can't move the | 624 | * one major problem with this implementation is that you can't move the |
623 | * cursor after inputing korean chars, otherwise it will eat up and replace | 625 | * cursor after inputing korean chars, otherwise it will eat up and replace |
624 | * the char before the cursor you move to. fix that | 626 | * the char before the cursor you move to. fix that |
625 | * | 627 | * |
626 | * make backspace delete one single char, not the whole thing if still | 628 | * make backspace delete one single char, not the whole thing if still |
627 | * editing. | 629 | * editing. |
628 | * | 630 | * |
629 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 631 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
630 | * | 632 | * |
631 | * how korean input works | 633 | * how korean input works |
632 | * | 634 | * |
633 | * all following chars means unicode char value and are in hex | 635 | * all following chars means unicode char value and are in hex |
634 | * | 636 | * |
635 | * ÃÊÀ½ = schar (start char) | 637 | * ÃÊÀ½ = schar (start char) |
636 | * ÁßÀ½ = mchar (middle char) | 638 | * ÁßÀ½ = mchar (middle char) |
637 | * ³¡À½ = echar (end char) | 639 | * ³¡À½ = echar (end char) |
638 | * | 640 | * |
639 | * there are 19 schars. unicode position is at 1100 - 1112 | 641 | * there are 19 schars. unicode position is at 1100 - 1112 |
640 | * there are 21 mchars. unicode position is at 1161 - 1175 | 642 | * there are 21 mchars. unicode position is at 1161 - 1175 |
641 | * there are 27 echars. unicode position is at 11a8 - 11c2 | 643 | * there are 27 echars. unicode position is at 11a8 - 11c2 |
642 | * | 644 | * |
643 | * the map with everything combined is at ac00 - d7a3 | 645 | * the map with everything combined is at ac00 - d7a3 |
644 | * | 646 | * |
645 | */ | 647 | */ |
646 | 648 | ||
647 | ushort Keyboard::parseKoreanInput (ushort c) { | 649 | ushort Keyboard::parseKoreanInput (ushort c) { |
648 | 650 | ||
649 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) | 651 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) |
650 | || | 652 | || |
651 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode | 653 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode |
652 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { | 654 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { |
653 | 655 | ||
654 | schar = 0, mchar = 0, echar = 0; | 656 | schar = 0, mchar = 0, echar = 0; |
655 | return c; | 657 | return c; |
656 | } | 658 | } |
657 | 659 | ||
658 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input | 660 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input |
659 | 661 | ||
660 | if (schar == 0 || (schar != 0 && mchar == 0)) { | 662 | if (schar == 0 || (schar != 0 && mchar == 0)) { |
661 | schar = c; mchar = 0; echar = 0; | 663 | schar = c; mchar = 0; echar = 0; |
662 | return c; | 664 | return c; |
663 | } | 665 | } |
664 | else if (mchar != 0) { | 666 | else if (mchar != 0) { |
665 | 667 | ||
666 | if (echar == 0) { | 668 | if (echar == 0) { |
667 | 669 | ||
668 | if (!(echar = constoe(c))) { | 670 | if (!(echar = constoe(c))) { |
669 | 671 | ||
670 | schar = c; mchar = 0; echar = 0; | 672 | schar = c; mchar = 0; echar = 0; |
671 | return c; | 673 | return c; |
672 | } | 674 | } |
673 | 675 | ||
674 | } | 676 | } |
675 | else { // must figure out what the echar is | 677 | else { // must figure out what the echar is |
676 | 678 | ||
677 | if (echar == 0x11a8) { // ¤¡ | 679 | if (echar == 0x11a8) { // ¤¡ |
678 | 680 | ||
679 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ | 681 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ |
680 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ | 682 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ |
681 | else { | 683 | else { |
682 | schar = c; mchar = 0; echar = 0; | 684 | schar = c; mchar = 0; echar = 0; |
683 | return c; | 685 | return c; |
684 | } | 686 | } |
685 | 687 | ||
686 | } else if (echar == 0x11ab) { // ¤¤ | 688 | } else if (echar == 0x11ab) { // ¤¤ |
687 | 689 | ||
688 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ | 690 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ |
689 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ | 691 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ |
690 | else { | 692 | else { |
691 | schar = c; mchar = 0; echar = 0; | 693 | schar = c; mchar = 0; echar = 0; |
692 | return c; | 694 | return c; |
693 | } | 695 | } |
694 | 696 | ||
695 | } else if (echar == 0x11af) { // ¤© | 697 | } else if (echar == 0x11af) { // ¤© |
696 | 698 | ||
697 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ | 699 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ |
698 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± | 700 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± |
699 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² | 701 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² |
700 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ | 702 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ |
701 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ | 703 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ |
702 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ | 704 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ |
703 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ | 705 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ |
704 | else { | 706 | else { |
705 | schar = c; mchar = 0; echar = 0; | 707 | schar = c; mchar = 0; echar = 0; |
706 | return c; | 708 | return c; |
707 | } | 709 | } |
708 | 710 | ||
709 | } else if (echar == 0x11b8) { // ¤² | 711 | } else if (echar == 0x11b8) { // ¤² |
710 | 712 | ||
711 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ | 713 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ |
712 | else { | 714 | else { |
713 | schar = c; mchar = 0; echar = 0; | 715 | schar = c; mchar = 0; echar = 0; |
714 | return c; | 716 | return c; |
715 | } | 717 | } |
716 | 718 | ||
717 | } else if (echar == 0x11ba) { // ¤µ | 719 | } else if (echar == 0x11ba) { // ¤µ |
718 | 720 | ||
719 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ | 721 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ |
720 | else { | 722 | else { |
721 | schar = c; mchar = 0; echar = 0; | 723 | schar = c; mchar = 0; echar = 0; |
722 | return c; | 724 | return c; |
723 | } | 725 | } |
724 | 726 | ||
725 | } else { // if any other char, cannot combine chars | 727 | } else { // if any other char, cannot combine chars |
726 | 728 | ||
727 | schar = c; mchar = 0; echar = 0; | 729 | schar = c; mchar = 0; echar = 0; |
728 | return c; | 730 | return c; |
729 | } | 731 | } |
730 | 732 | ||
731 | unicode = echar; | 733 | unicode = echar; |
732 | } | 734 | } |
733 | } | 735 | } |
734 | 736 | ||
735 | } | 737 | } |
736 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input | 738 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input |
737 | 739 | ||
738 | if (schar != 0 && mchar == 0) { mchar = c; } | 740 | if (schar != 0 && mchar == 0) { mchar = c; } |
739 | 741 | ||
740 | else if (schar != 0 && mchar != 0 && echar == 0) { | 742 | else if (schar != 0 && mchar != 0 && echar == 0) { |
741 | 743 | ||
742 | switch (mchar) { | 744 | switch (mchar) { |
743 | case 0x1169: | 745 | case 0x1169: |
744 | if (c == 0x1161) mchar = 0x116a; | 746 | if (c == 0x1161) mchar = 0x116a; |
745 | else if (c == 0x1162) mchar = 0x116b; | 747 | else if (c == 0x1162) mchar = 0x116b; |
746 | else if (c == 0x1175) mchar = 0x116c; | 748 | else if (c == 0x1175) mchar = 0x116c; |
747 | else { | 749 | else { |
748 | schar = 0; mchar = 0; echar = 0; | 750 | schar = 0; mchar = 0; echar = 0; |
749 | return c; | 751 | return c; |
750 | } | 752 | } |
751 | break; | 753 | break; |
752 | case 0x116e: | 754 | case 0x116e: |
753 | if (c == 0x1165) mchar = 0x116f; | 755 | if (c == 0x1165) mchar = 0x116f; |
754 | else if (c == 0x1166) mchar = 0x1170; | 756 | else if (c == 0x1166) mchar = 0x1170; |
755 | else if (c == 0x1175) mchar = 0x1171; | 757 | else if (c == 0x1175) mchar = 0x1171; |
756 | else { | 758 | else { |
757 | schar = 0; mchar = 0; echar = 0; | 759 | schar = 0; mchar = 0; echar = 0; |
758 | return c; | 760 | return c; |
759 | } | 761 | } |
760 | break; | 762 | break; |
761 | case 0x1173: | 763 | case 0x1173: |
762 | if (c == 0x1175) mchar = 0x1174; | 764 | if (c == 0x1175) mchar = 0x1174; |
763 | else { | 765 | else { |
764 | schar = 0; mchar = 0; echar = 0; | 766 | schar = 0; mchar = 0; echar = 0; |
765 | return c; | 767 | return c; |
766 | } | 768 | } |
767 | break; | 769 | break; |
768 | default: | 770 | default: |
769 | schar = 0; mchar = 0; echar = 0; | 771 | schar = 0; mchar = 0; echar = 0; |
770 | return c; | 772 | return c; |
771 | } | 773 | } |
772 | } | 774 | } |
773 | else if (schar != 0 && mchar != 0 && echar != 0) { | 775 | else if (schar != 0 && mchar != 0 && echar != 0) { |
774 | 776 | ||
775 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 777 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
776 | 778 | ||
777 | ushort prev = 0; | 779 | ushort prev = 0; |
778 | switch (echar) { | 780 | switch (echar) { |
779 | /* | 781 | /* |