summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index b793391..2a80f1e 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -1,1065 +1,1065 @@
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 <iostream.h> 36#include <iostream.h>
37 37
38#include <sys/utsname.h> 38#include <sys/utsname.h>
39 39
40 40
41#define USE_SMALL_BACKSPACE 41#define USE_SMALL_BACKSPACE
42 42
43/* Keyboard::Keyboard {{{1 */ 43/* Keyboard::Keyboard {{{1 */
44Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : 44Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
45 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), 45 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0),
46 alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1), 46 alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1),
47 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), 47 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0),
48 configdlg(0) 48 configdlg(0)
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 ("pickboard"); 58 config->setGroup ("pickboard");
59 usePicks = config->readBoolEntry ("open", "0"); // default closed 59 usePicks = config->readBoolEntry ("open", "0"); // default closed
60 delete config; 60 delete config;
61 61
62 setFont( QFont( familyStr, 8 ) ); 62 setFont( QFont( familyStr, 10 ) );
63 63
64 picks = new KeyboardPicks( this ); 64 picks = new KeyboardPicks( this );
65 picks->setFont( QFont( familyStr, 8 ) ); 65 picks->setFont( QFont( familyStr, 10 ) );
66 picks->initialise(); 66 picks->initialise();
67 if (usePicks) { 67 if (usePicks) {
68 68
69 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 69 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
70 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 70 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
71 71
72 } else picks->hide(); 72 } else picks->hide();
73 73
74 keys = new Keys(); 74 keys = new Keys();
75 75
76 repeatTimer = new QTimer( this ); 76 repeatTimer = new QTimer( this );
77 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 77 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
78 78
79} 79}
80 80
81/* Keyboard::resizeEvent {{{1 */ 81/* Keyboard::resizeEvent {{{1 */
82void Keyboard::resizeEvent(QResizeEvent*) 82void Keyboard::resizeEvent(QResizeEvent*)
83{ 83{
84 int ph = picks->sizeHint().height(); 84 int ph = picks->sizeHint().height();
85 picks->setGeometry( 0, 0, width(), ph ); 85 picks->setGeometry( 0, 0, width(), ph );
86 keyHeight = (height()-(usePicks ? ph : 0))/5; 86 keyHeight = (height()-(usePicks ? ph : 0))/5;
87 87
88 int nk; // number of keys? 88 int nk; // number of keys?
89 if ( useLargeKeys ) { 89 if ( useLargeKeys ) {
90 nk = 15; 90 nk = 15;
91 } else { 91 } else {
92 nk = 19; 92 nk = 19;
93 } 93 }
94 defaultKeyWidth = (width()/nk)/2; 94 defaultKeyWidth = (width()/nk)/2;
95 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? 95 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
96 96
97} 97}
98 98
99/* KeyboardPicks::initialize {{{1 */ 99/* KeyboardPicks::initialize {{{1 */
100void KeyboardPicks::initialise() 100void KeyboardPicks::initialise()
101{ 101{
102 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 102 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
103 mode = 0; 103 mode = 0;
104 dc = new KeyboardConfig(this); 104 dc = new KeyboardConfig(this);
105 configs.append(dc); 105 configs.append(dc);
106} 106}
107 107
108/* KeyboardPicks::sizeHint {{{1 */ 108/* KeyboardPicks::sizeHint {{{1 */
109QSize KeyboardPicks::sizeHint() const 109QSize KeyboardPicks::sizeHint() const
110{ 110{
111 return QSize(240,fontMetrics().lineSpacing()); 111 return QSize(240,fontMetrics().lineSpacing());
112} 112}
113 113
114 114
115/* KeyboardConfig::generateText {{{1 */ 115/* KeyboardConfig::generateText {{{1 */
116void KeyboardConfig::generateText(const QString &s) 116void KeyboardConfig::generateText(const QString &s)
117{ 117{
118#if defined(Q_WS_QWS) || defined(_WS_QWS_) 118#if defined(Q_WS_QWS) || defined(_WS_QWS_)
119 for (int i=0; i<(int)backspaces; i++) { 119 for (int i=0; i<(int)backspaces; i++) {
120 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); 120 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );
121 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); 121 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );
122 } 122 }
123 for (int i=0; i<(int)s.length(); i++) { 123 for (int i=0; i<(int)s.length(); i++) {
124 parent->emitKey( s[i].unicode(), 0, 0, true, false ); 124 parent->emitKey( s[i].unicode(), 0, 0, true, false );
125 parent->emitKey( s[i].unicode(), 0, 0, false, false ); 125 parent->emitKey( s[i].unicode(), 0, 0, false, false );
126 } 126 }
127 parent->emitKey( 0, Qt::Key_Space, 0, true, false ); 127 parent->emitKey( 0, Qt::Key_Space, 0, true, false );
128 parent->emitKey( 0, Qt::Key_Space, 0, false, false ); 128 parent->emitKey( 0, Qt::Key_Space, 0, false, false );
129 backspaces = 0; 129 backspaces = 0;
130#endif 130#endif
131} 131}
132 132
133 133
134 134
135 135
136/* Keyboard::paintEvent {{{1 */ 136/* Keyboard::paintEvent {{{1 */
137void Keyboard::paintEvent(QPaintEvent* e) 137void Keyboard::paintEvent(QPaintEvent* e)
138{ 138{
139 QPainter painter(this); 139 QPainter painter(this);
140 painter.setClipRect(e->rect()); 140 painter.setClipRect(e->rect());
141 drawKeyboard( painter ); 141 drawKeyboard( painter );
142 picks->dc->draw( &painter ); 142 picks->dc->draw( &painter );
143} 143}
144 144
145 145
146/* Keyboard::drawKeyboard {{{1 */ 146/* Keyboard::drawKeyboard {{{1 */
147 147
148void Keyboard::drawKeyboard(QPainter &p, int row, int col) 148void Keyboard::drawKeyboard(QPainter &p, int row, int col)
149{ 149{
150 QColor keycolor = 150 QColor keycolor =
151 QColor(240,240,240); 151 QColor(240,240,240);
152 QColor keycolor_pressed = QColor(171,183,198); 152 QColor keycolor_pressed = QColor(171,183,198);
153 QColor keycolor_lines = QColor(138,148,160); 153 QColor keycolor_lines = QColor(138,148,160);
154 QColor textcolor = QColor(43,54,68); 154 QColor textcolor = QColor(43,54,68);
155 155
156 156
157 if (row != -1 && col != -1) { //just redraw one key 157 if (row != -1 && col != -1) { //just redraw one key
158 158
159 int x = 0; 159 int x = 0;
160 for (int i = 0; i < col; i++) { 160 for (int i = 0; i < col; i++) {
161 161
162 x += keys->width(row, i) * defaultKeyWidth; 162 x += keys->width(row, i) * defaultKeyWidth;
163 } 163 }
164 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 164 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
165 165
166 int keyWidth = keys->width(row, col); 166 int keyWidth = keys->width(row, col);
167 167
168 p.fillRect(x + 1, y + 1, 168 p.fillRect(x + 1, y + 1,
169 keyWidth * defaultKeyWidth - 1, keyHeight - 1, 169 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
170 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); 170 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor);
171 171
172 QPixmap *pix = keys->pix(row,col); 172 QPixmap *pix = keys->pix(row,col);
173 173
174 ushort c = keys->uni(row, col); 174 ushort c = keys->uni(row, col);
175 175
176 if (!pix) { 176 if (!pix) {
177 p.setPen(textcolor); 177 p.setPen(textcolor);
178 p.drawText(x, y, 178 p.drawText(x, y,
179 defaultKeyWidth * keyWidth, keyHeight, 179 defaultKeyWidth * keyWidth, keyHeight,
180 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); 180 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c);
181 } 181 }
182 else 182 else
183 // center the image in the middle of the key 183 // center the image in the middle of the key
184 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, 184 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2,
185 y + (keyHeight - pix->height())/2 + 1, 185 y + (keyHeight - pix->height())/2 + 1,
186 *pix ); 186 *pix );
187 187
188 // this fixes the problem that the very right end of the board's vertical line 188 // this fixes the problem that the very right end of the board's vertical line
189 // gets painted over, because it's one pixel shorter than all other keys 189 // gets painted over, because it's one pixel shorter than all other keys
190 p.setPen(keycolor_lines); 190 p.setPen(keycolor_lines);
191 p.drawLine(width() - 1, 0, width() - 1, height()); 191 p.drawLine(width() - 1, 0, width() - 1, height());
192 192
193 } else { 193 } else {
194 194
195 195
196 p.fillRect(0, 0, width(), height(), keycolor); 196 p.fillRect(0, 0, width(), height(), keycolor);
197 197
198 for (row = 1; row <= 5; row++) { 198 for (row = 1; row <= 5; row++) {
199 199
200 int x = 0; 200 int x = 0;
201 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 201 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
202 202
203 p.setPen(keycolor_lines); 203 p.setPen(keycolor_lines);
204 p.drawLine(x, y, x + width(), y); 204 p.drawLine(x, y, x + width(), y);
205 205
206 for (int col = 0; col < keys->numKeys(row); col++) { 206 for (int col = 0; col < keys->numKeys(row); col++) {
207 207
208 QPixmap *pix = keys->pix(row, col); 208 QPixmap *pix = keys->pix(row, col);
209 int keyWidth = keys->width(row, col); 209 int keyWidth = keys->width(row, col);
210 210
211 211
212 int keyWidthPix = defaultKeyWidth * keyWidth; 212 int keyWidthPix = defaultKeyWidth * keyWidth;
213 213
214 if (keys->pressed(row, col)) 214 if (keys->pressed(row, col))
215 p.fillRect(x+1, y+1, keyWidthPix - 1, 215 p.fillRect(x+1, y+1, keyWidthPix - 1,
216 keyHeight - 1, keycolor_pressed); 216 keyHeight - 1, keycolor_pressed);
217 217
218 ushort c = keys->uni(row, col); 218 ushort c = keys->uni(row, col);
219 219
220 if (!pix) { 220 if (!pix) {
221 p.setPen(textcolor); 221 p.setPen(textcolor);
222 p.drawText(x, y, 222 p.drawText(x, y,
223 keyWidthPix, keyHeight, 223 keyWidthPix, keyHeight,
224 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); 224 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c);
225 } 225 }
226 else { 226 else {
227 // center the image in the middle of the key 227 // center the image in the middle of the key
228 p.drawPixmap( x + (keyWidthPix - pix->width())/2, 228 p.drawPixmap( x + (keyWidthPix - pix->width())/2,
229 y + (keyHeight - pix->height())/2 + 1, 229 y + (keyHeight - pix->height())/2 + 1,
230 QPixmap(*pix) ); 230 QPixmap(*pix) );
231 } 231 }
232 232
233 p.setPen(keycolor_lines); 233 p.setPen(keycolor_lines);
234 p.drawLine(x, y, x, y + keyHeight); 234 p.drawLine(x, y, x, y + keyHeight);
235 235
236 x += keyWidthPix; 236 x += keyWidthPix;
237 } 237 }
238 238
239 239
240 } 240 }
241 p.drawLine(0, height() - 1, width(), height() - 1); 241 p.drawLine(0, height() - 1, width(), height() - 1);
242 p.drawLine(width() - 1, 0, width() - 1, height()); 242 p.drawLine(width() - 1, 0, width() - 1, height());
243 } 243 }
244 244
245} 245}
246 246
247 247
248/* Keyboard::mousePressEvent {{{1 */ 248/* Keyboard::mousePressEvent {{{1 */
249void Keyboard::mousePressEvent(QMouseEvent *e) 249void Keyboard::mousePressEvent(QMouseEvent *e)
250{ 250{
251 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; 251 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
252 if (row > 5) row = 5; 252 if (row > 5) row = 5;
253 253
254 // figure out the column 254 // figure out the column
255 int col = 0; 255 int col = 0;
256 for (int w = 0; e->x() >= w; col++) 256 for (int w = 0; e->x() >= w; col++)
257 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys 257 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys
258 w += keys->width(row,col) * defaultKeyWidth; 258 w += keys->width(row,col) * defaultKeyWidth;
259 else break; 259 else break;
260 260
261 col --; // rewind one... 261 col --; // rewind one...
262 262
263 qkeycode = keys->qcode(row, col); 263 qkeycode = keys->qcode(row, col);
264 unicode = keys->uni(row, col); 264 unicode = keys->uni(row, col);
265 265
266 // might need to repaint if two or more of the same keys. 266 // might need to repaint if two or more of the same keys.
267 // should be faster if just paint one key even though multiple keys exist. 267 // should be faster if just paint one key even though multiple keys exist.
268 bool need_repaint = FALSE; 268 bool need_repaint = FALSE;
269 269
270 if (unicode == 0) { // either Qt char, or nothing 270 if (unicode == 0) { // either Qt char, or nothing
271 271
272 if (qkeycode == Qt::Key_F1) { // toggle the pickboard 272 if (qkeycode == Qt::Key_F1) { // toggle the pickboard
273 273
274 if ( configdlg ) { 274 if ( configdlg ) {
275 delete (ConfigDlg *) configdlg; 275 delete (ConfigDlg *) configdlg;
276 configdlg = 0; 276 configdlg = 0;
277 } 277 }
278 else { 278 else {
279 configdlg = new ConfigDlg (); 279 configdlg = new ConfigDlg ();
280 connect(configdlg, SIGNAL(pickboardToggled(bool)), 280 connect(configdlg, SIGNAL(pickboardToggled(bool)),
281 this, SLOT(togglePickboard(bool))); 281 this, SLOT(togglePickboard(bool)));
282 connect(configdlg, SIGNAL(setMapToDefault()), 282 connect(configdlg, SIGNAL(setMapToDefault()),
283 this, SLOT(setMapToDefault())); 283 this, SLOT(setMapToDefault()));
284 connect(configdlg, SIGNAL(setMapToFile(QString)), 284 connect(configdlg, SIGNAL(setMapToFile(QString)),
285 this, SLOT(setMapToFile(QString))); 285 this, SLOT(setMapToFile(QString)));
286 configdlg->showMaximized(); 286 configdlg->showMaximized();
287 configdlg->show(); 287 configdlg->show();
288 configdlg->raise(); 288 configdlg->raise();
289 } 289 }
290 290
291 } else if (qkeycode == Qt::Key_Control) { 291 } else if (qkeycode == Qt::Key_Control) {
292 ctrl = keys->pressedPtr(row, col); 292 ctrl = keys->pressedPtr(row, col);
293 need_repaint = TRUE; 293 need_repaint = TRUE;
294 *ctrl = !keys->pressed(row, col); 294 *ctrl = !keys->pressed(row, col);
295 295
296 } else if (qkeycode == Qt::Key_Alt) { 296 } else if (qkeycode == Qt::Key_Alt) {
297 alt = keys->pressedPtr(row, col); 297 alt = keys->pressedPtr(row, col);
298 need_repaint = TRUE; 298 need_repaint = TRUE;
299 *alt = !keys->pressed(row, col); 299 *alt = !keys->pressed(row, col);
300 300
301 } else if (qkeycode == Qt::Key_Shift) { 301 } else if (qkeycode == Qt::Key_Shift) {
302 need_repaint = TRUE; 302 need_repaint = TRUE;
303 303
304 if (shift) { 304 if (shift) {
305 *shift = 0; 305 *shift = 0;
306 shift = 0; 306 shift = 0;
307 } 307 }
308 else { 308 else {
309 shift = keys->pressedPtr(row, col); 309 shift = keys->pressedPtr(row, col);
310 *shift = 1; 310 *shift = 1;
311 if (lock) { 311 if (lock) {
312 *lock = 0; 312 *lock = 0;
313 lock = 0; 313 lock = 0;
314 } 314 }
315 } 315 }
316 316
317 } else if (qkeycode == Qt::Key_CapsLock) { 317 } else if (qkeycode == Qt::Key_CapsLock) {
318 need_repaint = TRUE; 318 need_repaint = TRUE;
319 319
320 if (lock) { 320 if (lock) {
321 *lock = 0; 321 *lock = 0;
322 lock = 0; 322 lock = 0;
323 } 323 }
324 else { 324 else {
325 lock = keys->pressedPtr(row, col);; 325 lock = keys->pressedPtr(row, col);;
326 *lock = 1; 326 *lock = 1;
327 if (shift) { 327 if (shift) {
328 *shift = 0; 328 *shift = 0;
329 shift = 0; 329 shift = 0;
330 } 330 }
331 } 331 }
332 332
333 } 333 }
334 334
335 } 335 }
336 else { // normal char 336 else { // normal char
337 if ((shift || lock) && keys->shift(unicode)) { 337 if ((shift || lock) && keys->shift(unicode)) {
338 unicode = keys->shift(unicode); 338 unicode = keys->shift(unicode);
339 } 339 }
340 } 340 }
341 341
342 // korean parsing 342 // korean parsing
343 if (keys->lang == "ko") { 343 if (keys->lang == "ko") {
344 344
345 unicode = parseKoreanInput(unicode); 345 unicode = parseKoreanInput(unicode);
346 } 346 }
347 347
348 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); 348 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
349 349
350 emit key(unicode, qkeycode, modifiers, true, false); 350 emit key(unicode, qkeycode, modifiers, true, false);
351 351
352 // pickboard stuff 352 // pickboard stuff
353 if (usePicks) { 353 if (usePicks) {
354 354
355 KeyboardConfig *dc = picks->dc; 355 KeyboardConfig *dc = picks->dc;
356 356
357 if (dc) { 357 if (dc) {
358 if (qkeycode == Qt::Key_Backspace) { 358 if (qkeycode == Qt::Key_Backspace) {
359 dc->input.remove(dc->input.last()); // remove last input 359 dc->input.remove(dc->input.last()); // remove last input
360 dc->decBackspaces(); 360 dc->decBackspaces();
361 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { 361 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) {
362 dc->input.clear(); 362 dc->input.clear();
363 dc->resetBackspaces(); 363 dc->resetBackspaces();
364 } else { 364 } else {
365 dc->add(QString(QChar(unicode))); 365 dc->add(QString(QChar(unicode)));
366 dc->incBackspaces(); 366 dc->incBackspaces();
367 } 367 }
368 } 368 }
369 picks->repaint(); 369 picks->repaint();
370 } 370 }
371 371
372 372
373 // painting 373 // painting
374 pressed = TRUE; 374 pressed = TRUE;
375 375
376 pressedKeyRow = row; 376 pressedKeyRow = row;
377 pressedKeyCol = col; 377 pressedKeyCol = col;
378 378
379 if (need_repaint) repaint(FALSE); 379 if (need_repaint) repaint(FALSE);
380 else { // just paint the one key pressed 380 else { // just paint the one key pressed
381 381
382 382
383 383
384 QPainter p(this); 384 QPainter p(this);
385 drawKeyboard(p, row, col); 385 drawKeyboard(p, row, col);
386 386
387 } 387 }
388 388
389 pressTid = startTimer(80); 389 pressTid = startTimer(80);
390 390
391} 391}
392 392
393 393
394/* Keyboard::mouseReleaseEvent {{{1 */ 394/* Keyboard::mouseReleaseEvent {{{1 */
395void Keyboard::mouseReleaseEvent(QMouseEvent*) 395void Keyboard::mouseReleaseEvent(QMouseEvent*)
396{ 396{
397 pressed = FALSE; 397 pressed = FALSE;
398 if ( pressTid == 0 ) 398 if ( pressTid == 0 )
399#if defined(Q_WS_QWS) || defined(_WS_QWS_) 399#if defined(Q_WS_QWS) || defined(_WS_QWS_)
400 if ( unicode != -1 ) { 400 if ( unicode != -1 ) {
401 emit key( unicode, qkeycode, modifiers, false, false ); 401 emit key( unicode, qkeycode, modifiers, false, false );
402 repeatTimer->stop(); 402 repeatTimer->stop();
403 } 403 }
404#endif 404#endif
405 if (shift && unicode != 0) { 405 if (shift && unicode != 0) {
406 406
407 407
408 *shift = 0; // unpress shift key 408 *shift = 0; // unpress shift key
409 shift = 0; // reset the shift pointer 409 shift = 0; // reset the shift pointer
410 repaint(FALSE); 410 repaint(FALSE);
411 411
412 } 412 }
413 else 413 else
414 414
415 clearHighlight(); 415 clearHighlight();
416} 416}
417 417
418/* Keyboard::timerEvent {{{1 */ 418/* Keyboard::timerEvent {{{1 */
419/* 419/*
420void Keyboard::timerEvent(QTimerEvent* e) 420void Keyboard::timerEvent(QTimerEvent* e)
421{ 421{
422 if ( e->timerId() == pressTid ) { 422 if ( e->timerId() == pressTid ) {
423 killTimer(pressTid); 423 killTimer(pressTid);
424 pressTid = 0; 424 pressTid = 0;
425 if ( !pressed ) 425 if ( !pressed )
426 cout << "calling clearHighlight from timerEvent\n"; 426 cout << "calling clearHighlight from timerEvent\n";
427 clearHighlight(); 427 clearHighlight();
428 } 428 }
429} 429}
430*/ 430*/
431 431
432void Keyboard::repeat() 432void Keyboard::repeat()
433{ 433{
434 434
435 repeatTimer->start( 200 ); 435 repeatTimer->start( 200 );
436 emit key( unicode, 0, modifiers, true, true ); 436 emit key( unicode, 0, modifiers, true, true );
437} 437}
438 438
439void Keyboard::clearHighlight() 439void Keyboard::clearHighlight()
440{ 440{
441 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { 441 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) {
442 int tmpRow = pressedKeyRow; 442 int tmpRow = pressedKeyRow;
443 int tmpCol = pressedKeyCol; 443 int tmpCol = pressedKeyCol;
444 444
445 pressedKeyRow = -1; 445 pressedKeyRow = -1;
446 pressedKeyCol = -1; 446 pressedKeyCol = -1;
447 447
448 QPainter p(this); 448 QPainter p(this);
449 drawKeyboard(p, tmpRow, tmpCol); 449 drawKeyboard(p, tmpRow, tmpCol);
450 } 450 }
451} 451}
452 452
453 453
454/* Keyboard::sizeHint {{{1 */ 454/* Keyboard::sizeHint {{{1 */
455QSize Keyboard::sizeHint() const 455QSize Keyboard::sizeHint() const
456{ 456{
457 QFontMetrics fm=fontMetrics(); 457 QFontMetrics fm=fontMetrics();
458 int keyHeight = fm.lineSpacing() + 2; 458 int keyHeight = fm.lineSpacing() + 2;
459 459
460 return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); 460 return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1);
461} 461}
462 462
463 463
464void Keyboard::resetState() 464void Keyboard::resetState()
465{ 465{
466 schar = mchar = echar = 0; 466 schar = mchar = echar = 0;
467 picks->resetState(); 467 picks->resetState();
468} 468}
469 469
470/* Keyboard::togglePickboard {{{1 */ 470/* Keyboard::togglePickboard {{{1 */
471void Keyboard::togglePickboard(bool on_off) 471void Keyboard::togglePickboard(bool on_off)
472{ 472{
473 usePicks = on_off; 473 usePicks = on_off;
474 if (usePicks) { 474 if (usePicks) {
475 picks->show(); 475 picks->show();
476 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send 476 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send
477 //adjustSize(); 477 //adjustSize();
478 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 478 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
479 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 479 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
480 } else { 480 } else {
481 481
482 picks->hide(); 482 picks->hide();
483 picks->resetState(); 483 picks->resetState();
484 //move(x(), y() + picks->height()); 484 //move(x(), y() + picks->height());
485 //adjustSize(); 485 //adjustSize();
486 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 486 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
487 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 487 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
488 488
489 } 489 }
490 /* 490 /*
491 * this closes && opens the input method 491 * this closes && opens the input method
492 */ 492 */
493 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 493 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
494 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 494 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
495} 495}
496 496
497/* Keyboard::setMapTo ... {{{1 */ 497/* Keyboard::setMapTo ... {{{1 */
498void Keyboard::setMapToDefault() { 498void Keyboard::setMapToDefault() {
499 499
500 500
501 /* load current locale language map */ 501 /* load current locale language map */
502 Config *config = new Config("locale"); 502 Config *config = new Config("locale");
503 config->setGroup( "Language" ); 503 config->setGroup( "Language" );
504 QString l = config->readEntry( "Language" , "en" ); 504 QString l = config->readEntry( "Language" , "en" );
505 delete config; 505 delete config;
506 506
507 QString key_map = QPEApplication::qpeDir() + "/share/multikey/" 507 QString key_map = QPEApplication::qpeDir() + "/share/multikey/"
508 + l + ".keymap"; 508 + l + ".keymap";
509 509
510 /* save change to multikey config file */ 510 /* save change to multikey config file */
511 config = new Config("multikey"); 511 config = new Config("multikey");
512 config->setGroup ("keymaps"); 512 config->setGroup ("keymaps");
513 config->writeEntry ("current", key_map); // default closed 513 config->writeEntry ("current", key_map); // default closed
514 delete config; 514 delete config;
515 515
516 delete keys; 516 delete keys;
517 keys = new Keys(key_map); 517 keys = new Keys(key_map);
518 518
519 // have to repaint the keyboard 519 // have to repaint the keyboard
520 repaint(FALSE); 520 repaint(FALSE);
521} 521}
522 522
523void Keyboard::setMapToFile(QString file) { 523void Keyboard::setMapToFile(QString file) {
524 524
525 /* save change to multikey config file */ 525 /* save change to multikey config file */
526 Config *config = new Config("multikey"); 526 Config *config = new Config("multikey");
527 config->setGroup ("keymaps"); 527 config->setGroup ("keymaps");
528 config->writeEntry ("current", file); // default closed 528 config->writeEntry ("current", file); // default closed
529 delete config; 529 delete config;
530 530
531 delete keys; 531 delete keys;
532 keys = new Keys(file); 532 keys = new Keys(file);
533 repaint(FALSE); 533 repaint(FALSE);
534 534
535} 535}
536 536
537/* korean input functions {{{1 537/* korean input functions {{{1
538 * 538 *
539 * TODO 539 * TODO
540 * one major problem with this implementation is that you can't move the 540 * one major problem with this implementation is that you can't move the
541 * cursor after inputing korean chars, otherwise it will eat up and replace 541 * cursor after inputing korean chars, otherwise it will eat up and replace
542 * the char before the cursor you move to. fix that 542 * the char before the cursor you move to. fix that
543 * 543 *
544 * make backspace delete one single char, not the whole thing if still 544 * make backspace delete one single char, not the whole thing if still
545 * editing. 545 * editing.
546 * 546 *
547 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 547 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
548 * 548 *
549 * how korean input works 549 * how korean input works
550 * 550 *
551 * all following chars means unicode char value and are in hex 551 * all following chars means unicode char value and are in hex
552 * 552 *
553 * ÃÊÀ½ = schar (start char) 553 * ÃÊÀ½ = schar (start char)
554 * ÁßÀ½ = mchar (middle char) 554 * ÁßÀ½ = mchar (middle char)
555 * ³¡À½ = echar (end char) 555 * ³¡À½ = echar (end char)
556 * 556 *
557 * there are 19 schars. unicode position is at 1100 - 1112 557 * there are 19 schars. unicode position is at 1100 - 1112
558 * there are 21 mchars. unicode position is at 1161 - 1175 558 * there are 21 mchars. unicode position is at 1161 - 1175
559 * there are 27 echars. unicode position is at 11a8 - 11c2 559 * there are 27 echars. unicode position is at 11a8 - 11c2
560 * 560 *
561 * the map with everything combined is at ac00 - d7a3 561 * the map with everything combined is at ac00 - d7a3
562 * 562 *
563 */ 563 */
564 564
565ushort Keyboard::parseKoreanInput (ushort c) { 565ushort Keyboard::parseKoreanInput (ushort c) {
566 566
567 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) 567 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
568 || 568 ||
569 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode 569 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
570 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { 570 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
571 571
572 schar = 0, mchar = 0, echar = 0; 572 schar = 0, mchar = 0, echar = 0;
573 return c; 573 return c;
574 } 574 }
575 575
576 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input 576 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input
577 577
578 if (schar == 0 || (schar != 0 && mchar == 0)) { 578 if (schar == 0 || (schar != 0 && mchar == 0)) {
579 schar = c; mchar = 0; echar = 0; 579 schar = c; mchar = 0; echar = 0;
580 return c; 580 return c;
581 } 581 }
582 else if (mchar != 0) { 582 else if (mchar != 0) {
583 583
584 if (echar == 0) { 584 if (echar == 0) {
585 585
586 if (!(echar = constoe(c))) { 586 if (!(echar = constoe(c))) {
587 587
588 schar = c; mchar = 0; echar = 0; 588 schar = c; mchar = 0; echar = 0;
589 return c; 589 return c;
590 } 590 }
591 591
592 } 592 }
593 else { // must figure out what the echar is 593 else { // must figure out what the echar is
594 594
595 if (echar == 0x11a8) { // ¤¡ 595 if (echar == 0x11a8) { // ¤¡
596 596
597 if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ 597 if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡
598 else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ 598 else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ
599 else { 599 else {
600 schar = c; mchar = 0; echar = 0; 600 schar = c; mchar = 0; echar = 0;
601 return c; 601 return c;
602 } 602 }
603 603
604 } else if (echar == 0x11ab) { // ¤¤ 604 } else if (echar == 0x11ab) { // ¤¤
605 605
606 if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ 606 if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸
607 else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ 607 else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾
608 else { 608 else {
609 schar = c; mchar = 0; echar = 0; 609 schar = c; mchar = 0; echar = 0;
610 return c; 610 return c;
611 } 611 }
612 612
613 } else if (echar == 0x11af) { // ¤© 613 } else if (echar == 0x11af) { // ¤©
614 614
615 if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ 615 if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡
616 else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± 616 else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤±
617 else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² 617 else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤²
618 else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ 618 else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ
619 else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ 619 else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼
620 else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ 620 else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½
621 else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ 621 else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾
622 else { 622 else {
623 schar = c; mchar = 0; echar = 0; 623 schar = c; mchar = 0; echar = 0;
624 return c; 624 return c;
625 } 625 }
626 626
627 } else if (echar == 0x11b8) { // ¤² 627 } else if (echar == 0x11b8) { // ¤²
628 628
629 if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ 629 if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ
630 else { 630 else {
631 schar = c; mchar = 0; echar = 0; 631 schar = c; mchar = 0; echar = 0;
632 return c; 632 return c;
633 } 633 }
634 634
635 } else if (echar == 0x11ba) { // ¤µ 635 } else if (echar == 0x11ba) { // ¤µ
636 636
637 if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ 637 if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ
638 else { 638 else {
639 schar = c; mchar = 0; echar = 0; 639 schar = c; mchar = 0; echar = 0;
640 return c; 640 return c;
641 } 641 }
642 642
643 } else { // if any other char, cannot combine chars 643 } else { // if any other char, cannot combine chars
644 644
645 schar = c; mchar = 0; echar = 0; 645 schar = c; mchar = 0; echar = 0;
646 return c; 646 return c;
647 } 647 }
648 648
649 unicode = echar; 649 unicode = echar;
650 } 650 }
651 } 651 }
652 652
653 } 653 }
654 else if (0x1161 <= c && c <= 0x1175) { // mchar was input 654 else if (0x1161 <= c && c <= 0x1175) { // mchar was input
655 655
656 if (schar != 0 && mchar == 0) { mchar = c; } 656 if (schar != 0 && mchar == 0) { mchar = c; }
657 657
658 else if (schar != 0 && mchar != 0 && echar == 0) { 658 else if (schar != 0 && mchar != 0 && echar == 0) {
659 659
660 switch (mchar) { 660 switch (mchar) {
661 case 0x1169: 661 case 0x1169:
662 if (c == 0x1161) mchar = 0x116a; 662 if (c == 0x1161) mchar = 0x116a;
663 else if (c == 0x1162) mchar = 0x116b; 663 else if (c == 0x1162) mchar = 0x116b;
664 else if (c == 0x1175) mchar = 0x116c; 664 else if (c == 0x1175) mchar = 0x116c;
665 else { 665 else {
666 schar = 0; mchar = 0; echar = 0; 666 schar = 0; mchar = 0; echar = 0;
667 return c; 667 return c;
668 } 668 }
669 break; 669 break;
670 case 0x116e: 670 case 0x116e:
671 if (c == 0x1165) mchar = 0x116f; 671 if (c == 0x1165) mchar = 0x116f;
672 else if (c == 0x1166) mchar = 0x1170; 672 else if (c == 0x1166) mchar = 0x1170;
673 else if (c == 0x1175) mchar = 0x1171; 673 else if (c == 0x1175) mchar = 0x1171;
674 else { 674 else {
675 schar = 0; mchar = 0; echar = 0; 675 schar = 0; mchar = 0; echar = 0;
676 return c; 676 return c;
677 } 677 }
678 break; 678 break;
679 case 0x1173: 679 case 0x1173:
680 if (c == 0x1175) mchar = 0x1174; 680 if (c == 0x1175) mchar = 0x1174;
681 else { 681 else {
682 schar = 0; mchar = 0; echar = 0; 682 schar = 0; mchar = 0; echar = 0;
683 return c; 683 return c;
684 } 684 }
685 break; 685 break;
686 default: 686 default:
687 schar = 0; mchar = 0; echar = 0; 687 schar = 0; mchar = 0; echar = 0;
688 return c; 688 return c;
689 } 689 }
690 } 690 }
691 else if (schar != 0 && mchar != 0 && echar != 0) { 691 else if (schar != 0 && mchar != 0 && echar != 0) {
692 692
693 emit key( 8, Qt::Key_Backspace, 0, true, false ); 693 emit key( 8, Qt::Key_Backspace, 0, true, false );
694 694
695 ushort prev = 0; 695 ushort prev = 0;
696 switch (echar) { 696 switch (echar) {
697 /* 697 /*
698 case 0x11a9: 698 case 0x11a9:
699 prev = combineKoreanChars(schar, mchar, 0x11a8); 699 prev = combineKoreanChars(schar, mchar, 0x11a8);
700 schar = 0x1100; 700 schar = 0x1100;
701 break; 701 break;
702 */ 702 */
703 case 0x11aa: 703 case 0x11aa:
704 prev = combineKoreanChars(schar, mchar, 0x11a8); 704 prev = combineKoreanChars(schar, mchar, 0x11a8);
705 schar = 0x1109; 705 schar = 0x1109;
706 break; 706 break;
707 case 0x11ac: 707 case 0x11ac:
708 prev = combineKoreanChars(schar, mchar, 0x11ab); 708 prev = combineKoreanChars(schar, mchar, 0x11ab);
709 schar = 0x110c; 709 schar = 0x110c;
710 break; 710 break;
711 case 0x11ad: 711 case 0x11ad:
712 prev = combineKoreanChars(schar, mchar, 0x11ab); 712 prev = combineKoreanChars(schar, mchar, 0x11ab);
713 schar = 0x1112; 713 schar = 0x1112;
714 break; 714 break;
715 case 0x11b0: 715 case 0x11b0:
716 prev = combineKoreanChars(schar, mchar, 0x11af); 716 prev = combineKoreanChars(schar, mchar, 0x11af);
717 schar = 0x1100; 717 schar = 0x1100;
718 break; 718 break;
719 case 0x11b1: 719 case 0x11b1:
720 prev = combineKoreanChars(schar, mchar, 0x11af); 720 prev = combineKoreanChars(schar, mchar, 0x11af);
721 schar = 0x1106; 721 schar = 0x1106;
722 break; 722 break;
723 case 0x11b2: 723 case 0x11b2:
724 prev = combineKoreanChars(schar, mchar, 0x11af); 724 prev = combineKoreanChars(schar, mchar, 0x11af);
725 schar = 0x1107; 725 schar = 0x1107;
726 break; 726 break;
727 case 0x11b3: 727 case 0x11b3:
728 prev = combineKoreanChars(schar, mchar, 0x11af); 728 prev = combineKoreanChars(schar, mchar, 0x11af);
729 schar = 0x1109; 729 schar = 0x1109;
730 break; 730 break;
731 case 0x11b4: 731 case 0x11b4:
732 prev = combineKoreanChars(schar, mchar, 0x11af); 732 prev = combineKoreanChars(schar, mchar, 0x11af);
733 schar = 0x1110; 733 schar = 0x1110;
734 break; 734 break;
735 case 0x11b9: 735 case 0x11b9:
736 prev = combineKoreanChars(schar, mchar, 0x11b8); 736 prev = combineKoreanChars(schar, mchar, 0x11b8);
737 schar = 0x1109; 737 schar = 0x1109;
738 break; 738 break;
739 /* 739 /*
740 case 0x11bb: 740 case 0x11bb:
741 prev = combineKoreanChars(schar, mchar, 0x11ba); 741 prev = combineKoreanChars(schar, mchar, 0x11ba);
742 schar = 0x1109; 742 schar = 0x1109;
743 break; 743 break;
744 */ 744 */
745 default: 745 default:
746 746
747 if (constoe(echar)) { 747 if (constoe(echar)) {
748 748
749 prev = combineKoreanChars(schar, mchar, 0); 749 prev = combineKoreanChars(schar, mchar, 0);
750 schar = constoe(echar); 750 schar = constoe(echar);
751 } 751 }
752 break; 752 break;
753 } 753 }
754 754
755 emit key( prev, prev, 0, true, false ); 755 emit key( prev, prev, 0, true, false );
756 756
757 mchar = c; echar = 0; 757 mchar = c; echar = 0;
758 758
759 return combineKoreanChars(schar, mchar, 0); 759 return combineKoreanChars(schar, mchar, 0);
760 760
761 } 761 }
762 else { 762 else {
763 schar = 0; mchar = 0; echar = 0; 763 schar = 0; mchar = 0; echar = 0;
764 return c; 764 return c;
765 } 765 }
766 766
767 } 767 }
768 else /*if (c == ' ')*/ return c; 768 else /*if (c == ' ')*/ return c;
769 769
770 770
771 // and now... finally delete previous char, and return new char 771 // and now... finally delete previous char, and return new char
772 emit key( 8, Qt::Key_Backspace, 0, true, false ); 772 emit key( 8, Qt::Key_Backspace, 0, true, false );
773 773
774 774
775 return combineKoreanChars( schar, mchar, echar); 775 return combineKoreanChars( schar, mchar, echar);
776 776
777} 777}
778 778
779ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { 779ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) {
780 780
781 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; 781 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00;
782 782
783} 783}
784 784
785ushort Keyboard::constoe(const ushort c) { 785ushort Keyboard::constoe(const ushort c) {
786 786
787 // converts schars to echars if possible 787 // converts schars to echars if possible
788 788
789 if (0x1100 <= c && c <= 0x1112) { // schar to echar 789 if (0x1100 <= c && c <= 0x1112) { // schar to echar
790 790
791 switch (c) { 791 switch (c) {
792 case 0x1100: return 0x11a8; 792 case 0x1100: return 0x11a8;
793 case 0x1101: return 0x11a9; 793 case 0x1101: return 0x11a9;
794 case 0x1102: return 0x11ab; 794 case 0x1102: return 0x11ab;
795 case 0x1103: return 0x11ae; 795 case 0x1103: return 0x11ae;
796 case 0x1105: return 0x11af; 796 case 0x1105: return 0x11af;
797 case 0x1106: return 0x11b7; 797 case 0x1106: return 0x11b7;
798 case 0x1107: return 0x11b8; 798 case 0x1107: return 0x11b8;
799 case 0x1109: return 0x11ba; 799 case 0x1109: return 0x11ba;
800 case 0x110a: return 0x11bb; 800 case 0x110a: return 0x11bb;
801 case 0x110b: return 0x11bc; 801 case 0x110b: return 0x11bc;
802 case 0x110c: return 0x11bd; 802 case 0x110c: return 0x11bd;
803 case 0x110e: return 0x11be; 803 case 0x110e: return 0x11be;
804 case 0x110f: return 0x11bf; 804 case 0x110f: return 0x11bf;
805 case 0x1110: return 0x11c0; 805 case 0x1110: return 0x11c0;
806 case 0x1111: return 0x11c1; 806 case 0x1111: return 0x11c1;
807 case 0x1112: return 0x11c2; 807 case 0x1112: return 0x11c2;
808 default: return 0; 808 default: return 0;
809 809
810 } 810 }
811 811
812 } else { //echar to schar 812 } else { //echar to schar
813 813
814 switch (c) { 814 switch (c) {
815 case 0x11a8: return 0x1100; 815 case 0x11a8: return 0x1100;
816 case 0x11a9: return 0x1101; 816 case 0x11a9: return 0x1101;
817 case 0x11ab: return 0x1102; 817 case 0x11ab: return 0x1102;
818 case 0x11ae: return 0x1103; 818 case 0x11ae: return 0x1103;
819 case 0x11af: return 0x1105; 819 case 0x11af: return 0x1105;
820 case 0x11b7: return 0x1106; 820 case 0x11b7: return 0x1106;
821 case 0x11b8: return 0x1107; 821 case 0x11b8: return 0x1107;
822 case 0x11ba: return 0x1109; 822 case 0x11ba: return 0x1109;
823 case 0x11bb: return 0x110a; 823 case 0x11bb: return 0x110a;
824 case 0x11bc: return 0x110b; 824 case 0x11bc: return 0x110b;
825 case 0x11bd: return 0x110c; 825 case 0x11bd: return 0x110c;
826 case 0x11be: return 0x110e; 826 case 0x11be: return 0x110e;
827 case 0x11bf: return 0x110f; 827 case 0x11bf: return 0x110f;
828 case 0x11c0: return 0x1110; 828 case 0x11c0: return 0x1110;
829 case 0x11c1: return 0x1111; 829 case 0x11c1: return 0x1111;
830 case 0x11c2: return 0x1112; 830 case 0x11c2: return 0x1112;
831 default: return 0; 831 default: return 0;
832 832
833 } 833 }
834 834
835 } 835 }
836} 836}
837 837
838 838
839// Keys::Keys {{{1 839// Keys::Keys {{{1
840 840
841Keys::Keys() { 841Keys::Keys() {
842 842
843 Config *config = new Config ("multikey"); 843 Config *config = new Config ("multikey");
844 config->setGroup( "keymaps" ); 844 config->setGroup( "keymaps" );
845 QString key_map = config->readEntry( "current" ); 845 QString key_map = config->readEntry( "current" );
846 delete config; 846 delete config;
847 847
848 if (key_map.isNull()) { 848 if (key_map.isNull()) {
849 849
850 Config *config = new Config("locale"); 850 Config *config = new Config("locale");
851 config->setGroup( "Language" ); 851 config->setGroup( "Language" );
852 QString l = config->readEntry( "Language" , "en" ); 852 QString l = config->readEntry( "Language" , "en" );
853 delete config; 853 delete config;
854 854
855 key_map = QPEApplication::qpeDir() + "/share/multikey/" 855 key_map = QPEApplication::qpeDir() + "/share/multikey/"
856 + l + ".keymap"; 856 + l + ".keymap";
857 857
858 } 858 }
859 859
860 860
861 setKeysFromFile(key_map); 861 setKeysFromFile(key_map);
862} 862}
863 863
864Keys::Keys(const char * filename) { 864Keys::Keys(const char * filename) {
865 865
866 setKeysFromFile(filename); 866 setKeysFromFile(filename);
867} 867}
868 868
869// Keys::setKeysFromFile {{{2 869// Keys::setKeysFromFile {{{2
870void Keys::setKeysFromFile(const char * filename) { 870void Keys::setKeysFromFile(const char * filename) {
871 871
872 QFile f(filename); 872 QFile f(filename);
873 873
874 if (f.open(IO_ReadOnly)) { 874 if (f.open(IO_ReadOnly)) {
875 875
876 QTextStream t(&f); 876 QTextStream t(&f);
877 int row; 877 int row;
878 int qcode; 878 int qcode;
879 ushort unicode; 879 ushort unicode;
880 int width; 880 int width;
881 QString buf; 881 QString buf;
882 QString comment; 882 QString comment;
883 char * xpm[256]; //couldnt be larger than that... could it? 883 char * xpm[256]; //couldnt be larger than that... could it?
884 QPixmap *xpm2pix = 0; 884 QPixmap *xpm2pix = 0;
885 885
886 buf = t.readLine(); 886 buf = t.readLine();
887 while (buf) { 887 while (buf) {
888 888
889 // key definition 889 // key definition
890 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { 890 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
891 // no $1 type referencing!!! this implementation of regexp sucks 891 // no $1 type referencing!!! this implementation of regexp sucks
892 892
893 // dont know of any sscanf() type funcs in Qt lib 893 // dont know of any sscanf() type funcs in Qt lib
894 QTextStream tmp (buf, IO_ReadOnly); 894 QTextStream tmp (buf, IO_ReadOnly);
895 tmp >> row >> qcode >> unicode >> width >> comment; 895 tmp >> row >> qcode >> unicode >> width >> comment;
896 896
897 buf = t.readLine(); 897 buf = t.readLine();
898 int xpmLineCount = 0; 898 int xpmLineCount = 0;
899 xpm2pix = 0; 899 xpm2pix = 0;
900 900
901 // erase blank space 901 // erase blank space
902 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); 902 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
903 903
904 while (buf.contains(QRegExp("^\\s*\".*\""))) { 904 while (buf.contains(QRegExp("^\\s*\".*\""))) {
905 905
906 QString xpmBuf = buf.stripWhiteSpace(); 906 QString xpmBuf = buf.stripWhiteSpace();
907 907
908 xpm[xpmLineCount] = new char [xpmBuf.length()]; 908 xpm[xpmLineCount] = new char [xpmBuf.length()];
909 909
910 int j = 0; 910 int j = 0;
911 for (ushort i = 0; i < xpmBuf.length(); i++) { 911 for (ushort i = 0; i < xpmBuf.length(); i++) {
912 if (xpmBuf[i].latin1() != '"') { 912 if (xpmBuf[i].latin1() != '"') {
913 913
914 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); 914 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1();
915 j++; 915 j++;
916 } 916 }
917 917
918 } 918 }
919 // have to close that facker up 919 // have to close that facker up
920 ((char *)xpm[xpmLineCount])[j] = '\0'; 920 ((char *)xpm[xpmLineCount])[j] = '\0';
921 921
922 xpmLineCount++; 922 xpmLineCount++;
923 buf = t.readLine(); 923 buf = t.readLine();
924 } 924 }
925 if (xpmLineCount) { 925 if (xpmLineCount) {
926 926
927 xpm2pix = new QPixmap((const char **)xpm); 927 xpm2pix = new QPixmap((const char **)xpm);
928 for (int i = 0; i < xpmLineCount; i++) 928 for (int i = 0; i < xpmLineCount; i++)
929 929
930 delete [] (xpm[i]); 930 delete [] (xpm[i]);
931 931
932 } 932 }
933 setKey(row, qcode, unicode, width, xpm2pix); 933 setKey(row, qcode, unicode, width, xpm2pix);
934 } 934 }
935 935
936 // shift map 936 // shift map
937 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 937 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
938 938
939 QTextStream tmp (buf, IO_ReadOnly); 939 QTextStream tmp (buf, IO_ReadOnly);
940 ushort lower, shift; 940 ushort lower, shift;
941 tmp >> lower >> shift; 941 tmp >> lower >> shift;
942 942
943 shiftMap.insert(lower, shift); 943 shiftMap.insert(lower, shift);
944 944
945 buf = t.readLine(); 945 buf = t.readLine();
946 } 946 }
947 947
948 // other variables like lang & title 948 // other variables like lang & title
949 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { 949 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) {
950 950
951 QTextStream tmp (buf, IO_ReadOnly); 951 QTextStream tmp (buf, IO_ReadOnly);
952 QString name, equals, value; 952 QString name, equals, value;
953 953
954 tmp >> name >> equals >> value; 954 tmp >> name >> equals >> value;
955 955
956 if (name == "lang") { 956 if (name == "lang") {
957 957
958 lang = value; 958 lang = value;
959 959
960 } 960 }
961 961
962 cout << name << " = " << value << "\n"; 962 cout << name << " = " << value << "\n";
963 buf = t.readLine(); 963 buf = t.readLine();
964 } 964 }
965 // comments 965 // comments
966 else if (buf.contains(QRegExp("^\\s*#"))) { 966 else if (buf.contains(QRegExp("^\\s*#"))) {
967 967
968 buf = t.readLine(); 968 buf = t.readLine();
969 969
970 } else { // blank line, or garbage 970 } else { // blank line, or garbage
971 971
972 buf = t.readLine(); 972 buf = t.readLine();
973 973
974 } 974 }
975 975
976 } 976 }
977 f.close(); 977 f.close();
978 } 978 }
979 979
980} 980}
981 981
982// Keys::setKey {{{2 982// Keys::setKey {{{2
983void Keys::setKey(const int row, const int qcode, const ushort unicode, 983void Keys::setKey(const int row, const int qcode, const ushort unicode,
984 const int width, QPixmap *pix) { 984 const int width, QPixmap *pix) {
985 985
986 Key * key; 986 Key * key;
987 key = new Key; 987 key = new Key;
988 key->qcode = qcode; 988 key->qcode = qcode;
989 key->unicode = unicode; 989 key->unicode = unicode;
990 key->width = width; 990 key->width = width;
991 991
992 // share key->pressed between same keys 992 // share key->pressed between same keys
993 bool found = 0; 993 bool found = 0;
994 for (int i = 1; i <= 5; i++) { 994 for (int i = 1; i <= 5; i++) {
995 for (unsigned int j = 0; j < keys[i].count(); j++) 995 for (unsigned int j = 0; j < keys[i].count(); j++)
996 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { 996 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) {
997 997
998 key->pressed = keys[i].at(j)->pressed; 998 key->pressed = keys[i].at(j)->pressed;
999 found = 1; 999 found = 1;
1000 } 1000 }
1001 1001
1002 } 1002 }
1003 if (!found) { 1003 if (!found) {
1004 1004
1005 key->pressed = new bool; 1005 key->pressed = new bool;
1006 *(key->pressed) = 0; 1006 *(key->pressed) = 0;
1007 } 1007 }
1008 1008
1009 key->pix = pix; 1009 key->pix = pix;
1010 1010
1011 1011
1012 keys[row].append(key); 1012 keys[row].append(key);
1013} 1013}
1014// Keys:: other functions {{{2 1014// Keys:: other functions {{{2
1015int Keys::width(const int row, const int col) { 1015int Keys::width(const int row, const int col) {
1016 1016
1017 return keys[row].at(col)->width; 1017 return keys[row].at(col)->width;
1018 1018
1019} 1019}
1020ushort Keys::uni(const int row, const int col) { 1020ushort Keys::uni(const int row, const int col) {
1021 1021
1022 return keys[row].at(col)->unicode; 1022 return keys[row].at(col)->unicode;
1023 1023
1024} 1024}
1025 1025
1026int Keys::qcode(const int row, const int col) { 1026int Keys::qcode(const int row, const int col) {
1027 1027
1028 return keys[row].at(col)->qcode; 1028 return keys[row].at(col)->qcode;
1029} 1029}
1030 1030
1031QPixmap *Keys::pix(const int row, const int col) { 1031QPixmap *Keys::pix(const int row, const int col) {
1032 1032
1033 return keys[row].at(col)->pix; 1033 return keys[row].at(col)->pix;
1034 1034
1035} 1035}
1036bool Keys::pressed(const int row, const int col) { 1036bool Keys::pressed(const int row, const int col) {
1037 1037
1038 return *(keys[row].at(col)->pressed); 1038 return *(keys[row].at(col)->pressed);
1039} 1039}
1040 1040
1041int Keys::numKeys(const int row) { 1041int Keys::numKeys(const int row) {
1042 1042
1043 return keys[row].count(); 1043 return keys[row].count();
1044} 1044}
1045 1045
1046void Keys::setPressed(const int row, const int col, const bool pressed) { 1046void Keys::setPressed(const int row, const int col, const bool pressed) {
1047 1047
1048 *(keys[row].at(col)->pressed) = pressed; 1048 *(keys[row].at(col)->pressed) = pressed;
1049} 1049}
1050 1050
1051ushort Keys::shift(const ushort uni) { 1051ushort Keys::shift(const ushort uni) {
1052 1052
1053 if (shiftMap[uni]) { 1053 if (shiftMap[uni]) {
1054 1054
1055 return shiftMap[uni]; 1055 return shiftMap[uni];
1056 } 1056 }
1057 else 1057 else
1058 return 0; 1058 return 0;
1059 1059
1060} 1060}
1061 1061
1062bool *Keys::pressedPtr(const int row, const int col) { 1062bool *Keys::pressedPtr(const int row, const int col) {
1063 1063
1064 return keys[row].at(col)->pressed; 1064 return keys[row].at(col)->pressed;
1065} 1065}