summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp148
-rw-r--r--inputmethods/multikey/keyboard.h6
2 files changed, 153 insertions, 1 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index 28d5cab..1dd8ca1 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -1,1495 +1,1641 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "keyboard.h" 21#include "keyboard.h"
22#include "configdlg.h" 22#include "configdlg.h"
23 23
24#include <qpe/global.h> 24#include <qpe/global.h>
25#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
26 26
27#include <qwindowsystem_qws.h> 27#include <qwindowsystem_qws.h>
28#include <qpainter.h> 28#include <qpainter.h>
29#include <qfontmetrics.h> 29#include <qfontmetrics.h>
30#include <qtimer.h> 30#include <qtimer.h>
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#include <qpe/config.h> 32#include <qpe/config.h>
33#include <ctype.h> 33#include <ctype.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qstringlist.h> 36#include <qstringlist.h>
37 37
38#include <sys/utsname.h> 38#include <sys/utsname.h>
39 39
40 40
41/* Keyboard::Keyboard {{{1 */ 41/* Keyboard::Keyboard {{{1 */
42Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : 42Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
43 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), 43 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0),
44 meta(0), circumflex(0), diaeresis(0), 44 meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0),
45 useLargeKeys(TRUE), usePicks(0), useRepeat(0), 45 useLargeKeys(TRUE), usePicks(0), useRepeat(0),
46 pressedKeyRow(-1), pressedKeyCol(-1), 46 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 51
52 // get the default font 52 // get the default font
53 Config *config = new Config( "qpe" ); 53 Config *config = new Config( "qpe" );
54 config->setGroup( "Appearance" ); 54 config->setGroup( "Appearance" );
55 QString familyStr = config->readEntry( "FontFamily", "fixed" ); 55 QString familyStr = config->readEntry( "FontFamily", "fixed" );
56 delete config; 56 delete config;
57 57
58 config = new Config("multikey"); 58 config = new Config("multikey");
59 config->setGroup ("general"); 59 config->setGroup ("general");
60 usePicks = config->readBoolEntry ("usePickboard", 0); // default closed 60 usePicks = config->readBoolEntry ("usePickboard", 0); // default closed
61 useRepeat = config->readBoolEntry ("useRepeat", 1); 61 useRepeat = config->readBoolEntry ("useRepeat", 1);
62 delete config; 62 delete config;
63 63
64 64
65 setFont( QFont( familyStr, 10 ) ); 65 setFont( QFont( familyStr, 10 ) );
66 66
67 picks = new KeyboardPicks( this ); 67 picks = new KeyboardPicks( this );
68 picks->setFont( QFont( familyStr, 10 ) ); 68 picks->setFont( QFont( familyStr, 10 ) );
69 picks->initialise(); 69 picks->initialise();
70 if (usePicks) { 70 if (usePicks) {
71 71
72 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 72 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
73 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 73 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
74 74
75 } else picks->hide(); 75 } else picks->hide();
76 76
77 loadKeyboardColors(); 77 loadKeyboardColors();
78 78
79 keys = new Keys(); 79 keys = new Keys();
80 80
81 repeatTimer = new QTimer( this ); 81 repeatTimer = new QTimer( this );
82 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 82 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
83 83
84} 84}
85 85
86Keyboard::~Keyboard() { 86Keyboard::~Keyboard() {
87 87
88 if ( configdlg ) { 88 if ( configdlg ) {
89 delete (ConfigDlg *) configdlg; 89 delete (ConfigDlg *) configdlg;
90 configdlg = 0; 90 configdlg = 0;
91 } 91 }
92 92
93} 93}
94 94
95/* Keyboard::resizeEvent {{{1 */ 95/* Keyboard::resizeEvent {{{1 */
96void Keyboard::resizeEvent(QResizeEvent*) 96void Keyboard::resizeEvent(QResizeEvent*)
97{ 97{
98 int ph = picks->sizeHint().height(); 98 int ph = picks->sizeHint().height();
99 picks->setGeometry( 0, 0, width(), ph ); 99 picks->setGeometry( 0, 0, width(), ph );
100 keyHeight = (height()-(usePicks ? ph : 0))/keys->rows(); 100 keyHeight = (height()-(usePicks ? ph : 0))/keys->rows();
101 101
102 int nk; // number of keys? 102 int nk; // number of keys?
103 if ( useLargeKeys ) { 103 if ( useLargeKeys ) {
104 nk = 15; 104 nk = 15;
105 } else { 105 } else {
106 nk = 19; 106 nk = 19;
107 } 107 }
108 defaultKeyWidth = (width()/nk)/2; 108 defaultKeyWidth = (width()/nk)/2;
109 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? 109 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
110 110
111} 111}
112 112
113/* KeyboardPicks::initialize {{{1 */ 113/* KeyboardPicks::initialize {{{1 */
114void KeyboardPicks::initialise() 114void KeyboardPicks::initialise()
115{ 115{
116 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 116 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
117 mode = 0; 117 mode = 0;
118 dc = new KeyboardConfig(this); 118 dc = new KeyboardConfig(this);
119 configs.append(dc); 119 configs.append(dc);
120} 120}
121 121
122/* KeyboardPicks::sizeHint {{{1 */ 122/* KeyboardPicks::sizeHint {{{1 */
123QSize KeyboardPicks::sizeHint() const 123QSize KeyboardPicks::sizeHint() const
124{ 124{
125 return QSize(240,fontMetrics().lineSpacing()); 125 return QSize(240,fontMetrics().lineSpacing());
126} 126}
127 127
128 128
129/* KeyboardConfig::generateText {{{1 */ 129/* KeyboardConfig::generateText {{{1 */
130void KeyboardConfig::generateText(const QString &s) 130void KeyboardConfig::generateText(const QString &s)
131{ 131{
132#if defined(Q_WS_QWS) || defined(_WS_QWS_) 132#if defined(Q_WS_QWS) || defined(_WS_QWS_)
133 for (int i=0; i<(int)backspaces; i++) { 133 for (int i=0; i<(int)backspaces; i++) {
134 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); 134 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );
135 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); 135 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );
136 } 136 }
137 for (int i=0; i<(int)s.length(); i++) { 137 for (int i=0; i<(int)s.length(); i++) {
138 parent->emitKey( s[i].unicode(), 0, 0, true, false ); 138 parent->emitKey( s[i].unicode(), 0, 0, true, false );
139 parent->emitKey( s[i].unicode(), 0, 0, false, false ); 139 parent->emitKey( s[i].unicode(), 0, 0, false, false );
140 } 140 }
141 parent->emitKey( 0, Qt::Key_Space, 0, true, false ); 141 parent->emitKey( 0, Qt::Key_Space, 0, true, false );
142 parent->emitKey( 0, Qt::Key_Space, 0, false, false ); 142 parent->emitKey( 0, Qt::Key_Space, 0, false, false );
143 backspaces = 0; 143 backspaces = 0;
144#endif 144#endif
145} 145}
146 146
147 147
148 148
149 149
150/* Keyboard::paintEvent {{{1 */ 150/* Keyboard::paintEvent {{{1 */
151void Keyboard::paintEvent(QPaintEvent* e) 151void Keyboard::paintEvent(QPaintEvent* e)
152{ 152{
153 QPainter painter(this); 153 QPainter painter(this);
154 painter.setClipRect(e->rect()); 154 painter.setClipRect(e->rect());
155 drawKeyboard( painter ); 155 drawKeyboard( painter );
156 picks->dc->draw( &painter ); 156 picks->dc->draw( &painter );
157} 157}
158 158
159 159
160/* Keyboard::drawKeyboard {{{1 */ 160/* Keyboard::drawKeyboard {{{1 */
161 161
162void Keyboard::drawKeyboard(QPainter &p, int row, int col) 162void Keyboard::drawKeyboard(QPainter &p, int row, int col)
163{ 163{
164 164
165 165
166 if (row != -1 && col != -1) { //just redraw one key 166 if (row != -1 && col != -1) { //just redraw one key
167 167
168 int x = 0; 168 int x = 0;
169 for (int i = 0; i < col; i++) { 169 for (int i = 0; i < col; i++) {
170 170
171 x += keys->width(row, i) * defaultKeyWidth; 171 x += keys->width(row, i) * defaultKeyWidth;
172 } 172 }
173 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 173 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
174 174
175 int keyWidth = keys->width(row, col); 175 int keyWidth = keys->width(row, col);
176 176
177 p.fillRect(x + 1, y + 1, 177 p.fillRect(x + 1, y + 1,
178 keyWidth * defaultKeyWidth - 1, keyHeight - 1, 178 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
179 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); 179 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor);
180 180
181 QImage *pix = keys->pix(row,col); 181 QImage *pix = keys->pix(row,col);
182 182
183 ushort c = keys->uni(row, col); 183 ushort c = keys->uni(row, col);
184 184
185 p.setPen(textcolor); 185 p.setPen(textcolor);
186 if (!pix) { 186 if (!pix) {
187 if ((shift || lock) && keys->shift(c)) 187 if ((shift || lock) && keys->shift(c))
188 188
189 if (circumflex && keys->circumflex(keys->shift(c))) 189 if (circumflex && keys->circumflex(keys->shift(c)))
190 c = keys->circumflex(keys->shift(c)); 190 c = keys->circumflex(keys->shift(c));
191 else if (diaeresis && keys->diaeresis(keys->shift(c))) 191 else if (diaeresis && keys->diaeresis(keys->shift(c)))
192 c = keys->diaeresis(keys->shift(c)); 192 c = keys->diaeresis(keys->shift(c));
193 else if (baccent && keys->baccent(keys->shift(c)))
194 c = keys->baccent(keys->shift(c));
195 else if (accent && keys->accent(keys->shift(c)))
196 c = keys->accent(keys->shift(c));
193 else if (meta && keys->meta(keys->shift(c))) 197 else if (meta && keys->meta(keys->shift(c)))
194 c = keys->meta(keys->shift(c)); 198 c = keys->meta(keys->shift(c));
195 else 199 else
196 c = keys->shift(c); 200 c = keys->shift(c);
197 201
198 else if (meta && keys->meta(c)) 202 else if (meta && keys->meta(c))
199 c = keys->meta(c); 203 c = keys->meta(c);
200 else if (circumflex && keys->circumflex(c)) 204 else if (circumflex && keys->circumflex(c))
201 c = keys->circumflex(c); 205 c = keys->circumflex(c);
206 else if (baccent && keys->baccent(c))
207 c = keys->baccent(c);
208 else if (accent && keys->accent(c))
209 c = keys->accent(c);
202 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { 210 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) {
203 211
204 // the diaeresis key itself has to be in the diaeresisMap, 212 // the diaeresis key itself has to be in the diaeresisMap,
205 // or just do this to make it display the diaeresis char. 213 // or just do this to make it display the diaeresis char.
206 214
207 if (c == 0x2c6) 215 if (c == 0x2c6)
208 c = 0xa8; 216 c = 0xa8;
209 else 217 else
210 c = keys->diaeresis(c); 218 c = keys->diaeresis(c);
211 } 219 }
212 220
213 p.drawText(x, y, 221 p.drawText(x, y,
214 defaultKeyWidth * keyWidth + 3, keyHeight, 222 defaultKeyWidth * keyWidth + 3, keyHeight,
215 AlignCenter, (QChar)c); 223 AlignCenter, (QChar)c);
216 } 224 }
217 else 225 else
218 // center the image in the middle of the key 226 // center the image in the middle of the key
219 p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1, 227 p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1,
220 y + (keyHeight - pix->height())/2 + 1, 228 y + (keyHeight - pix->height())/2 + 1,
221 *pix ); 229 *pix );
222 230
223 // this fixes the problem that the very right end of the board's vertical line 231 // this fixes the problem that the very right end of the board's vertical line
224 // gets painted over, because it's one pixel shorter than all other keys 232 // gets painted over, because it's one pixel shorter than all other keys
225 p.setPen(keycolor_lines); 233 p.setPen(keycolor_lines);
226 p.drawLine(width() - 1, 0, width() - 1, height()); 234 p.drawLine(width() - 1, 0, width() - 1, height());
227 235
228 } else { 236 } else {
229 237
230 238
231 p.fillRect(0, 0, width(), height(), keycolor); 239 p.fillRect(0, 0, width(), height(), keycolor);
232 240
233 for (row = 1; row <= keys->rows(); row++) { 241 for (row = 1; row <= keys->rows(); row++) {
234 242
235 int x = 0; 243 int x = 0;
236 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 244 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
237 245
238 p.setPen(keycolor_lines); 246 p.setPen(keycolor_lines);
239 p.drawLine(x, y, x + width(), y); 247 p.drawLine(x, y, x + width(), y);
240 248
241 for (int col = 0; col < keys->numKeys(row); col++) { 249 for (int col = 0; col < keys->numKeys(row); col++) {
242 250
243 QImage *pix = keys->pix(row, col); 251 QImage *pix = keys->pix(row, col);
244 int keyWidth = keys->width(row, col); 252 int keyWidth = keys->width(row, col);
245 253
246 254
247 int keyWidthPix = defaultKeyWidth * keyWidth; 255 int keyWidthPix = defaultKeyWidth * keyWidth;
248 256
249 if (keys->pressed(row, col)) 257 if (keys->pressed(row, col))
250 p.fillRect(x+1, y+1, keyWidthPix - 1, 258 p.fillRect(x+1, y+1, keyWidthPix - 1,
251 keyHeight - 1, keycolor_pressed); 259 keyHeight - 1, keycolor_pressed);
252 260
253 ushort c = keys->uni(row, col); 261 ushort c = keys->uni(row, col);
254 262
255 p.setPen(textcolor); 263 p.setPen(textcolor);
256 if (!pix) { 264 if (!pix) {
257 if ((shift || lock) && keys->shift(c)) 265 if ((shift || lock) && keys->shift(c))
258 266
259 if (circumflex && keys->circumflex(keys->shift(c))) 267 if (circumflex && keys->circumflex(keys->shift(c)))
260 c = keys->circumflex(keys->shift(c)); 268 c = keys->circumflex(keys->shift(c));
261 else if (diaeresis && keys->diaeresis(keys->shift(c))) 269 else if (diaeresis && keys->diaeresis(keys->shift(c)))
262 c = keys->diaeresis(keys->shift(c)); 270 c = keys->diaeresis(keys->shift(c));
271 else if (baccent && keys->baccent(keys->shift(c)))
272 c = keys->baccent(keys->shift(c));
273 else if (accent && keys->accent(keys->shift(c)))
274 c = keys->accent(keys->shift(c));
263 else if (meta && keys->meta(keys->shift(c))) 275 else if (meta && keys->meta(keys->shift(c)))
264 c = keys->meta(keys->shift(c)); 276 c = keys->meta(keys->shift(c));
265 else 277 else
266 c = keys->shift(c); 278 c = keys->shift(c);
267 279
268 else if (meta && keys->meta(c)) 280 else if (meta && keys->meta(c))
269 c = keys->meta(c); 281 c = keys->meta(c);
270 else if (circumflex && keys->circumflex(c)) 282 else if (circumflex && keys->circumflex(c))
271 c = keys->circumflex(c); 283 c = keys->circumflex(c);
284 else if (baccent && keys->baccent(c))
285 c = keys->baccent(c);
286 else if (accent && keys->accent(c))
287 c = keys->accent(c);
272 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { 288 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) {
273 289
274 if (c == 0x2c6) 290 if (c == 0x2c6)
275 c = 0xa8; 291 c = 0xa8;
276 else 292 else
277 c = keys->diaeresis(c); 293 c = keys->diaeresis(c);
278 } 294 }
279 295
280 p.drawText(x, y, 296 p.drawText(x, y,
281 keyWidthPix + 3, keyHeight, 297 keyWidthPix + 3, keyHeight,
282 AlignCenter, (QChar)c); 298 AlignCenter, (QChar)c);
283 } 299 }
284 else { 300 else {
285 // center the image in the middle of the key 301 // center the image in the middle of the key
286 pix->setColor(1, textcolor.rgb()); 302 pix->setColor(1, textcolor.rgb());
287 p.drawImage( x + (keyWidthPix - pix->width())/2 + 1, 303 p.drawImage( x + (keyWidthPix - pix->width())/2 + 1,
288 y + (keyHeight - pix->height())/2 + 1, 304 y + (keyHeight - pix->height())/2 + 1,
289 QImage(*pix) ); 305 QImage(*pix) );
290 } 306 }
291 307
292 p.setPen(keycolor_lines); 308 p.setPen(keycolor_lines);
293 p.drawLine(x, y, x, y + keyHeight); 309 p.drawLine(x, y, x, y + keyHeight);
294 310
295 x += keyWidthPix; 311 x += keyWidthPix;
296 } 312 }
297 313
298 314
299 } 315 }
300 p.setPen(keycolor_lines); 316 p.setPen(keycolor_lines);
301 p.drawLine(0, height() - 1, width(), height() - 1); 317 p.drawLine(0, height() - 1, width(), height() - 1);
302 p.drawLine(width() - 1, 0, width() - 1, height()); 318 p.drawLine(width() - 1, 0, width() - 1, height());
303 } 319 }
304 320
305} 321}
306 322
307 323
308/* Keyboard::mousePressEvent {{{1 */ 324/* Keyboard::mousePressEvent {{{1 */
309void Keyboard::mousePressEvent(QMouseEvent *e) 325void Keyboard::mousePressEvent(QMouseEvent *e)
310{ 326{
311 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; 327 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
312 if (row > 5) row = 5; 328 if (row > 5) row = 5;
313 329
314 // figure out the column 330 // figure out the column
315 int col = 0; 331 int col = 0;
316 for (int w = 0; e->x() >= w; col++) 332 for (int w = 0; e->x() >= w; col++)
317 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys 333 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys
318 w += keys->width(row,col) * defaultKeyWidth; 334 w += keys->width(row,col) * defaultKeyWidth;
319 else break; 335 else break;
320 336
321 if (col <= 0) return; 337 if (col <= 0) return;
322 338
323 col --; // rewind one... 339 col --; // rewind one...
324 340
325 qkeycode = keys->qcode(row, col); 341 qkeycode = keys->qcode(row, col);
326 unicode = keys->uni(row, col); 342 unicode = keys->uni(row, col);
327 343
328 // might need to repaint if two or more of the same keys. 344 // might need to repaint if two or more of the same keys.
329 // should be faster if just paint one key even though multiple keys exist. 345 // should be faster if just paint one key even though multiple keys exist.
330 bool need_repaint = FALSE; 346 bool need_repaint = FALSE;
331 347
332 // circumflex and diaeresis support 348 // circumflex and diaeresis support
333 // messy to have this here, but too hard to implement any other method 349 // messy to have this here, but too hard to implement any other method
334 if (unicode == 0x2c6) { 350 if (unicode == 0x2c6) {
335 351
336 unicode = 0; 352 unicode = 0;
337 if (shift || lock) { 353 if (shift || lock) {
338 354
339 // diaeresis 355 // diaeresis
340 qkeycode = 0x2001; 356 qkeycode = 0x2001;
341 } 357 }
342 else { 358 else {
343 359
344 // circumflex 360 // circumflex
345 qkeycode = 0x2000; 361 qkeycode = 0x2000;
346 } 362 }
347 } 363 }
348 364
365 // Back accent character support
366
367 if (unicode == 0x60) {
368
369 unicode = 0;
370 if (shift || lock) {
371
372 // circumblex
373 qkeycode = 0x2000;
374 }
375 else {
376
377 // back accent
378 qkeycode = 0x2002;
379 }
380 }
381
382 // Accent character support
383
384 if (unicode == 0xb4) {
385
386 unicode = 0;
387 if (shift || lock) {
388
389 // diaeresis
390 qkeycode = 0x2001;
391 }
392 else {
393
394 // accent
395 qkeycode = 0x2003;
396 }
397 }
398
399
349 if (unicode == 0) { // either Qt char, or nothing 400 if (unicode == 0) { // either Qt char, or nothing
350 401
351 if (qkeycode == Qt::Key_F1) { // toggle the pickboard 402 if (qkeycode == Qt::Key_F1) { // toggle the pickboard
352 403
353 if ( configdlg ) { 404 if ( configdlg ) {
354 405
355 delete (ConfigDlg *) configdlg; 406 delete (ConfigDlg *) configdlg;
356 configdlg = 0; 407 configdlg = 0;
357 } 408 }
358 else { 409 else {
359 configdlg = new ConfigDlg (); 410 configdlg = new ConfigDlg ();
360 connect(configdlg, SIGNAL(setMapToDefault()), 411 connect(configdlg, SIGNAL(setMapToDefault()),
361 this, SLOT(setMapToDefault())); 412 this, SLOT(setMapToDefault()));
362 connect(configdlg, SIGNAL(setMapToFile(QString)), 413 connect(configdlg, SIGNAL(setMapToFile(QString)),
363 this, SLOT(setMapToFile(QString))); 414 this, SLOT(setMapToFile(QString)));
364 connect(configdlg, SIGNAL(pickboardToggled(bool)), 415 connect(configdlg, SIGNAL(pickboardToggled(bool)),
365 this, SLOT(togglePickboard(bool))); 416 this, SLOT(togglePickboard(bool)));
366 connect(configdlg, SIGNAL(repeatToggled(bool)), 417 connect(configdlg, SIGNAL(repeatToggled(bool)),
367 this, SLOT(toggleRepeat(bool))); 418 this, SLOT(toggleRepeat(bool)));
368 connect(configdlg, SIGNAL(reloadKeyboard()), 419 connect(configdlg, SIGNAL(reloadKeyboard()),
369 this, SLOT(reloadKeyboard())); 420 this, SLOT(reloadKeyboard()));
370 connect(configdlg, SIGNAL(configDlgClosed()), 421 connect(configdlg, SIGNAL(configDlgClosed()),
371 this, SLOT(cleanupConfigDlg())); 422 this, SLOT(cleanupConfigDlg()));
372 configdlg->showMaximized(); 423 configdlg->showMaximized();
373 configdlg->show(); 424 configdlg->show();
374 configdlg->raise(); 425 configdlg->raise();
375 } 426 }
376 427
377 } else if (qkeycode == Qt::Key_Control) { 428 } else if (qkeycode == Qt::Key_Control) {
378 need_repaint = TRUE; 429 need_repaint = TRUE;
379 430
380 if (ctrl) { 431 if (ctrl) {
381 432
382 *ctrl = 0; 433 *ctrl = 0;
383 ctrl = 0; 434 ctrl = 0;
384 435
385 } else { 436 } else {
386 437
387 ctrl = keys->pressedPtr(row, col); 438 ctrl = keys->pressedPtr(row, col);
388 need_repaint = TRUE; 439 need_repaint = TRUE;
389 *ctrl = !keys->pressed(row, col); 440 *ctrl = !keys->pressed(row, col);
390 441
391 } 442 }
392 443
393 } else if (qkeycode == Qt::Key_Alt) { 444 } else if (qkeycode == Qt::Key_Alt) {
394 need_repaint = TRUE; 445 need_repaint = TRUE;
395 446
396 if (alt) { 447 if (alt) {
397 *alt = 0; 448 *alt = 0;
398 alt = 0; 449 alt = 0;
399 450
400 } else { 451 } else {
401 452
402 alt = keys->pressedPtr(row, col); 453 alt = keys->pressedPtr(row, col);
403 need_repaint = TRUE; 454 need_repaint = TRUE;
404 *alt = !keys->pressed(row, col); 455 *alt = !keys->pressed(row, col);
405 } 456 }
406 457
407 } else if (qkeycode == Qt::Key_Shift) { 458 } else if (qkeycode == Qt::Key_Shift) {
408 need_repaint = TRUE; 459 need_repaint = TRUE;
409 460
410 if (shift) { 461 if (shift) {
411 *shift = 0; 462 *shift = 0;
412 shift = 0; 463 shift = 0;
413 } 464 }
414 else { 465 else {
415 shift = keys->pressedPtr(row, col); 466 shift = keys->pressedPtr(row, col);
416 *shift = 1; 467 *shift = 1;
417 if (lock) { 468 if (lock) {
418 *lock = 0; 469 *lock = 0;
419 lock = 0; 470 lock = 0;
420 } 471 }
421 } 472 }
422 473
423 474
424 /* 475 /*
425 * want to be able to hit circumflex/diaeresis -> shift 476 * want to be able to hit circumflex/diaeresis -> shift
426 * to type in shifted circumflex/diaeresis chars. 477 * to type in shifted circumflex/diaeresis chars.
427 * same thing with meta 478 * same thing with meta
428 479
429 if (meta) { *meta = 0; meta = 0; } 480 if (meta) { *meta = 0; meta = 0; }
430 if (circumflex) { *circumflex = 0; circumflex = 0; } 481 if (circumflex) { *circumflex = 0; circumflex = 0; }
431 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 482 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
432 483
433 */ 484 */
434 485
435 } else if (qkeycode == Qt::Key_CapsLock) { 486 } else if (qkeycode == Qt::Key_CapsLock) {
436 need_repaint = TRUE; 487 need_repaint = TRUE;
437 488
438 if (lock) { 489 if (lock) {
439 *lock = 0; 490 *lock = 0;
440 lock = 0; 491 lock = 0;
441 } 492 }
442 else { 493 else {
443 lock = keys->pressedPtr(row, col);; 494 lock = keys->pressedPtr(row, col);;
444 *lock = true;; 495 *lock = true;;
445 if (shift) { 496 if (shift) {
446 *shift = 0; 497 *shift = 0;
447 shift = 0; 498 shift = 0;
448 } 499 }
449 } 500 }
450 501
451 /* 502 /*
452 if (meta) { *meta = 0; meta = 0; } 503 if (meta) { *meta = 0; meta = 0; }
453 if (circumflex) { *circumflex = 0; circumflex = 0; } 504 if (circumflex) { *circumflex = 0; circumflex = 0; }
454 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 505 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
455 */ 506 */
456 507
457 } else if (qkeycode == Qt::Key_Meta) { 508 } else if (qkeycode == Qt::Key_Meta) {
458 need_repaint = TRUE; 509 need_repaint = TRUE;
459 510
460 if (meta) { 511 if (meta) {
461 *meta = 0; 512 *meta = 0;
462 meta = 0; 513 meta = 0;
463 514
464 } else { 515 } else {
465 516
466 meta = keys->pressedPtr(row, col); 517 meta = keys->pressedPtr(row, col);
467 *meta = true; 518 *meta = true;
468 } 519 }
469 520
470 // reset all the other keys 521 // reset all the other keys
471 if (shift) { *shift = 0; shift = 0; } 522 if (shift) { *shift = 0; shift = 0; }
472 if (lock) { *lock = 0; lock = 0; } 523 if (lock) { *lock = 0; lock = 0; }
473 if (circumflex) { *circumflex = 0; circumflex = 0; } 524 if (circumflex) { *circumflex = 0; circumflex = 0; }
474 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 525 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
526 if (baccent) { *baccent = 0; baccent = 0; }
527 if (accent) { *accent = 0; accent = 0; }
475 528
476 // dont need to emit this key... acts same as alt 529 // dont need to emit this key... acts same as alt
477 qkeycode = 0; 530 qkeycode = 0;
478 531
479 // circumflex 532 // circumflex
480 } else if (qkeycode == 0x2000) { 533 } else if (qkeycode == 0x2000) {
481 need_repaint = TRUE; 534 need_repaint = TRUE;
482 535
483 if (circumflex) { 536 if (circumflex) {
484 537
485 *circumflex = 0; 538 *circumflex = 0;
486 circumflex = 0; 539 circumflex = 0;
487 540
488 } else { 541 } else {
489 542
490 circumflex = keys->pressedPtr(row, col); 543 circumflex = keys->pressedPtr(row, col);
491 *circumflex = true; 544 *circumflex = true;
492 } 545 }
493 546
494 /* no need to turn off shift or lock if circumflex 547 /* no need to turn off shift or lock if circumflex
495 * keys are pressed 548 * keys are pressed
496 549
497 if (shift) { *shift = 0; shift = 0; } 550 if (shift) { *shift = 0; shift = 0; }
498 if (lock) { *lock = 0; lock = 0; } 551 if (lock) { *lock = 0; lock = 0; }
499 552
500 */ 553 */
501 554
502 // have to reset all the other keys 555 // have to reset all the other keys
503 if (meta) { *meta = 0; meta = 0; } 556 if (meta) { *meta = 0; meta = 0; }
504 if (diaeresis) { 557 if (diaeresis) {
505 558
506 // *diaeresis and *circumflex point to the same thing 559 // *diaeresis and *circumflex point to the same thing
507 // when diaeresis is enabled and you hit the circumflex 560 // when diaeresis is enabled and you hit the circumflex
508 // since they are the same key, it should turn off the 561 // since they are the same key, it should turn off the
509 // key 562 // key
510 563
511 *diaeresis = 0; 564 *diaeresis = 0;
512 diaeresis = 0; 565 diaeresis = 0;
513 circumflex = 0; 566 circumflex = 0;
514 } 567 }
515 568
516 qkeycode = 0; 569 qkeycode = 0;
517 570
518 // diaeresis 571 // diaeresis
519 } else if (qkeycode == 0x2001) { 572 } else if (qkeycode == 0x2001) {
520 need_repaint = TRUE; 573 need_repaint = TRUE;
521 574
522 if (diaeresis) { 575 if (diaeresis) {
523 576
524 *diaeresis = 0; 577 *diaeresis = 0;
525 diaeresis = 0; 578 diaeresis = 0;
526 579
527 } else { 580 } else {
528 581
529 diaeresis = keys->pressedPtr(row, col); 582 diaeresis = keys->pressedPtr(row, col);
530 *diaeresis = true; 583 *diaeresis = true;
531 } 584 }
532 585
533 586
534 if (shift) { *shift = 0; shift = 0; } 587 if (shift) { *shift = 0; shift = 0; }
535 588
536 /* 589 /*
537 * 590 *
538 if (lock) { *lock = 0; lock = 0; } 591 if (lock) { *lock = 0; lock = 0; }
539 * 592 *
540 */ 593 */
541 594
542 if (meta) { *meta = 0; meta = 0; } 595 if (meta) { *meta = 0; meta = 0; }
543 if (circumflex) { 596 if (circumflex) {
544 597
545 // *circumflex = 0; 598 // *circumflex = 0;
546 // 599 //
547 // same thing the diaeresis pointer points too 600 // same thing the diaeresis pointer points too
548 601
549 circumflex = 0; 602 circumflex = 0;
550 } 603 }
551 604
552 605
553 qkeycode = 0; 606 qkeycode = 0;
607
608 // Back accent
609 } else if (qkeycode == 0x2002) {
610 need_repaint = TRUE;
611
612 if (baccent) {
613
614 *baccent = 0;
615 baccent = 0;
616
617 } else {
618
619 baccent = keys->pressedPtr(row, col);
620 *baccent = true;
621 }
622
623
624 if (shift) { *shift = 0; shift = 0; }
625 if (meta) { *meta = 0; meta = 0; }
626 if (accent) { *accent = 0; accent = 0; }
627
628 qkeycode = 0;
629
630 // Accent
631 } else if (qkeycode == 0x2003) {
632 need_repaint = TRUE;
633
634 if (accent) {
635
636 *accent = 0;
637 accent = 0;
638
639 } else {
640
641 accent = keys->pressedPtr(row, col);
642 *accent = true;
643 }
644
645
646 if (shift) { *shift = 0; shift = 0; }
647 if (meta) { *meta = 0; meta = 0; }
648 if (baccent) { *baccent = 0; }
649
650 qkeycode = 0;
554 } 651 }
555 652
556 } 653 }
557 else { // normal char 654 else { // normal char
558 if ((shift || lock) && keys->shift(unicode)) { 655 if ((shift || lock) && keys->shift(unicode)) {
559 656
560 // make diaeresis/circumflex -> shift input shifted 657 // make diaeresis/circumflex -> shift input shifted
561 // diaeresis/circumflex chars 658 // diaeresis/circumflex chars
562 659
563 if (circumflex && keys->circumflex(keys->shift(unicode))) 660 if (circumflex && keys->circumflex(keys->shift(unicode)))
564 unicode = keys->circumflex(keys->shift(unicode)); 661 unicode = keys->circumflex(keys->shift(unicode));
565 else if (diaeresis && keys->diaeresis(keys->shift(unicode))) 662 else if (diaeresis && keys->diaeresis(keys->shift(unicode)))
566 unicode = keys->diaeresis(keys->shift(unicode)); 663 unicode = keys->diaeresis(keys->shift(unicode));
664 else if (baccent && keys->baccent(keys->shift(unicode)))
665 unicode = keys->baccent(keys->shift(unicode));
666 else if (accent && keys->accent(keys->shift(unicode)))
667 unicode = keys->accent(keys->shift(unicode));
567 else if (meta && keys->meta(keys->shift(unicode))) 668 else if (meta && keys->meta(keys->shift(unicode)))
568 unicode = keys->meta(keys->shift(unicode)); 669 unicode = keys->meta(keys->shift(unicode));
569 else 670 else
570 unicode = keys->shift(unicode); 671 unicode = keys->shift(unicode);
571 } 672 }
572 else if (meta && keys->meta(unicode)) { 673 else if (meta && keys->meta(unicode)) {
573 unicode = keys->meta(unicode); 674 unicode = keys->meta(unicode);
574 } 675 }
575 else if (circumflex && keys->circumflex(unicode)) { 676 else if (circumflex && keys->circumflex(unicode)) {
576 unicode = keys->circumflex(unicode); 677 unicode = keys->circumflex(unicode);
577 } 678 }
578 else if (diaeresis && keys->diaeresis(unicode)) { 679 else if (diaeresis && keys->diaeresis(unicode)) {
579 680
580 unicode = keys->diaeresis(unicode); 681 unicode = keys->diaeresis(unicode);
581 } 682 }
683 else if (baccent && keys->baccent(unicode)) {
684 unicode = keys->baccent(unicode);
685 }
686 else if (accent && keys->accent(unicode)) {
687 unicode = keys->accent(unicode);
688 }
582 } 689 }
583 690
584 // korean parsing 691 // korean parsing
585 if (keys->lang == "ko") { 692 if (keys->lang == "ko") {
586 693
587 unicode = parseKoreanInput(unicode); 694 unicode = parseKoreanInput(unicode);
588 } 695 }
589 696
590 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); 697 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
591 698
592 if ('A' <= unicode && unicode <= 'z' && modifiers) { 699 if ('A' <= unicode && unicode <= 'z' && modifiers) {
593 700
594 qkeycode = QChar(unicode).upper(); 701 qkeycode = QChar(unicode).upper();
595 unicode = qkeycode - '@'; 702 unicode = qkeycode - '@';
596 } 703 }
597 704
598 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); 705 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false);
599 706
600 // pickboard stuff 707 // pickboard stuff
601 if (usePicks) { 708 if (usePicks) {
602 709
603 KeyboardConfig *dc = picks->dc; 710 KeyboardConfig *dc = picks->dc;
604 711
605 if (dc) { 712 if (dc) {
606 if (qkeycode == Qt::Key_Backspace) { 713 if (qkeycode == Qt::Key_Backspace) {
607 dc->input.remove(dc->input.last()); // remove last input 714 dc->input.remove(dc->input.last()); // remove last input
608 dc->decBackspaces(); 715 dc->decBackspaces();
609 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { 716 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) {
610 dc->input.clear(); 717 dc->input.clear();
611 dc->resetBackspaces(); 718 dc->resetBackspaces();
612 } else { 719 } else {
613 dc->add(QString(QChar(unicode))); 720 dc->add(QString(QChar(unicode)));
614 dc->incBackspaces(); 721 dc->incBackspaces();
615 } 722 }
616 } 723 }
617 picks->repaint(); 724 picks->repaint();
618 } 725 }
619 726
620 727
621 // painting 728 // painting
622 pressed = TRUE; 729 pressed = TRUE;
623 730
624 pressedKeyRow = row; 731 pressedKeyRow = row;
625 pressedKeyCol = col; 732 pressedKeyCol = col;
626 733
627 if (need_repaint) repaint(FALSE); 734 if (need_repaint) repaint(FALSE);
628 else { // just paint the one key pressed 735 else { // just paint the one key pressed
629 736
630 737
631 738
632 QPainter p(this); 739 QPainter p(this);
633 drawKeyboard(p, row, col); 740 drawKeyboard(p, row, col);
634 741
635 } 742 }
636 743
637 if (useRepeat) repeatTimer->start( 800 ); 744 if (useRepeat) repeatTimer->start( 800 );
638 //pressTid = startTimer(80); 745 //pressTid = startTimer(80);
639 746
640} 747}
641 748
642 749
643/* Keyboard::mouseReleaseEvent {{{1 */ 750/* Keyboard::mouseReleaseEvent {{{1 */
644void Keyboard::mouseReleaseEvent(QMouseEvent*) 751void Keyboard::mouseReleaseEvent(QMouseEvent*)
645{ 752{
646 pressed = FALSE; 753 pressed = FALSE;
647 //if ( pressTid == 0 ) 754 //if ( pressTid == 0 )
648#if defined(Q_WS_QWS) || defined(_WS_QWS_) 755#if defined(Q_WS_QWS) || defined(_WS_QWS_)
649 if ( unicode != -1 ) { 756 if ( unicode != -1 ) {
650 emit key( unicode, qkeycode, modifiers, false, false ); 757 emit key( unicode, qkeycode, modifiers, false, false );
651 repeatTimer->stop(); 758 repeatTimer->stop();
652 } 759 }
653#endif 760#endif
654 if (shift && unicode != 0) { 761 if (shift && unicode != 0) {
655 762
656 763
657 *shift = 0; // unpress shift key 764 *shift = 0; // unpress shift key
658 shift = 0; // reset the shift pointer 765 shift = 0; // reset the shift pointer
659 repaint(FALSE); 766 repaint(FALSE);
660 767
661 } 768 }
662 769
663 /* 770 /*
664 * do not make the meta key release after being pressed 771 * do not make the meta key release after being pressed
665 * 772 *
666 773
667 else if (meta && unicode != 0) { 774 else if (meta && unicode != 0) {
668 775
669 *meta = 0; 776 *meta = 0;
670 meta = 0; 777 meta = 0;
671 repaint(FALSE); 778 repaint(FALSE);
672 } 779 }
673 780
674 */ 781 */
675 782
676 else clearHighlight(); 783 else clearHighlight();
677} 784}
678 785
679/* Keyboard::timerEvent {{{1 */ 786/* Keyboard::timerEvent {{{1 */
680 787
681/* dont know what this does, but i think it is here so that if your screen 788/* dont know what this does, but i think it is here so that if your screen
682 * sticks (like on an ipaq) then it will stop repeating if you click another 789 * sticks (like on an ipaq) then it will stop repeating if you click another
683 * key... but who knows what anything does in this thing anyway? 790 * key... but who knows what anything does in this thing anyway?
684 791
685 void Keyboard::timerEvent(QTimerEvent* e) 792 void Keyboard::timerEvent(QTimerEvent* e)
686{ 793{
687 if ( e->timerId() == pressTid ) { 794 if ( e->timerId() == pressTid ) {
688 killTimer(pressTid); 795 killTimer(pressTid);
689 pressTid = 0; 796 pressTid = 0;
690 if ( !pressed ) 797 if ( !pressed )
691 cout << "calling clearHighlight from timerEvent\n"; 798 cout << "calling clearHighlight from timerEvent\n";
692 //clearHighlight(); 799 //clearHighlight();
693 } 800 }
694} 801}
695*/ 802*/
696 803
697void Keyboard::repeat() 804void Keyboard::repeat()
698{ 805{
699 806
700 repeatTimer->start( 200 ); 807 repeatTimer->start( 200 );
701 emit key( unicode, qkeycode, modifiers, true, true ); 808 emit key( unicode, qkeycode, modifiers, true, true );
702} 809}
703 810
704void Keyboard::clearHighlight() 811void Keyboard::clearHighlight()
705{ 812{
706 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { 813 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) {
707 int tmpRow = pressedKeyRow; 814 int tmpRow = pressedKeyRow;
708 int tmpCol = pressedKeyCol; 815 int tmpCol = pressedKeyCol;
709 816
710 pressedKeyRow = -1; 817 pressedKeyRow = -1;
711 pressedKeyCol = -1; 818 pressedKeyCol = -1;
712 819
713 QPainter p(this); 820 QPainter p(this);
714 drawKeyboard(p, tmpRow, tmpCol); 821 drawKeyboard(p, tmpRow, tmpCol);
715 } 822 }
716} 823}
717 824
718 825
719/* Keyboard::sizeHint {{{1 */ 826/* Keyboard::sizeHint {{{1 */
720QSize Keyboard::sizeHint() const 827QSize Keyboard::sizeHint() const
721{ 828{
722 QFontMetrics fm=fontMetrics(); 829 QFontMetrics fm=fontMetrics();
723 int keyHeight = fm.lineSpacing() + 2; 830 int keyHeight = fm.lineSpacing() + 2;
724 831
725 return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1); 832 return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1);
726} 833}
727 834
728 835
729void Keyboard::resetState() 836void Keyboard::resetState()
730{ 837{
731 if (shift) { *shift = 0; shift = 0; } 838 if (shift) { *shift = 0; shift = 0; }
732 if (lock) {*lock = 0; lock = 0; } 839 if (lock) {*lock = 0; lock = 0; }
733 if (meta) { *meta = 0; meta = 0; } 840 if (meta) { *meta = 0; meta = 0; }
734 if (circumflex) { *circumflex = 0; circumflex = 0; } 841 if (circumflex) { *circumflex = 0; circumflex = 0; }
735 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 842 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
843 if (baccent) { *baccent = 0; baccent = 0; }
844 if (accent) { *accent = 0; accent = 0; }
736 845
737 schar = mchar = echar = 0; 846 schar = mchar = echar = 0;
738 picks->resetState(); 847 picks->resetState();
739} 848}
740 849
741/* Keyboard::togglePickboard {{{1 */ 850/* Keyboard::togglePickboard {{{1 */
742void Keyboard::togglePickboard(bool on_off) 851void Keyboard::togglePickboard(bool on_off)
743{ 852{
744 usePicks = on_off; 853 usePicks = on_off;
745 if (usePicks) { 854 if (usePicks) {
746 picks->show(); 855 picks->show();
747 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send 856 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send
748 //adjustSize(); 857 //adjustSize();
749 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 858 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
750 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 859 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
751 } else { 860 } else {
752 861
753 picks->hide(); 862 picks->hide();
754 picks->resetState(); 863 picks->resetState();
755 //move(x(), y() + picks->height()); 864 //move(x(), y() + picks->height());
756 //adjustSize(); 865 //adjustSize();
757 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 866 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
758 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 867 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
759 868
760 } 869 }
761 /* 870 /*
762 * this closes && opens the input method 871 * this closes && opens the input method
763 */ 872 */
764 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 873 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
765 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 874 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
766} 875}
767 876
768void Keyboard::toggleRepeat(bool on) { 877void Keyboard::toggleRepeat(bool on) {
769 878
770 useRepeat = on; 879 useRepeat = on;
771 //cout << "setting useRepeat to: " << useRepeat << "\n"; 880 //cout << "setting useRepeat to: " << useRepeat << "\n";
772} 881}
773 882
774void Keyboard::cleanupConfigDlg() { 883void Keyboard::cleanupConfigDlg() {
775 884
776 if ( configdlg ) { 885 if ( configdlg ) {
777 delete (ConfigDlg *) configdlg; 886 delete (ConfigDlg *) configdlg;
778 configdlg = 0; 887 configdlg = 0;
779 } 888 }
780} 889}
781 890
782/* Keyboard::setMapTo ... {{{1 */ 891/* Keyboard::setMapTo ... {{{1 */
783void Keyboard::setMapToDefault() { 892void Keyboard::setMapToDefault() {
784 893
785 894
786 /* load current locale language map */ 895 /* load current locale language map */
787 Config *config = new Config("locale"); 896 Config *config = new Config("locale");
788 config->setGroup( "Language" ); 897 config->setGroup( "Language" );
789 QString l = config->readEntry( "Language" , "en" ); 898 QString l = config->readEntry( "Language" , "en" );
790 delete config; 899 delete config;
791 900
792 QString key_map = QPEApplication::qpeDir() + "share/multikey/" 901 QString key_map = QPEApplication::qpeDir() + "share/multikey/"
793 + l + ".keymap"; 902 + l + ".keymap";
794 903
795 /* save change to multikey config file */ 904 /* save change to multikey config file */
796 config = new Config("multikey"); 905 config = new Config("multikey");
797 config->setGroup ("keymaps"); 906 config->setGroup ("keymaps");
798 config->writeEntry ("current", key_map); // default closed 907 config->writeEntry ("current", key_map); // default closed
799 delete config; 908 delete config;
800 909
801 int prevRows = keys->rows(); 910 int prevRows = keys->rows();
802 911
803 delete keys; 912 delete keys;
804 keys = new Keys(key_map); 913 keys = new Keys(key_map);
805 914
806 // have to repaint the keyboard 915 // have to repaint the keyboard
807 if (prevRows != keys->rows()) { 916 if (prevRows != keys->rows()) {
808 917
809 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 918 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
810 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 919 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
811 920
812 } else repaint(FALSE); 921 } else repaint(FALSE);
813 922
814 resetState(); 923 resetState();
815} 924}
816 925
817void Keyboard::setMapToFile(QString map) { 926void Keyboard::setMapToFile(QString map) {
818 927
819 /* save change to multikey config file */ 928 /* save change to multikey config file */
820 Config *config = new Config("multikey"); 929 Config *config = new Config("multikey");
821 config->setGroup ("keymaps"); 930 config->setGroup ("keymaps");
822 config->writeEntry ("current", map); // default closed 931 config->writeEntry ("current", map); // default closed
823 932
824 delete config; 933 delete config;
825 934
826 int prevRows = keys->rows(); 935 int prevRows = keys->rows();
827 936
828 delete keys; 937 delete keys;
829 if (QFile(map).exists()) 938 if (QFile(map).exists())
830 keys = new Keys(map); 939 keys = new Keys(map);
831 else 940 else
832 keys = new Keys(); 941 keys = new Keys();
833 942
834 if (keys->rows() != prevRows) { 943 if (keys->rows() != prevRows) {
835 944
836 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 945 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
837 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 946 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
838 } 947 }
839 else repaint(FALSE); 948 else repaint(FALSE);
840 949
841 resetState(); 950 resetState();
842} 951}
843 952
844/* Keybaord::reloadKeyboard {{{1 */ 953/* Keybaord::reloadKeyboard {{{1 */
845void Keyboard::reloadKeyboard() { 954void Keyboard::reloadKeyboard() {
846 955
847 // reload colors and redraw 956 // reload colors and redraw
848 loadKeyboardColors(); 957 loadKeyboardColors();
849 repaint(); 958 repaint();
850 959
851} 960}
852 961
853void Keyboard::loadKeyboardColors() { 962void Keyboard::loadKeyboardColors() {
854 963
855 Config config ("multikey"); 964 Config config ("multikey");
856 config.setGroup("colors"); 965 config.setGroup("colors");
857 966
858 QStringList color; 967 QStringList color;
859 color = config.readListEntry("keycolor", QChar(',')); 968 color = config.readListEntry("keycolor", QChar(','));
860 if (color.isEmpty()) { 969 if (color.isEmpty()) {
861 color = QStringList::split(",", "240,240,240"); 970 color = QStringList::split(",", "240,240,240");
862 config.writeEntry("keycolor", color.join(",")); 971 config.writeEntry("keycolor", color.join(","));
863 972
864 } 973 }
865 keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 974 keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
866 975
867 color = config.readListEntry("keycolor_pressed", QChar(',')); 976 color = config.readListEntry("keycolor_pressed", QChar(','));
868 if (color.isEmpty()) { 977 if (color.isEmpty()) {
869 color = QStringList::split(",", "171,183,198"); 978 color = QStringList::split(",", "171,183,198");
870 config.writeEntry("keycolor_pressed", color.join(",")); 979 config.writeEntry("keycolor_pressed", color.join(","));
871 980
872 } 981 }
873 keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 982 keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
874 983
875 color = config.readListEntry("keycolor_lines", QChar(',')); 984 color = config.readListEntry("keycolor_lines", QChar(','));
876 if (color.isEmpty()) { 985 if (color.isEmpty()) {
877 color = QStringList::split(",", "138,148,160"); 986 color = QStringList::split(",", "138,148,160");
878 config.writeEntry("keycolor_lines", color.join(",")); 987 config.writeEntry("keycolor_lines", color.join(","));
879 988
880 } 989 }
881 keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 990 keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
882 991
883 color = config.readListEntry("textcolor", QChar(',')); 992 color = config.readListEntry("textcolor", QChar(','));
884 if (color.isEmpty()) { 993 if (color.isEmpty()) {
885 color = QStringList::split(",", "43,54,68"); 994 color = QStringList::split(",", "43,54,68");
886 config.writeEntry("textcolor", color.join(",")); 995 config.writeEntry("textcolor", color.join(","));
887 996
888 } 997 }
889 textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 998 textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
890 999
891} 1000}
892 1001
893/* korean input functions {{{1 1002/* korean input functions {{{1
894 * 1003 *
895 * TODO 1004 * TODO
896 * one major problem with this implementation is that you can't move the 1005 * one major problem with this implementation is that you can't move the
897 * cursor after inputing korean chars, otherwise it will eat up and replace 1006 * cursor after inputing korean chars, otherwise it will eat up and replace
898 * the char before the cursor you move to. fix that 1007 * the char before the cursor you move to. fix that
899 * 1008 *
900 * make backspace delete one single char, not the whole thing if still 1009 * make backspace delete one single char, not the whole thing if still
901 * editing. 1010 * editing.
902 * 1011 *
903 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 1012 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
904 * 1013 *
905 * how korean input works 1014 * how korean input works
906 * 1015 *
907 * all following chars means unicode char value and are in hex 1016 * all following chars means unicode char value and are in hex
908 * 1017 *
909 * ÃÊÀ½ = schar (start char) 1018 * ÃÊÀ½ = schar (start char)
910 * ÁßÀ½ = mchar (middle char) 1019 * ÁßÀ½ = mchar (middle char)
911 * ³¡À½ = echar (end char) 1020 * ³¡À½ = echar (end char)
912 * 1021 *
913 * there are 19 schars. unicode position is at 1100 - 1112 1022 * there are 19 schars. unicode position is at 1100 - 1112
914 * there are 21 mchars. unicode position is at 1161 - 1175 1023 * there are 21 mchars. unicode position is at 1161 - 1175
915 * there are 27 echars. unicode position is at 11a8 - 11c2 1024 * there are 27 echars. unicode position is at 11a8 - 11c2
916 * 1025 *
917 * the map with everything combined is at ac00 - d7a3 1026 * the map with everything combined is at ac00 - d7a3
918 * 1027 *
919 */ 1028 */
920 1029
921ushort Keyboard::parseKoreanInput (ushort c) { 1030ushort Keyboard::parseKoreanInput (ushort c) {
922 1031
923 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) 1032 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
924 || 1033 ||
925 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode 1034 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
926 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { 1035 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
927 1036
928 schar = 0, mchar = 0, echar = 0; 1037 schar = 0, mchar = 0, echar = 0;
929 return c; 1038 return c;
930 } 1039 }
931 1040
932 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input 1041 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input
933 1042
934 if (schar == 0 || (schar != 0 && mchar == 0)) { 1043 if (schar == 0 || (schar != 0 && mchar == 0)) {
935 schar = c; mchar = 0; echar = 0; 1044 schar = c; mchar = 0; echar = 0;
936 return c; 1045 return c;
937 } 1046 }
938 else if (mchar != 0) { 1047 else if (mchar != 0) {
939 1048
940 if (echar == 0) { 1049 if (echar == 0) {
941 1050
942 if (!(echar = constoe(c))) { 1051 if (!(echar = constoe(c))) {
943 1052
944 schar = c; mchar = 0; echar = 0; 1053 schar = c; mchar = 0; echar = 0;
945 return c; 1054 return c;
946 } 1055 }
947 1056
948 } 1057 }
949 else { // must figure out what the echar is 1058 else { // must figure out what the echar is
950 1059
951 if (echar == 0x11a8) { // ¤¡ 1060 if (echar == 0x11a8) { // ¤¡
952 1061
953 if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ 1062 if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡
954 else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ 1063 else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ
955 else { 1064 else {
956 schar = c; mchar = 0; echar = 0; 1065 schar = c; mchar = 0; echar = 0;
957 return c; 1066 return c;
958 } 1067 }
959 1068
960 } else if (echar == 0x11ab) { // ¤¤ 1069 } else if (echar == 0x11ab) { // ¤¤
961 1070
962 if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ 1071 if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸
963 else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ 1072 else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾
964 else { 1073 else {
965 schar = c; mchar = 0; echar = 0; 1074 schar = c; mchar = 0; echar = 0;
966 return c; 1075 return c;
967 } 1076 }
968 1077
969 } else if (echar == 0x11af) { // ¤© 1078 } else if (echar == 0x11af) { // ¤©
970 1079
971 if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ 1080 if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡
972 else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± 1081 else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤±
973 else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² 1082 else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤²
974 else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ 1083 else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ
975 else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ 1084 else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼
976 else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ 1085 else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½
977 else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ 1086 else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾
978 else { 1087 else {
979 schar = c; mchar = 0; echar = 0; 1088 schar = c; mchar = 0; echar = 0;
980 return c; 1089 return c;
981 } 1090 }
982 1091
983 } else if (echar == 0x11b8) { // ¤² 1092 } else if (echar == 0x11b8) { // ¤²
984 1093
985 if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ 1094 if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ
986 else { 1095 else {
987 schar = c; mchar = 0; echar = 0; 1096 schar = c; mchar = 0; echar = 0;
988 return c; 1097 return c;
989 } 1098 }
990 1099
991 } else if (echar == 0x11ba) { // ¤µ 1100 } else if (echar == 0x11ba) { // ¤µ
992 1101
993 if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ 1102 if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ
994 else { 1103 else {
995 schar = c; mchar = 0; echar = 0; 1104 schar = c; mchar = 0; echar = 0;
996 return c; 1105 return c;
997 } 1106 }
998 1107
999 } else { // if any other char, cannot combine chars 1108 } else { // if any other char, cannot combine chars
1000 1109
1001 schar = c; mchar = 0; echar = 0; 1110 schar = c; mchar = 0; echar = 0;
1002 return c; 1111 return c;
1003 } 1112 }
1004 1113
1005 unicode = echar; 1114 unicode = echar;
1006 } 1115 }
1007 } 1116 }
1008 1117
1009 } 1118 }
1010 else if (0x1161 <= c && c <= 0x1175) { // mchar was input 1119 else if (0x1161 <= c && c <= 0x1175) { // mchar was input
1011 1120
1012 if (schar != 0 && mchar == 0) { mchar = c; } 1121 if (schar != 0 && mchar == 0) { mchar = c; }
1013 1122
1014 else if (schar != 0 && mchar != 0 && echar == 0) { 1123 else if (schar != 0 && mchar != 0 && echar == 0) {
1015 1124
1016 switch (mchar) { 1125 switch (mchar) {
1017 case 0x1169: 1126 case 0x1169:
1018 if (c == 0x1161) mchar = 0x116a; 1127 if (c == 0x1161) mchar = 0x116a;
1019 else if (c == 0x1162) mchar = 0x116b; 1128 else if (c == 0x1162) mchar = 0x116b;
1020 else if (c == 0x1175) mchar = 0x116c; 1129 else if (c == 0x1175) mchar = 0x116c;
1021 else { 1130 else {
1022 schar = 0; mchar = 0; echar = 0; 1131 schar = 0; mchar = 0; echar = 0;
1023 return c; 1132 return c;
1024 } 1133 }
1025 break; 1134 break;
1026 case 0x116e: 1135 case 0x116e:
1027 if (c == 0x1165) mchar = 0x116f; 1136 if (c == 0x1165) mchar = 0x116f;
1028 else if (c == 0x1166) mchar = 0x1170; 1137 else if (c == 0x1166) mchar = 0x1170;
1029 else if (c == 0x1175) mchar = 0x1171; 1138 else if (c == 0x1175) mchar = 0x1171;
1030 else { 1139 else {
1031 schar = 0; mchar = 0; echar = 0; 1140 schar = 0; mchar = 0; echar = 0;
1032 return c; 1141 return c;
1033 } 1142 }
1034 break; 1143 break;
1035 case 0x1173: 1144 case 0x1173:
1036 if (c == 0x1175) mchar = 0x1174; 1145 if (c == 0x1175) mchar = 0x1174;
1037 else { 1146 else {
1038 schar = 0; mchar = 0; echar = 0; 1147 schar = 0; mchar = 0; echar = 0;
1039 return c; 1148 return c;
1040 } 1149 }
1041 break; 1150 break;
1042 default: 1151 default:
1043 schar = 0; mchar = 0; echar = 0; 1152 schar = 0; mchar = 0; echar = 0;
1044 return c; 1153 return c;
1045 } 1154 }
1046 } 1155 }
1047 else if (schar != 0 && mchar != 0 && echar != 0) { 1156 else if (schar != 0 && mchar != 0 && echar != 0) {
1048 1157
1049 emit key( 8, Qt::Key_Backspace, 0, true, false ); 1158 emit key( 8, Qt::Key_Backspace, 0, true, false );
1050 1159
1051 ushort prev = 0; 1160 ushort prev = 0;
1052 switch (echar) { 1161 switch (echar) {
1053 /* 1162 /*
1054 case 0x11a9: 1163 case 0x11a9:
1055 prev = combineKoreanChars(schar, mchar, 0x11a8); 1164 prev = combineKoreanChars(schar, mchar, 0x11a8);
1056 schar = 0x1100; 1165 schar = 0x1100;
1057 break; 1166 break;
1058 */ 1167 */
1059 case 0x11aa: 1168 case 0x11aa:
1060 prev = combineKoreanChars(schar, mchar, 0x11a8); 1169 prev = combineKoreanChars(schar, mchar, 0x11a8);
1061 schar = 0x1109; 1170 schar = 0x1109;
1062 break; 1171 break;
1063 case 0x11ac: 1172 case 0x11ac:
1064 prev = combineKoreanChars(schar, mchar, 0x11ab); 1173 prev = combineKoreanChars(schar, mchar, 0x11ab);
1065 schar = 0x110c; 1174 schar = 0x110c;
1066 break; 1175 break;
1067 case 0x11ad: 1176 case 0x11ad:
1068 prev = combineKoreanChars(schar, mchar, 0x11ab); 1177 prev = combineKoreanChars(schar, mchar, 0x11ab);
1069 schar = 0x1112; 1178 schar = 0x1112;
1070 break; 1179 break;
1071 case 0x11b0: 1180 case 0x11b0:
1072 prev = combineKoreanChars(schar, mchar, 0x11af); 1181 prev = combineKoreanChars(schar, mchar, 0x11af);
1073 schar = 0x1100; 1182 schar = 0x1100;
1074 break; 1183 break;
1075 case 0x11b1: 1184 case 0x11b1:
1076 prev = combineKoreanChars(schar, mchar, 0x11af); 1185 prev = combineKoreanChars(schar, mchar, 0x11af);
1077 schar = 0x1106; 1186 schar = 0x1106;
1078 break; 1187 break;
1079 case 0x11b2: 1188 case 0x11b2:
1080 prev = combineKoreanChars(schar, mchar, 0x11af); 1189 prev = combineKoreanChars(schar, mchar, 0x11af);
1081 schar = 0x1107; 1190 schar = 0x1107;
1082 break; 1191 break;
1083 case 0x11b3: 1192 case 0x11b3:
1084 prev = combineKoreanChars(schar, mchar, 0x11af); 1193 prev = combineKoreanChars(schar, mchar, 0x11af);
1085 schar = 0x1109; 1194 schar = 0x1109;
1086 break; 1195 break;
1087 case 0x11b4: 1196 case 0x11b4:
1088 prev = combineKoreanChars(schar, mchar, 0x11af); 1197 prev = combineKoreanChars(schar, mchar, 0x11af);
1089 schar = 0x1110; 1198 schar = 0x1110;
1090 break; 1199 break;
1091 case 0x11b9: 1200 case 0x11b9:
1092 prev = combineKoreanChars(schar, mchar, 0x11b8); 1201 prev = combineKoreanChars(schar, mchar, 0x11b8);
1093 schar = 0x1109; 1202 schar = 0x1109;
1094 break; 1203 break;
1095 /* 1204 /*
1096 case 0x11bb: 1205 case 0x11bb:
1097 prev = combineKoreanChars(schar, mchar, 0x11ba); 1206 prev = combineKoreanChars(schar, mchar, 0x11ba);
1098 schar = 0x1109; 1207 schar = 0x1109;
1099 break; 1208 break;
1100 */ 1209 */
1101 default: 1210 default:
1102 1211
1103 if (constoe(echar)) { 1212 if (constoe(echar)) {
1104 1213
1105 prev = combineKoreanChars(schar, mchar, 0); 1214 prev = combineKoreanChars(schar, mchar, 0);
1106 schar = constoe(echar); 1215 schar = constoe(echar);
1107 } 1216 }
1108 break; 1217 break;
1109 } 1218 }
1110 1219
1111 emit key( prev, prev, 0, true, false ); 1220 emit key( prev, prev, 0, true, false );
1112 1221
1113 mchar = c; echar = 0; 1222 mchar = c; echar = 0;
1114 1223
1115 return combineKoreanChars(schar, mchar, 0); 1224 return combineKoreanChars(schar, mchar, 0);
1116 1225
1117 } 1226 }
1118 else { 1227 else {
1119 schar = 0; mchar = 0; echar = 0; 1228 schar = 0; mchar = 0; echar = 0;
1120 return c; 1229 return c;
1121 } 1230 }
1122 1231
1123 } 1232 }
1124 else /*if (c == ' ')*/ return c; 1233 else /*if (c == ' ')*/ return c;
1125 1234
1126 1235
1127 // and now... finally delete previous char, and return new char 1236 // and now... finally delete previous char, and return new char
1128 emit key( 8, Qt::Key_Backspace, 0, true, false ); 1237 emit key( 8, Qt::Key_Backspace, 0, true, false );
1129 1238
1130 1239
1131 return combineKoreanChars( schar, mchar, echar); 1240 return combineKoreanChars( schar, mchar, echar);
1132 1241
1133} 1242}
1134 1243
1135ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { 1244ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) {
1136 1245
1137 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; 1246 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00;
1138 1247
1139} 1248}
1140 1249
1141ushort Keyboard::constoe(const ushort c) { 1250ushort Keyboard::constoe(const ushort c) {
1142 1251
1143 // converts schars to echars if possible 1252 // converts schars to echars if possible
1144 1253
1145 if (0x1100 <= c && c <= 0x1112) { // schar to echar 1254 if (0x1100 <= c && c <= 0x1112) { // schar to echar
1146 1255
1147 switch (c) { 1256 switch (c) {
1148 case 0x1100: return 0x11a8; 1257 case 0x1100: return 0x11a8;
1149 case 0x1101: return 0x11a9; 1258 case 0x1101: return 0x11a9;
1150 case 0x1102: return 0x11ab; 1259 case 0x1102: return 0x11ab;
1151 case 0x1103: return 0x11ae; 1260 case 0x1103: return 0x11ae;
1152 case 0x1105: return 0x11af; 1261 case 0x1105: return 0x11af;
1153 case 0x1106: return 0x11b7; 1262 case 0x1106: return 0x11b7;
1154 case 0x1107: return 0x11b8; 1263 case 0x1107: return 0x11b8;
1155 case 0x1109: return 0x11ba; 1264 case 0x1109: return 0x11ba;
1156 case 0x110a: return 0x11bb; 1265 case 0x110a: return 0x11bb;
1157 case 0x110b: return 0x11bc; 1266 case 0x110b: return 0x11bc;
1158 case 0x110c: return 0x11bd; 1267 case 0x110c: return 0x11bd;
1159 case 0x110e: return 0x11be; 1268 case 0x110e: return 0x11be;
1160 case 0x110f: return 0x11bf; 1269 case 0x110f: return 0x11bf;
1161 case 0x1110: return 0x11c0; 1270 case 0x1110: return 0x11c0;
1162 case 0x1111: return 0x11c1; 1271 case 0x1111: return 0x11c1;
1163 case 0x1112: return 0x11c2; 1272 case 0x1112: return 0x11c2;
1164 default: return 0; 1273 default: return 0;
1165 1274
1166 } 1275 }
1167 1276
1168 } else { //echar to schar 1277 } else { //echar to schar
1169 1278
1170 switch (c) { 1279 switch (c) {
1171 case 0x11a8: return 0x1100; 1280 case 0x11a8: return 0x1100;
1172 case 0x11a9: return 0x1101; 1281 case 0x11a9: return 0x1101;
1173 case 0x11ab: return 0x1102; 1282 case 0x11ab: return 0x1102;
1174 case 0x11ae: return 0x1103; 1283 case 0x11ae: return 0x1103;
1175 case 0x11af: return 0x1105; 1284 case 0x11af: return 0x1105;
1176 case 0x11b7: return 0x1106; 1285 case 0x11b7: return 0x1106;
1177 case 0x11b8: return 0x1107; 1286 case 0x11b8: return 0x1107;
1178 case 0x11ba: return 0x1109; 1287 case 0x11ba: return 0x1109;
1179 case 0x11bb: return 0x110a; 1288 case 0x11bb: return 0x110a;
1180 case 0x11bc: return 0x110b; 1289 case 0x11bc: return 0x110b;
1181 case 0x11bd: return 0x110c; 1290 case 0x11bd: return 0x110c;
1182 case 0x11be: return 0x110e; 1291 case 0x11be: return 0x110e;
1183 case 0x11bf: return 0x110f; 1292 case 0x11bf: return 0x110f;
1184 case 0x11c0: return 0x1110; 1293 case 0x11c0: return 0x1110;
1185 case 0x11c1: return 0x1111; 1294 case 0x11c1: return 0x1111;
1186 case 0x11c2: return 0x1112; 1295 case 0x11c2: return 0x1112;
1187 default: return 0; 1296 default: return 0;
1188 1297
1189 } 1298 }
1190 1299
1191 } 1300 }
1192} 1301}
1193 1302
1194 1303
1195// Keys::Keys {{{1 1304// Keys::Keys {{{1
1196 1305
1197Keys::Keys() { 1306Keys::Keys() {
1198 1307
1199 Config *config = new Config ("multikey"); 1308 Config *config = new Config ("multikey");
1200 config->setGroup( "keymaps" ); 1309 config->setGroup( "keymaps" );
1201 QString map = config->readEntry( "current" ); 1310 QString map = config->readEntry( "current" );
1202 delete config; 1311 delete config;
1203 1312
1204 if (map.isNull() || !(QFile(map).exists())) { 1313 if (map.isNull() || !(QFile(map).exists())) {
1205 1314
1206 Config *config = new Config("locale"); 1315 Config *config = new Config("locale");
1207 config->setGroup( "Language" ); 1316 config->setGroup( "Language" );
1208 QString l = config->readEntry( "Language" , "en" ); 1317 QString l = config->readEntry( "Language" , "en" );
1209 delete config; 1318 delete config;
1210 1319
1211 map = QPEApplication::qpeDir() + "/share/multikey/" 1320 map = QPEApplication::qpeDir() + "/share/multikey/"
1212 + l + ".keymap"; 1321 + l + ".keymap";
1213 1322
1214 } 1323 }
1215 1324
1216 setKeysFromFile(map); 1325 setKeysFromFile(map);
1217} 1326}
1218 1327
1219Keys::Keys(const char * filename) { 1328Keys::Keys(const char * filename) {
1220 1329
1221 setKeysFromFile(filename); 1330 setKeysFromFile(filename);
1222} 1331}
1223 1332
1224// Keys::setKeysFromFile {{{2 1333// Keys::setKeysFromFile {{{2
1225void Keys::setKeysFromFile(const char * filename) { 1334void Keys::setKeysFromFile(const char * filename) {
1226 1335
1227 QFile f(filename); 1336 QFile f(filename);
1228 1337
1229 if (f.open(IO_ReadOnly)) { 1338 if (f.open(IO_ReadOnly)) {
1230 1339
1231 QTextStream t(&f); 1340 QTextStream t(&f);
1232 int row; 1341 int row;
1233 int qcode; 1342 int qcode;
1234 ushort unicode; 1343 ushort unicode;
1235 int width; 1344 int width;
1236 QString buf; 1345 QString buf;
1237 QString comment; 1346 QString comment;
1238 char * xpm[256]; //couldnt be larger than that... could it? 1347 char * xpm[256]; //couldnt be larger than that... could it?
1239 QImage *xpm2pix = 0; 1348 QImage *xpm2pix = 0;
1240 1349
1241 buf = t.readLine(); 1350 buf = t.readLine();
1242 while (buf) { 1351 while (buf) {
1243 1352
1244 // get rid of comments 1353 // get rid of comments
1245 buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); 1354 buf.replace(QRegExp("#.*$", FALSE, FALSE), "");
1246 1355
1247 // key definition 1356 // key definition
1248 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { 1357 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
1249 // no $1 type referencing!!! this implementation of regexp sucks 1358 // no $1 type referencing!!! this implementation of regexp sucks
1250 1359
1251 // dont know of any sscanf() type funcs in Qt lib 1360 // dont know of any sscanf() type funcs in Qt lib
1252 QTextStream tmp (buf, IO_ReadOnly); 1361 QTextStream tmp (buf, IO_ReadOnly);
1253 tmp >> row >> qcode >> unicode >> width >> comment; 1362 tmp >> row >> qcode >> unicode >> width >> comment;
1254 1363
1255 buf = t.readLine(); 1364 buf = t.readLine();
1256 int xpmLineCount = 0; 1365 int xpmLineCount = 0;
1257 xpm2pix = 0; 1366 xpm2pix = 0;
1258 1367
1259 // erase blank space 1368 // erase blank space
1260 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); 1369 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
1261 1370
1262 while (buf.contains(QRegExp("^\\s*\".*\""))) { 1371 while (buf.contains(QRegExp("^\\s*\".*\""))) {
1263 1372
1264 QString xpmBuf = buf.stripWhiteSpace(); 1373 QString xpmBuf = buf.stripWhiteSpace();
1265 1374
1266 xpm[xpmLineCount] = new char [xpmBuf.length()]; 1375 xpm[xpmLineCount] = new char [xpmBuf.length()];
1267 1376
1268 int j = 0; 1377 int j = 0;
1269 for (ushort i = 0; i < xpmBuf.length(); i++) { 1378 for (ushort i = 0; i < xpmBuf.length(); i++) {
1270 if (xpmBuf[i].latin1() != '"') { 1379 if (xpmBuf[i].latin1() != '"') {
1271 1380
1272 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); 1381 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1();
1273 j++; 1382 j++;
1274 } 1383 }
1275 1384
1276 } 1385 }
1277 // have to close that facker up 1386 // have to close that facker up
1278 ((char *)xpm[xpmLineCount])[j] = '\0'; 1387 ((char *)xpm[xpmLineCount])[j] = '\0';
1279 1388
1280 xpmLineCount++; 1389 xpmLineCount++;
1281 buf = t.readLine(); 1390 buf = t.readLine();
1282 } 1391 }
1283 if (xpmLineCount) { 1392 if (xpmLineCount) {
1284 1393
1285 xpm2pix = new QImage((const char **)xpm); 1394 xpm2pix = new QImage((const char **)xpm);
1286 for (int i = 0; i < xpmLineCount; i++) 1395 for (int i = 0; i < xpmLineCount; i++)
1287 1396
1288 delete [] (xpm[i]); 1397 delete [] (xpm[i]);
1289 1398
1290 } 1399 }
1291 setKey(row, qcode, unicode, width, xpm2pix); 1400 setKey(row, qcode, unicode, width, xpm2pix);
1292 } 1401 }
1293 1402
1294 // shift map 1403 // shift map
1295 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1404 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1296 1405
1297 QTextStream tmp (buf, IO_ReadOnly); 1406 QTextStream tmp (buf, IO_ReadOnly);
1298 ushort lower, shift; 1407 ushort lower, shift;
1299 tmp >> lower >> shift; 1408 tmp >> lower >> shift;
1300 1409
1301 shiftMap.insert(lower, shift); 1410 shiftMap.insert(lower, shift);
1302 1411
1303 buf = t.readLine(); 1412 buf = t.readLine();
1304 } 1413 }
1305 1414
1306 // meta key map 1415 // meta key map
1307 else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1416 else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1308 1417
1309 QTextStream tmp (buf, IO_ReadOnly); 1418 QTextStream tmp (buf, IO_ReadOnly);
1310 ushort lower, shift; 1419 ushort lower, shift;
1311 QChar m; 1420 QChar m;
1312 tmp >> m >> lower >> shift; 1421 tmp >> m >> lower >> shift;
1313 1422
1314 metaMap.insert(lower, shift); 1423 metaMap.insert(lower, shift);
1315 1424
1316 buf = t.readLine(); 1425 buf = t.readLine();
1317 } 1426 }
1318 1427
1319 // circumflex 1428 // circumflex
1320 else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1429 else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1321 1430
1322 QTextStream tmp (buf, IO_ReadOnly); 1431 QTextStream tmp (buf, IO_ReadOnly);
1323 ushort lower, shift; 1432 ushort lower, shift;
1324 QChar c; 1433 QChar c;
1325 tmp >> c >> lower >> shift; 1434 tmp >> c >> lower >> shift;
1326 1435
1327 circumflexMap.insert(lower, shift); 1436 circumflexMap.insert(lower, shift);
1328 1437
1329 buf = t.readLine(); 1438 buf = t.readLine();
1330 } 1439 }
1331 // diaeresis 1440 // diaeresis
1332 else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1441 else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1333 1442
1334 QTextStream tmp (buf, IO_ReadOnly); 1443 QTextStream tmp (buf, IO_ReadOnly);
1335 ushort lower, shift; 1444 ushort lower, shift;
1336 QChar d; 1445 QChar d;
1337 tmp >> d >> lower >> shift; 1446 tmp >> d >> lower >> shift;
1338 1447
1339 diaeresisMap.insert(lower, shift); 1448 diaeresisMap.insert(lower, shift);
1340 1449
1341 buf = t.readLine(); 1450 buf = t.readLine();
1342 } 1451 }
1452 // back accent
1453 else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1454
1455 QTextStream tmp (buf, IO_ReadOnly);
1456 ushort lower, shift;
1457 QChar d;
1458 tmp >> d >> lower >> shift;
1459
1460 baccentMap.insert(lower, shift);
1461
1462 qDebug ("Estoy añadiendo %i con %i", lower, shift);
1463 buf = t.readLine();
1464 }
1465 // accent
1466 else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1467
1468 QTextStream tmp (buf, IO_ReadOnly);
1469 ushort lower, shift;
1470 QChar d;
1471 tmp >> d >> lower >> shift;
1472
1473 accentMap.insert(lower, shift);
1474
1475 buf = t.readLine();
1476 }
1343 1477
1344 // other variables like lang & title 1478 // other variables like lang & title
1345 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { 1479 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) {
1346 1480
1347 QTextStream tmp (buf, IO_ReadOnly); 1481 QTextStream tmp (buf, IO_ReadOnly);
1348 QString name, equals, value; 1482 QString name, equals, value;
1349 1483
1350 tmp >> name >> equals >> value; 1484 tmp >> name >> equals >> value;
1351 1485
1352 if (name == "lang") { 1486 if (name == "lang") {
1353 1487
1354 lang = value; 1488 lang = value;
1355 1489
1356 } 1490 }
1357 1491
1358 buf = t.readLine(); 1492 buf = t.readLine();
1359 } 1493 }
1360 // comments 1494 // comments
1361 else if (buf.contains(QRegExp("^\\s*#"))) { 1495 else if (buf.contains(QRegExp("^\\s*#"))) {
1362 1496
1363 buf = t.readLine(); 1497 buf = t.readLine();
1364 1498
1365 } else { // blank line, or garbage 1499 } else { // blank line, or garbage
1366 1500
1367 buf = t.readLine(); 1501 buf = t.readLine();
1368 1502
1369 } 1503 }
1370 1504
1371 } 1505 }
1372 f.close(); 1506 f.close();
1373 } 1507 }
1374 1508
1375} 1509}
1376 1510
1377// Keys::setKey {{{2 1511// Keys::setKey {{{2
1378void Keys::setKey(const int row, const int qcode, const ushort unicode, 1512void Keys::setKey(const int row, const int qcode, const ushort unicode,
1379 const int width, QImage *pix) { 1513 const int width, QImage *pix) {
1380 1514
1381 Key * key; 1515 Key * key;
1382 key = new Key; 1516 key = new Key;
1383 key->qcode = qcode; 1517 key->qcode = qcode;
1384 key->unicode = unicode; 1518 key->unicode = unicode;
1385 key->width = width; 1519 key->width = width;
1386 1520
1387 // share key->pressed between same keys 1521 // share key->pressed between same keys
1388 bool found = 0; 1522 bool found = 0;
1389 for (int i = 1; i <= 5; i++) { 1523 for (int i = 1; i <= 5; i++) {
1390 for (unsigned int j = 0; j < keys[i].count(); j++) 1524 for (unsigned int j = 0; j < keys[i].count(); j++)
1391 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { 1525 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) {
1392 1526
1393 key->pressed = keys[i].at(j)->pressed; 1527 key->pressed = keys[i].at(j)->pressed;
1394 found = 1; 1528 found = 1;
1395 } 1529 }
1396 1530
1397 } 1531 }
1398 if (!found) { 1532 if (!found) {
1399 1533
1400 key->pressed = new bool; 1534 key->pressed = new bool;
1401 *(key->pressed) = 0; 1535 *(key->pressed) = 0;
1402 } 1536 }
1403 1537
1404 key->pix = pix; 1538 key->pix = pix;
1405 1539
1406 1540
1407 keys[row].append(key); 1541 keys[row].append(key);
1408} 1542}
1409 1543
1410// Keys::~Keys {{{2 1544// Keys::~Keys {{{2
1411Keys::~Keys() { 1545Keys::~Keys() {
1412 1546
1413 for (int i = 1; i <= 5; i++) 1547 for (int i = 1; i <= 5; i++)
1414 for (unsigned int j = 0; j < keys[i].count(); j++) 1548 for (unsigned int j = 0; j < keys[i].count(); j++)
1415 delete keys[i].at(j); 1549 delete keys[i].at(j);
1416 1550
1417} 1551}
1418 1552
1419// Keys:: other functions {{{2 1553// Keys:: other functions {{{2
1420int Keys::width(const int row, const int col) { 1554int Keys::width(const int row, const int col) {
1421 1555
1422 return keys[row].at(col)->width; 1556 return keys[row].at(col)->width;
1423 1557
1424} 1558}
1425 1559
1426int Keys::rows() { 1560int Keys::rows() {
1427 1561
1428 for (int i = 1; i <= 5; i++) { 1562 for (int i = 1; i <= 5; i++) {
1429 1563
1430 if (keys[i].count() == 0) 1564 if (keys[i].count() == 0)
1431 return i - 1; 1565 return i - 1;
1432 1566
1433 } 1567 }
1434 return 5; 1568 return 5;
1435} 1569}
1436 1570
1437ushort Keys::uni(const int row, const int col) { 1571ushort Keys::uni(const int row, const int col) {
1438 1572
1439 return keys[row].at(col)->unicode; 1573 return keys[row].at(col)->unicode;
1440 1574
1441} 1575}
1442 1576
1443int Keys::qcode(const int row, const int col) { 1577int Keys::qcode(const int row, const int col) {
1444 1578
1445 return keys[row].at(col)->qcode; 1579 return keys[row].at(col)->qcode;
1446} 1580}
1447 1581
1448QImage *Keys::pix(const int row, const int col) { 1582QImage *Keys::pix(const int row, const int col) {
1449 1583
1450 return keys[row].at(col)->pix; 1584 return keys[row].at(col)->pix;
1451 1585
1452} 1586}
1453bool Keys::pressed(const int row, const int col) { 1587bool Keys::pressed(const int row, const int col) {
1454 1588
1455 return *(keys[row].at(col)->pressed); 1589 return *(keys[row].at(col)->pressed);
1456} 1590}
1457 1591
1458int Keys::numKeys(const int row) { 1592int Keys::numKeys(const int row) {
1459 1593
1460 return keys[row].count(); 1594 return keys[row].count();
1461} 1595}
1462 1596
1463void Keys::setPressed(const int row, const int col, const bool pressed) { 1597void Keys::setPressed(const int row, const int col, const bool pressed) {
1464 1598
1465 *(keys[row].at(col)->pressed) = pressed; 1599 *(keys[row].at(col)->pressed) = pressed;
1466} 1600}
1467 1601
1468ushort Keys::shift(const ushort uni) { 1602ushort Keys::shift(const ushort uni) {
1469 1603
1470 if (shiftMap[uni]) return shiftMap[uni]; 1604 if (shiftMap[uni]) return shiftMap[uni];
1471 else return 0; 1605 else return 0;
1472} 1606}
1473 1607
1474ushort Keys::meta(const ushort uni) { 1608ushort Keys::meta(const ushort uni) {
1475 1609
1476 if (metaMap[uni]) return metaMap[uni]; 1610 if (metaMap[uni]) return metaMap[uni];
1477 else return 0; 1611 else return 0;
1478} 1612}
1479 1613
1480ushort Keys::circumflex(const ushort uni) { 1614ushort Keys::circumflex(const ushort uni) {
1481 1615
1482 if (circumflexMap[uni]) return circumflexMap[uni]; 1616 if (circumflexMap[uni]) return circumflexMap[uni];
1483 else return 0; 1617 else return 0;
1484} 1618}
1485 1619
1486ushort Keys::diaeresis(const ushort uni) { 1620ushort Keys::diaeresis(const ushort uni) {
1487 1621
1488 if(diaeresisMap[uni]) return diaeresisMap[uni]; 1622 if(diaeresisMap[uni]) return diaeresisMap[uni];
1489 else return 0; 1623 else return 0;
1490} 1624}
1491 1625
1626ushort Keys::baccent(const ushort uni) {
1627
1628 if(baccentMap[uni]) return baccentMap[uni];
1629 else return 0;
1630}
1631
1632ushort Keys::accent(const ushort uni) {
1633
1634 if(accentMap[uni]) return accentMap[uni];
1635 else return 0;
1636}
1637
1492bool *Keys::pressedPtr(const int row, const int col) { 1638bool *Keys::pressedPtr(const int row, const int col) {
1493 1639
1494 return keys[row].at(col)->pressed; 1640 return keys[row].at(col)->pressed;
1495} 1641}
diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h
index 8af80d0..bc74e71 100644
--- a/inputmethods/multikey/keyboard.h
+++ b/inputmethods/multikey/keyboard.h
@@ -1,182 +1,188 @@
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#include <qframe.h> 20#include <qframe.h>
21#include <qmap.h> 21#include <qmap.h>
22#include "../pickboard/pickboardcfg.h" 22#include "../pickboard/pickboardcfg.h"
23#include "../pickboard/pickboardpicks.h" 23#include "../pickboard/pickboardpicks.h"
24#include "configdlg.h" 24#include "configdlg.h"
25 25
26class QTimer; 26class QTimer;
27 27
28class KeyboardConfig : public DictFilterConfig 28class KeyboardConfig : public DictFilterConfig
29{ 29{
30public: 30public:
31 KeyboardConfig(PickboardPicks* p) : DictFilterConfig(p), backspaces(0) { nrows = 1; } 31 KeyboardConfig(PickboardPicks* p) : DictFilterConfig(p), backspaces(0) { nrows = 1; }
32 virtual void generateText(const QString &s); 32 virtual void generateText(const QString &s);
33 void decBackspaces() { if (backspaces) backspaces--; } 33 void decBackspaces() { if (backspaces) backspaces--; }
34 void incBackspaces() { backspaces++; } 34 void incBackspaces() { backspaces++; }
35 void resetBackspaces() { backspaces = 0; } 35 void resetBackspaces() { backspaces = 0; }
36private: 36private:
37 int backspaces; 37 int backspaces;
38}; 38};
39 39
40 40
41class KeyboardPicks : public PickboardPicks 41class KeyboardPicks : public PickboardPicks
42{ 42{
43 Q_OBJECT 43 Q_OBJECT
44public: 44public:
45 KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0) 45 KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0)
46 : PickboardPicks(parent, name, f) { } 46 : PickboardPicks(parent, name, f) { }
47 void initialise(); 47 void initialise();
48 virtual QSize sizeHint() const; 48 virtual QSize sizeHint() const;
49 KeyboardConfig *dc; 49 KeyboardConfig *dc;
50}; 50};
51 51
52 52
53class Keys { 53class Keys {
54public: 54public:
55 55
56 Keys(); 56 Keys();
57 Keys(const char * filename); 57 Keys(const char * filename);
58 ~Keys(); 58 ~Keys();
59 int width(const int row, const int col); 59 int width(const int row, const int col);
60 int rows(); 60 int rows();
61 ushort uni(const int row, const int col); 61 ushort uni(const int row, const int col);
62 int qcode(const int row, const int col); 62 int qcode(const int row, const int col);
63 bool pressed(const int row, const int col); 63 bool pressed(const int row, const int col);
64 bool *pressedPtr(const int row, const int col); 64 bool *pressedPtr(const int row, const int col);
65 ushort shift(const ushort); 65 ushort shift(const ushort);
66 ushort meta(const ushort); 66 ushort meta(const ushort);
67 ushort circumflex(const ushort); 67 ushort circumflex(const ushort);
68 ushort diaeresis(const ushort); 68 ushort diaeresis(const ushort);
69 ushort baccent(const ushort);
70 ushort accent(const ushort);
69 QImage *pix(const int row, const int col); 71 QImage *pix(const int row, const int col);
70 int numKeys(const int row); 72 int numKeys(const int row);
71 void setKeysFromFile(const char *filename); 73 void setKeysFromFile(const char *filename);
72 void setKey(const int row, const int qcode, const ushort unicode, 74 void setKey(const int row, const int qcode, const ushort unicode,
73 const int width, QImage *pix); 75 const int width, QImage *pix);
74 void setPressed(const int row, const int col, const bool pressed); 76 void setPressed(const int row, const int col, const bool pressed);
75 QString lang; 77 QString lang;
76 QString label; 78 QString label;
77 79
78private: 80private:
79 81
80 typedef struct Key { 82 typedef struct Key {
81 int qcode; // are qt key codes just unicode values? 83 int qcode; // are qt key codes just unicode values?
82 ushort unicode; 84 ushort unicode;
83 int width; // not pixels but relative key width. normal key is 2 85 int width; // not pixels but relative key width. normal key is 2
84 86
85 // only needed for keys like ctrl that can have multiple keys pressed at once 87 // only needed for keys like ctrl that can have multiple keys pressed at once
86 bool *pressed; 88 bool *pressed;
87 QImage *pix; 89 QImage *pix;
88 }; 90 };
89 91
90 QList<Key> keys[6]; 92 QList<Key> keys[6];
91 QMap<ushort,ushort> shiftMap; 93 QMap<ushort,ushort> shiftMap;
92 QMap<ushort,ushort> metaMap; 94 QMap<ushort,ushort> metaMap;
93 QMap<ushort,ushort> circumflexMap; 95 QMap<ushort,ushort> circumflexMap;
94 QMap<ushort,ushort> diaeresisMap; 96 QMap<ushort,ushort> diaeresisMap;
97 QMap<ushort,ushort> baccentMap;
98 QMap<ushort,ushort> accentMap;
95 99
96}; 100};
97 101
98class Keyboard : public QFrame 102class Keyboard : public QFrame
99{ 103{
100 Q_OBJECT 104 Q_OBJECT
101public: 105public:
102 Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 ); 106 Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 );
103 ~Keyboard(); 107 ~Keyboard();
104 108
105 void resetState(); 109 void resetState();
106 110
107 void mousePressEvent(QMouseEvent*); 111 void mousePressEvent(QMouseEvent*);
108 void mouseReleaseEvent(QMouseEvent*); 112 void mouseReleaseEvent(QMouseEvent*);
109 void resizeEvent(QResizeEvent*); 113 void resizeEvent(QResizeEvent*);
110 void paintEvent(QPaintEvent* e); 114 void paintEvent(QPaintEvent* e);
111 //void timerEvent(QTimerEvent* e); 115 //void timerEvent(QTimerEvent* e);
112 void drawKeyboard( QPainter &p, int row = -1, int col = -1); 116 void drawKeyboard( QPainter &p, int row = -1, int col = -1);
113 117
114 QSize sizeHint() const; 118 QSize sizeHint() const;
115 119
116signals: 120signals:
117 void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool ); 121 void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool );
118 122
119private slots: 123private slots:
120 void repeat(); 124 void repeat();
121 void togglePickboard(bool on_off); 125 void togglePickboard(bool on_off);
122 void toggleRepeat(bool on_off); 126 void toggleRepeat(bool on_off);
123 void setMapToDefault(); 127 void setMapToDefault();
124 void setMapToFile(QString map); 128 void setMapToFile(QString map);
125 void cleanupConfigDlg(); 129 void cleanupConfigDlg();
126 130
127 // used to redraw keyboard after edited colors 131 // used to redraw keyboard after edited colors
128 void reloadKeyboard(); 132 void reloadKeyboard();
129 133
130private: 134private:
131 int getKey( int &w, int j = -1 ); 135 int getKey( int &w, int j = -1 );
132 void clearHighlight(); 136 void clearHighlight();
133 137
134 bool *shift; 138 bool *shift;
135 bool *lock; 139 bool *lock;
136 bool *ctrl; 140 bool *ctrl;
137 bool *alt; 141 bool *alt;
138 bool *meta; 142 bool *meta;
139 bool *circumflex; 143 bool *circumflex;
140 bool *diaeresis; 144 bool *diaeresis;
145 bool *baccent;
146 bool *accent;
141 147
142 uint useLargeKeys:1; 148 uint useLargeKeys:1;
143 uint usePicks:1; 149 uint usePicks:1;
144 uint useRepeat:1; 150 uint useRepeat:1;
145 151
146 int pressedKeyRow; 152 int pressedKeyRow;
147 int pressedKeyCol; 153 int pressedKeyCol;
148 154
149 KeyboardPicks *picks; 155 KeyboardPicks *picks;
150 156
151 int keyHeight; 157 int keyHeight;
152 int defaultKeyWidth; 158 int defaultKeyWidth;
153 int xoffs; 159 int xoffs;
154 160
155 int unicode; 161 int unicode;
156 int qkeycode; 162 int qkeycode;
157 int modifiers; 163 int modifiers;
158 164
159 int pressTid; 165 int pressTid;
160 bool pressed; 166 bool pressed;
161 167
162 Keys *keys; 168 Keys *keys;
163 169
164 /* for korean input */ 170 /* for korean input */
165 ushort schar, mchar, echar; 171 ushort schar, mchar, echar;
166 ushort parseKoreanInput(ushort c); 172 ushort parseKoreanInput(ushort c);
167 ushort combineKoreanChars(const ushort s, const ushort m, const ushort e); 173 ushort combineKoreanChars(const ushort s, const ushort m, const ushort e);
168 ushort constoe(const ushort c); 174 ushort constoe(const ushort c);
169 175
170 QTimer *repeatTimer; 176 QTimer *repeatTimer;
171 177
172 /* colors */ 178 /* colors */
173 void loadKeyboardColors(); 179 void loadKeyboardColors();
174 QColor keycolor; 180 QColor keycolor;
175 QColor keycolor_pressed; 181 QColor keycolor_pressed;
176 QColor keycolor_lines; 182 QColor keycolor_lines;
177 QColor textcolor; 183 QColor textcolor;
178 184
179 ConfigDlg *configdlg; 185 ConfigDlg *configdlg;
180}; 186};
181 187
182 188