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