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,962 +1,960 @@
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);
163 162
164 QPixmap *pix = keys.pix(row,col); 163 QPixmap *pix = keys.pix(row,col);
165 164
166 ushort c = keys.uni(row, col); 165 ushort c = keys.uni(row, col);
167 166
168 if (!pix) { 167 if (!pix) {
169 p.setPen(textcolor); 168 p.setPen(textcolor);
170 p.drawText(x, y, 169 p.drawText(x, y,
171 defaultKeyWidth * keyWidth, keyHeight, 170 defaultKeyWidth * keyWidth, keyHeight,
172 AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c); 171 AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c);
173 } 172 }
174 else 173 else
175 // center the image in the middle of the key 174 // center the image in the middle of the key
176 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, 175 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2,
177 y + (keyHeight - pix->height())/2 + 1, 176 y + (keyHeight - pix->height())/2 + 1,
178 *pix ); 177 *pix );
179 178
180 // this fixes the problem that the very right end of the board's vertical line 179 // this fixes the problem that the very right end of the board's vertical line
181 // gets painted over, because it's one pixel shorter than all other keys 180 // gets painted over, because it's one pixel shorter than all other keys
182 p.setPen(keycolor_lines); 181 p.setPen(keycolor_lines);
183 p.drawLine(width() - 1, 0, width() - 1, height()); 182 p.drawLine(width() - 1, 0, width() - 1, height());
184 183
185 } else { 184 } else {
186 185
187 186
188 p.fillRect(0, 0, width(), height(), keycolor); 187 p.fillRect(0, 0, width(), height(), keycolor);
189 188
190 for (row = 1; row <= 5; row++) { 189 for (row = 1; row <= 5; row++) {
191 190
192 int x = 0; 191 int x = 0;
193 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 192 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
194 193
195 p.setPen(keycolor_lines); 194 p.setPen(keycolor_lines);
196 p.drawLine(x, y, x + width(), y); 195 p.drawLine(x, y, x + width(), y);
197 196
198 for (int col = 0; col < keys.numKeys(row); col++) { 197 for (int col = 0; col < keys.numKeys(row); col++) {
199 198
200 QPixmap *pix = keys.pix(row, col); 199 QPixmap *pix = keys.pix(row, col);
201 int keyWidth = keys.width(row, col); 200 int keyWidth = keys.width(row, col);
202 201
203 202
204 int keyWidthPix = defaultKeyWidth * keyWidth; 203 int keyWidthPix = defaultKeyWidth * keyWidth;
205 204
206 if (keys.pressed(row, col)) 205 if (keys.pressed(row, col))
207 p.fillRect(x+1, y+1, keyWidthPix - 1, 206 p.fillRect(x+1, y+1, keyWidthPix - 1,
208 keyHeight - 1, keycolor_pressed); 207 keyHeight - 1, keycolor_pressed);
209 208
210 ushort c = keys.uni(row, col); 209 ushort c = keys.uni(row, col);
211 210
212 if (!pix) { 211 if (!pix) {
213 p.setPen(textcolor); 212 p.setPen(textcolor);
214 p.drawText(x, y, 213 p.drawText(x, y,
215 keyWidthPix, keyHeight, 214 keyWidthPix, keyHeight,
216 AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c); 215 AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c);
217 } 216 }
218 else { 217 else {
219 // center the image in the middle of the key 218 // center the image in the middle of the key
220 p.drawPixmap( x + (keyWidthPix - pix->width())/2, 219 p.drawPixmap( x + (keyWidthPix - pix->width())/2,
221 y + (keyHeight - pix->height())/2 + 1, 220 y + (keyHeight - pix->height())/2 + 1,
222 QPixmap(*pix) ); 221 QPixmap(*pix) );
223 } 222 }
224 223
225 p.setPen(keycolor_lines); 224 p.setPen(keycolor_lines);
226 p.drawLine(x, y, x, y + keyHeight); 225 p.drawLine(x, y, x, y + keyHeight);
227 226
228 x += keyWidthPix; 227 x += keyWidthPix;
229 } 228 }
230 229
231 230
232 } 231 }
233 p.drawLine(0, height() - 1, width(), height() - 1); 232 p.drawLine(0, height() - 1, width(), height() - 1);
234 p.drawLine(width() - 1, 0, width() - 1, height()); 233 p.drawLine(width() - 1, 0, width() - 1, height());
235 } 234 }
236 235
237} 236}
238 237
239 238
240/* Keyboard::mousePressEvent {{{1 */ 239/* Keyboard::mousePressEvent {{{1 */
241void Keyboard::mousePressEvent(QMouseEvent *e) 240void Keyboard::mousePressEvent(QMouseEvent *e)
242{ 241{
243 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; 242 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
244 if (row > 5) row = 5; 243 if (row > 5) row = 5;
245 244
246 // figure out the column 245 // figure out the column
247 int col = 0; 246 int col = 0;
248 for (int w = 0; e->x() >= w; col++) 247 for (int w = 0; e->x() >= w; col++)
249 if (col < keys.numKeys(row)) // it segfaults if it trys to read past numKeys 248 if (col < keys.numKeys(row)) // it segfaults if it trys to read past numKeys
250 w += keys.width(row,col) * defaultKeyWidth; 249 w += keys.width(row,col) * defaultKeyWidth;
251 else break; 250 else break;
252 251
253 col --; // rewind one... 252 col --; // rewind one...
254 253
255 qkeycode = keys.qcode(row, col); 254 qkeycode = keys.qcode(row, col);
256 unicode = keys.uni(row, col); 255 unicode = keys.uni(row, col);
257 256
258 // might need to repaint if two or more of the same keys. 257 // might need to repaint if two or more of the same keys.
259 // should be faster if just paint one key even though multiple keys exist. 258 // should be faster if just paint one key even though multiple keys exist.
260 bool need_repaint = FALSE; 259 bool need_repaint = FALSE;
261 260
262 if (unicode == 0) { // either Qt char, or nothing 261 if (unicode == 0) { // either Qt char, or nothing
263 262
264 if (qkeycode == Qt::Key_F1) { // toggle the pickboard 263 if (qkeycode == Qt::Key_F1) { // toggle the pickboard
265 264
266 usePicks = !usePicks; 265 usePicks = !usePicks;
267 if (usePicks) { 266 if (usePicks) {
268 picks->show(); 267 picks->show();
269 move(x(), y() - picks->height()); 268 move(x(), y() - picks->height());
270 adjustSize(); 269 adjustSize();
271 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 270 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
272 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 271 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
273 } else { 272 } else {
274 273
275 picks->hide(); 274 picks->hide();
276 picks->resetState(); 275 picks->resetState();
277 move(x(), y() + picks->height()); 276 move(x(), y() + picks->height());
278 adjustSize(); 277 adjustSize();
279 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 278 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
280 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 279 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
281 280
282 } 281 }
283 282
284 keys.setPressed(row, col, usePicks); 283 keys.setPressed(row, col, usePicks);
285 need_repaint = TRUE; 284 need_repaint = TRUE;
286 qkeycode = 0; // don't need to emit Key_F1 285 qkeycode = 0; // don't need to emit Key_F1
287 } else if (qkeycode == Qt::Key_Control) { 286 } else if (qkeycode == Qt::Key_Control) {
288 ctrl = keys.pressedPtr(row, col); 287 ctrl = keys.pressedPtr(row, col);
289 need_repaint = TRUE; 288 need_repaint = TRUE;
290 *ctrl = !keys.pressed(row, col); 289 *ctrl = !keys.pressed(row, col);
291 290
292 } else if (qkeycode == Qt::Key_Alt) { 291 } else if (qkeycode == Qt::Key_Alt) {
293 alt = keys.pressedPtr(row, col); 292 alt = keys.pressedPtr(row, col);
294 need_repaint = TRUE; 293 need_repaint = TRUE;
295 *alt = !keys.pressed(row, col); 294 *alt = !keys.pressed(row, col);
296 295
297 } else if (qkeycode == Qt::Key_Shift) { 296 } else if (qkeycode == Qt::Key_Shift) {
298 need_repaint = TRUE; 297 need_repaint = TRUE;
299 298
300 if (shift) { 299 if (shift) {
301 *shift = 0; 300 *shift = 0;
302 shift = 0; 301 shift = 0;
303 } 302 }
304 else { 303 else {
305 shift = keys.pressedPtr(row, col); 304 shift = keys.pressedPtr(row, col);
306 *shift = 1; 305 *shift = 1;
307 if (lock) { 306 if (lock) {
308 *lock = 0; 307 *lock = 0;
309 lock = 0; 308 lock = 0;
310 } 309 }
311 } 310 }
312 311
313 } else if (qkeycode == Qt::Key_CapsLock) { 312 } else if (qkeycode == Qt::Key_CapsLock) {
314 need_repaint = TRUE; 313 need_repaint = TRUE;
315 314
316 if (lock) { 315 if (lock) {
317 *lock = 0; 316 *lock = 0;
318 lock = 0; 317 lock = 0;
319 } 318 }
320 else { 319 else {
321 lock = keys.pressedPtr(row, col);; 320 lock = keys.pressedPtr(row, col);;
322 *lock = 1; 321 *lock = 1;
323 if (shift) { 322 if (shift) {
324 *shift = 0; 323 *shift = 0;
325 shift = 0; 324 shift = 0;
326 } 325 }
327 } 326 }
328 327
329 } 328 }
330 329
331 } 330 }
332 else { // normal char 331 else { // normal char
333 if ((shift || lock) && keys.shift(unicode)) { 332 if ((shift || lock) && keys.shift(unicode)) {
334 unicode = keys.shift(unicode); 333 unicode = keys.shift(unicode);
335 } 334 }
336 } 335 }
337 336
338 // korean parsing 337 // korean parsing
339 if (LANG == "ko") { 338 if (LANG == "ko") {
340 339
341 unicode = parseKoreanInput(unicode); 340 unicode = parseKoreanInput(unicode);
342 } 341 }
343 342
344 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); 343 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
345 344
346 emit key(unicode, qkeycode, modifiers, true, false); 345 emit key(unicode, qkeycode, modifiers, true, false);
347 346
348 // pickboard stuff 347 // pickboard stuff
349 if (usePicks) { 348 if (usePicks) {
350 349
351 KeyboardConfig *dc = picks->dc; 350 KeyboardConfig *dc = picks->dc;
352 351
353 if (dc) { 352 if (dc) {
354 if (qkeycode == Qt::Key_Backspace) { 353 if (qkeycode == Qt::Key_Backspace) {
355 dc->input.remove(dc->input.last()); // remove last input 354 dc->input.remove(dc->input.last()); // remove last input
356 dc->decBackspaces(); 355 dc->decBackspaces();
357 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { 356 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) {
358 dc->input.clear(); 357 dc->input.clear();
359 dc->resetBackspaces(); 358 dc->resetBackspaces();
360 } else { 359 } else {
361 dc->add(QString(QChar(unicode))); 360 dc->add(QString(QChar(unicode)));
362 dc->incBackspaces(); 361 dc->incBackspaces();
363 } 362 }
364 } 363 }
365 picks->repaint(); 364 picks->repaint();
366 } 365 }
367 366
368 367
369 // painting 368 // painting
370 pressed = TRUE; 369 pressed = TRUE;
371 370
372 pressedKeyRow = row; 371 pressedKeyRow = row;
373 pressedKeyCol = col; 372 pressedKeyCol = col;
374 373
375 if (need_repaint) repaint(FALSE); 374 if (need_repaint) repaint(FALSE);
376 else { // just paint the one key pressed 375 else { // just paint the one key pressed
377 376
378 377
379 378
380 QPainter p(this); 379 QPainter p(this);
381 drawKeyboard(p, row, col); 380 drawKeyboard(p, row, col);
382 381
383 } 382 }
384 383
385 pressTid = startTimer(80); 384 pressTid = startTimer(80);
386 385
387} 386}
388 387
389 388
390/* Keyboard::mouseReleaseEvent {{{1 */ 389/* Keyboard::mouseReleaseEvent {{{1 */
391void Keyboard::mouseReleaseEvent(QMouseEvent*) 390void Keyboard::mouseReleaseEvent(QMouseEvent*)
392{ 391{
393 pressed = FALSE; 392 pressed = FALSE;
394 if ( pressTid == 0 ) 393 if ( pressTid == 0 )
395#if defined(Q_WS_QWS) || defined(_WS_QWS_) 394#if defined(Q_WS_QWS) || defined(_WS_QWS_)
396 if ( unicode != -1 ) { 395 if ( unicode != -1 ) {
397 emit key( unicode, qkeycode, modifiers, false, false ); 396 emit key( unicode, qkeycode, modifiers, false, false );
398 repeatTimer->stop(); 397 repeatTimer->stop();
399 } 398 }
400#endif 399#endif
401 if (shift && unicode != 0) { 400 if (shift && unicode != 0) {
402 401
403 402
404 *shift = 0; // unpress shift key 403 *shift = 0; // unpress shift key
405 shift = 0; // reset the shift pointer 404 shift = 0; // reset the shift pointer
406 repaint(FALSE); 405 repaint(FALSE);
407 406
408 } 407 }
409 else 408 else
410 409
411 clearHighlight(); 410 clearHighlight();
412} 411}
413 412
414/* Keyboard::timerEvent {{{1 */ 413/* Keyboard::timerEvent {{{1 */
415/* 414/*
416void Keyboard::timerEvent(QTimerEvent* e) 415void Keyboard::timerEvent(QTimerEvent* e)
417{ 416{
418 if ( e->timerId() == pressTid ) { 417 if ( e->timerId() == pressTid ) {
419 killTimer(pressTid); 418 killTimer(pressTid);
420 pressTid = 0; 419 pressTid = 0;
421 if ( !pressed ) 420 if ( !pressed )
422 cout << "calling clearHighlight from timerEvent\n"; 421 cout << "calling clearHighlight from timerEvent\n";
423 clearHighlight(); 422 clearHighlight();
424 } 423 }
425} 424}
426*/ 425*/
427 426
428void Keyboard::repeat() 427void Keyboard::repeat()
429{ 428{
430 429
431 repeatTimer->start( 200 ); 430 repeatTimer->start( 200 );
432 emit key( unicode, 0, modifiers, true, true ); 431 emit key( unicode, 0, modifiers, true, true );
433} 432}
434 433
435void Keyboard::clearHighlight() 434void Keyboard::clearHighlight()
436{ 435{
437 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { 436 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) {
438 int tmpRow = pressedKeyRow; 437 int tmpRow = pressedKeyRow;
439 int tmpCol = pressedKeyCol; 438 int tmpCol = pressedKeyCol;
440 439
441 pressedKeyRow = -1; 440 pressedKeyRow = -1;
442 pressedKeyCol = -1; 441 pressedKeyCol = -1;
443 442
444 QPainter p(this); 443 QPainter p(this);
445 drawKeyboard(p, tmpRow, tmpCol); 444 drawKeyboard(p, tmpRow, tmpCol);
446 } 445 }
447} 446}
448 447
449 448
450/* Keyboard::sizeHint {{{1 */ 449/* Keyboard::sizeHint {{{1 */
451QSize Keyboard::sizeHint() const 450QSize Keyboard::sizeHint() const
452{ 451{
453 QFontMetrics fm=fontMetrics(); 452 QFontMetrics fm=fontMetrics();
454 int keyHeight = fm.lineSpacing(); 453 int keyHeight = fm.lineSpacing();
455 454
456 return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); 455 return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1);
457} 456}
458 457
459 458
460void Keyboard::resetState() 459void Keyboard::resetState()
461{ 460{
462 schar = mchar = echar = 0; 461 schar = mchar = echar = 0;
463 picks->resetState(); 462 picks->resetState();
464} 463}
465 464
466/* korean input functions {{{1 465/* korean input functions {{{1
467 * 466 *
468 * TODO 467 * TODO
469 * one major problem with this implementation is that you can't move the 468 * one major problem with this implementation is that you can't move the
470 * cursor after inputing korean chars, otherwise it will eat up and replace 469 * cursor after inputing korean chars, otherwise it will eat up and replace
471 * the char before the cursor you move to. fix that 470 * the char before the cursor you move to. fix that
472 * 471 *
473 * make backspace delete one single char, not the whole thing if still 472 * make backspace delete one single char, not the whole thing if still
474 * editing. 473 * editing.
475 * 474 *
476 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 475 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
477 * 476 *
478 * how korean input works 477 * how korean input works
479 * 478 *
480 * all following chars means unicode char value and are in hex 479 * all following chars means unicode char value and are in hex
481 * 480 *
482 * ÃÊÀ½ = schar (start char) 481 * ÃÊÀ½ = schar (start char)
483 * ÁßÀ½ = mchar (middle char) 482 * ÁßÀ½ = mchar (middle char)
484 * ³¡À½ = echar (end char) 483 * ³¡À½ = echar (end char)
485 * 484 *
486 * there are 19 schars. unicode position is at 1100 - 1112 485 * there are 19 schars. unicode position is at 1100 - 1112
487 * there are 21 mchars. unicode position is at 1161 - 1175 486 * there are 21 mchars. unicode position is at 1161 - 1175
488 * there are 27 echars. unicode position is at 11a8 - 11c2 487 * there are 27 echars. unicode position is at 11a8 - 11c2
489 * 488 *
490 * the map with everything combined is at ac00 - d7a3 489 * the map with everything combined is at ac00 - d7a3
491 * 490 *
492 */ 491 */
493 492
494ushort Keyboard::parseKoreanInput (ushort c) { 493ushort Keyboard::parseKoreanInput (ushort c) {
495 494
496 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) 495 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
497 || 496 ||
498 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode 497 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
499 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { 498 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
500 499
501 schar = 0, mchar = 0, echar = 0; 500 schar = 0, mchar = 0, echar = 0;
502 return c; 501 return c;
503 } 502 }
504 503
505 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input 504 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input
506 505
507 if (schar == 0 || (schar != 0 && mchar == 0)) { 506 if (schar == 0 || (schar != 0 && mchar == 0)) {
508 schar = c; mchar = 0; echar = 0; 507 schar = c; mchar = 0; echar = 0;
509 return c; 508 return c;
510 } 509 }
511 else if (mchar != 0) { 510 else if (mchar != 0) {
512 511
513 if (echar == 0) { 512 if (echar == 0) {
514 513
515 if (!(echar = constoe(c))) { 514 if (!(echar = constoe(c))) {
516 515
517 schar = c; mchar = 0; echar = 0; 516 schar = c; mchar = 0; echar = 0;
518 return c; 517 return c;
519 } 518 }
520 519
521 } 520 }
522 else { // must figure out what the echar is 521 else { // must figure out what the echar is
523 522
524 if (echar == 0x11a8) { // ¤¡ 523 if (echar == 0x11a8) { // ¤¡
525 524
526 if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ 525 if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡
527 else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ 526 else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ
528 else { 527 else {
529 schar = c; mchar = 0; echar = 0; 528 schar = c; mchar = 0; echar = 0;
530 return c; 529 return c;
531 } 530 }
532 531
533 } else if (echar == 0x11ab) { // ¤¤ 532 } else if (echar == 0x11ab) { // ¤¤
534 533
535 if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ 534 if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸
536 else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ 535 else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾
537 else { 536 else {
538 schar = c; mchar = 0; echar = 0; 537 schar = c; mchar = 0; echar = 0;
539 return c; 538 return c;
540 } 539 }
541 540
542 } else if (echar == 0x11af) { // ¤© 541 } else if (echar == 0x11af) { // ¤©
543 542
544 if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ 543 if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡
545 else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± 544 else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤±
546 else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² 545 else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤²
547 else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ 546 else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ
548 else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ 547 else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼
549 else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ 548 else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½
550 else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ 549 else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾
551 else { 550 else {
552 schar = c; mchar = 0; echar = 0; 551 schar = c; mchar = 0; echar = 0;
553 return c; 552 return c;
554 } 553 }
555 554
556 } else if (echar == 0x11b8) { // ¤² 555 } else if (echar == 0x11b8) { // ¤²
557 556
558 if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ 557 if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ
559 else { 558 else {
560 schar = c; mchar = 0; echar = 0; 559 schar = c; mchar = 0; echar = 0;
561 return c; 560 return c;
562 } 561 }
563 562
564 } else if (echar == 0x11ba) { // ¤µ 563 } else if (echar == 0x11ba) { // ¤µ
565 564
566 if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ 565 if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ
567 else { 566 else {
568 schar = c; mchar = 0; echar = 0; 567 schar = c; mchar = 0; echar = 0;
569 return c; 568 return c;
570 } 569 }
571 570
572 } else { // if any other char, cannot combine chars 571 } else { // if any other char, cannot combine chars
573 572
574 schar = c; mchar = 0; echar = 0; 573 schar = c; mchar = 0; echar = 0;
575 return c; 574 return c;
576 } 575 }
577 576
578 unicode = echar; 577 unicode = echar;
579 } 578 }
580 } 579 }
581 580
582 } 581 }
583 else if (0x1161 <= c && c <= 0x1175) { // mchar was input 582 else if (0x1161 <= c && c <= 0x1175) { // mchar was input
584 583
585 if (schar != 0 && mchar == 0) { mchar = c; } 584 if (schar != 0 && mchar == 0) { mchar = c; }
586 585
587 else if (schar != 0 && mchar != 0 && echar == 0) { 586 else if (schar != 0 && mchar != 0 && echar == 0) {
588 587
589 switch (mchar) { 588 switch (mchar) {
590 case 0x1169: 589 case 0x1169:
591 if (c == 0x1161) mchar = 0x116a; 590 if (c == 0x1161) mchar = 0x116a;
592 else if (c == 0x1162) mchar = 0x116b; 591 else if (c == 0x1162) mchar = 0x116b;
593 else if (c == 0x1175) mchar = 0x116c; 592 else if (c == 0x1175) mchar = 0x116c;
594 else { 593 else {
595 schar = 0; mchar = 0; echar = 0; 594 schar = 0; mchar = 0; echar = 0;
596 return c; 595 return c;
597 } 596 }
598 break; 597 break;
599 case 0x116e: 598 case 0x116e:
600 if (c == 0x1165) mchar = 0x116f; 599 if (c == 0x1165) mchar = 0x116f;
601 else if (c == 0x1166) mchar = 0x1170; 600 else if (c == 0x1166) mchar = 0x1170;
602 else if (c == 0x1175) mchar = 0x1171; 601 else if (c == 0x1175) mchar = 0x1171;
603 else { 602 else {
604 schar = 0; mchar = 0; echar = 0; 603 schar = 0; mchar = 0; echar = 0;
605 return c; 604 return c;
606 } 605 }
607 break; 606 break;
608 case 0x1173: 607 case 0x1173:
609 if (c == 0x1175) mchar = 0x1174; 608 if (c == 0x1175) mchar = 0x1174;
610 else { 609 else {
611 schar = 0; mchar = 0; echar = 0; 610 schar = 0; mchar = 0; echar = 0;
612 return c; 611 return c;
613 } 612 }
614 break; 613 break;
615 default: 614 default:
616 schar = 0; mchar = 0; echar = 0; 615 schar = 0; mchar = 0; echar = 0;
617 return c; 616 return c;
618 } 617 }
619 } 618 }
620 else if (schar != 0 && mchar != 0 && echar != 0) { 619 else if (schar != 0 && mchar != 0 && echar != 0) {
621 620
622 emit key( 8, Qt::Key_Backspace, 0, true, false ); 621 emit key( 8, Qt::Key_Backspace, 0, true, false );
623 622
624 ushort prev = 0; 623 ushort prev = 0;
625 switch (echar) { 624 switch (echar) {
626 /* 625 /*
627 case 0x11a9: 626 case 0x11a9:
628 prev = combineKoreanChars(schar, mchar, 0x11a8); 627 prev = combineKoreanChars(schar, mchar, 0x11a8);
629 schar = 0x1100; 628 schar = 0x1100;
630 break; 629 break;
631 */ 630 */
632 case 0x11aa: 631 case 0x11aa:
633 prev = combineKoreanChars(schar, mchar, 0x11a8); 632 prev = combineKoreanChars(schar, mchar, 0x11a8);
634 schar = 0x1109; 633 schar = 0x1109;
635 break; 634 break;
636 case 0x11ac: 635 case 0x11ac:
637 prev = combineKoreanChars(schar, mchar, 0x11ab); 636 prev = combineKoreanChars(schar, mchar, 0x11ab);
638 schar = 0x110c; 637 schar = 0x110c;
639 break; 638 break;
640 case 0x11ad: 639 case 0x11ad:
641 prev = combineKoreanChars(schar, mchar, 0x11ab); 640 prev = combineKoreanChars(schar, mchar, 0x11ab);
642 schar = 0x1112; 641 schar = 0x1112;
643 break; 642 break;
644 case 0x11b0: 643 case 0x11b0:
645 prev = combineKoreanChars(schar, mchar, 0x11af); 644 prev = combineKoreanChars(schar, mchar, 0x11af);
646 schar = 0x1100; 645 schar = 0x1100;
647 break; 646 break;
648 case 0x11b1: 647 case 0x11b1:
649 prev = combineKoreanChars(schar, mchar, 0x11af); 648 prev = combineKoreanChars(schar, mchar, 0x11af);
650 schar = 0x1106; 649 schar = 0x1106;
651 break; 650 break;
652 case 0x11b2: 651 case 0x11b2:
653 prev = combineKoreanChars(schar, mchar, 0x11af); 652 prev = combineKoreanChars(schar, mchar, 0x11af);
654 schar = 0x1107; 653 schar = 0x1107;
655 break; 654 break;
656 case 0x11b3: 655 case 0x11b3:
657 prev = combineKoreanChars(schar, mchar, 0x11af); 656 prev = combineKoreanChars(schar, mchar, 0x11af);
658 schar = 0x1109; 657 schar = 0x1109;
659 break; 658 break;
660 case 0x11b4: 659 case 0x11b4:
661 prev = combineKoreanChars(schar, mchar, 0x11af); 660 prev = combineKoreanChars(schar, mchar, 0x11af);
662 schar = 0x1110; 661 schar = 0x1110;
663 break; 662 break;
664 case 0x11b9: 663 case 0x11b9:
665 prev = combineKoreanChars(schar, mchar, 0x11b8); 664 prev = combineKoreanChars(schar, mchar, 0x11b8);
666 schar = 0x1109; 665 schar = 0x1109;
667 break; 666 break;
668 /* 667 /*
669 case 0x11bb: 668 case 0x11bb:
670 prev = combineKoreanChars(schar, mchar, 0x11ba); 669 prev = combineKoreanChars(schar, mchar, 0x11ba);
671 schar = 0x1109; 670 schar = 0x1109;
672 break; 671 break;
673 */ 672 */
674 default: 673 default:
675 674
676 if (constoe(echar)) { 675 if (constoe(echar)) {
677 676
678 prev = combineKoreanChars(schar, mchar, 0); 677 prev = combineKoreanChars(schar, mchar, 0);
679 schar = constoe(echar); 678 schar = constoe(echar);
680 } 679 }
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();
875 } 873 }
876 874
877} 875}
878 876
879// Keys::setKey {{{2 877// Keys::setKey {{{2
880void Keys::setKey(const int row, const int qcode, const ushort unicode, 878void Keys::setKey(const int row, const int qcode, const ushort unicode,
881 const int width, QPixmap *pix) { 879 const int width, QPixmap *pix) {
882 880
883 Key * key; 881 Key * key;
884 key = new Key; 882 key = new Key;
885 key->qcode = qcode; 883 key->qcode = qcode;
886 key->unicode = unicode; 884 key->unicode = unicode;
887 key->width = width; 885 key->width = width;
888 886
889 // share key->pressed between same keys 887 // share key->pressed between same keys
890 bool found = 0; 888 bool found = 0;
891 for (int i = 1; i <= 5; i++) { 889 for (int i = 1; i <= 5; i++) {
892 for (unsigned int j = 0; j < keys[i].count(); j++) 890 for (unsigned int j = 0; j < keys[i].count(); j++)
893 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { 891 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) {
894 892
895 key->pressed = keys[i].at(j)->pressed; 893 key->pressed = keys[i].at(j)->pressed;
896 found = 1; 894 found = 1;
897 } 895 }
898 896
899 } 897 }
900 if (!found) { 898 if (!found) {
901 899
902 key->pressed = new bool; 900 key->pressed = new bool;
903 *(key->pressed) = 0; 901 *(key->pressed) = 0;
904 } 902 }
905 903
906 key->pix = pix; 904 key->pix = pix;
907 905
908 906
909 keys[row].append(key); 907 keys[row].append(key);
910} 908}
911// Keys:: other functions {{{2 909// Keys:: other functions {{{2
912int Keys::width(const int row, const int col) { 910int Keys::width(const int row, const int col) {
913 911
914 return keys[row].at(col)->width; 912 return keys[row].at(col)->width;
915 913
916} 914}
917ushort Keys::uni(const int row, const int col) { 915ushort Keys::uni(const int row, const int col) {
918 916
919 return keys[row].at(col)->unicode; 917 return keys[row].at(col)->unicode;
920 918
921} 919}
922 920
923int Keys::qcode(const int row, const int col) { 921int Keys::qcode(const int row, const int col) {
924 922
925 return keys[row].at(col)->qcode; 923 return keys[row].at(col)->qcode;
926} 924}
927 925
928QPixmap *Keys::pix(const int row, const int col) { 926QPixmap *Keys::pix(const int row, const int col) {
929 927
930 return keys[row].at(col)->pix; 928 return keys[row].at(col)->pix;
931 929
932} 930}
933bool Keys::pressed(const int row, const int col) { 931bool Keys::pressed(const int row, const int col) {
934 932
935 return *(keys[row].at(col)->pressed); 933 return *(keys[row].at(col)->pressed);
936} 934}
937 935
938int Keys::numKeys(const int row) { 936int Keys::numKeys(const int row) {
939 937
940 return keys[row].count(); 938 return keys[row].count();
941} 939}
942 940
943void Keys::setPressed(const int row, const int col, const bool pressed) { 941void Keys::setPressed(const int row, const int col, const bool pressed) {
944 942
945 *(keys[row].at(col)->pressed) = pressed; 943 *(keys[row].at(col)->pressed) = pressed;
946} 944}
947 945
948ushort Keys::shift(const ushort uni) { 946ushort Keys::shift(const ushort uni) {
949 947
950 if (shiftMap[uni]) { 948 if (shiftMap[uni]) {
951 949
952 return shiftMap[uni]; 950 return shiftMap[uni];
953 } 951 }
954 else 952 else
955 return 0; 953 return 0;
956 954
957} 955}
958 956
959bool *Keys::pressedPtr(const int row, const int col) { 957bool *Keys::pressedPtr(const int row, const int col) {
960 958
961 return keys[row].at(col)->pressed; 959 return keys[row].at(col)->pressed;
962} 960}