summaryrefslogtreecommitdiff
authorhash <hash>2002-08-22 04:33:16 (UTC)
committer hash <hash>2002-08-22 04:33:16 (UTC)
commitea0d66f137984689c4d4ef6da7dd4b7323760e8c (patch) (unidiff)
tree75332072b67132ef7fd7559578b7f02405d69a88
parentee90b966cfc262770ef5a45c2bad0af6766245a2 (diff)
downloadopie-ea0d66f137984689c4d4ef6da7dd4b7323760e8c.zip
opie-ea0d66f137984689c4d4ef6da7dd4b7323760e8c.tar.gz
opie-ea0d66f137984689c4d4ef6da7dd4b7323760e8c.tar.bz2
fixed nasty bug related to ctrl and alt keys
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index d5a7afd..7098a6b 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -177,264 +177,282 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col)
177 keyWidth * defaultKeyWidth - 1, keyHeight - 1, 177 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
178 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); 178 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor);
179 179
180 QPixmap *pix = keys->pix(row,col); 180 QPixmap *pix = keys->pix(row,col);
181 181
182 ushort c = keys->uni(row, col); 182 ushort c = keys->uni(row, col);
183 183
184 p.setPen(textcolor); 184 p.setPen(textcolor);
185 if (!pix) 185 if (!pix)
186 p.drawText(x, y, 186 p.drawText(x, y,
187 defaultKeyWidth * keyWidth, keyHeight, 187 defaultKeyWidth * keyWidth, keyHeight,
188 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); 188 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c);
189 else 189 else
190 // center the image in the middle of the key 190 // center the image in the middle of the key
191 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, 191 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2,
192 y + (keyHeight - pix->height())/2 + 1, 192 y + (keyHeight - pix->height())/2 + 1,
193 *pix ); 193 *pix );
194 194
195 // this fixes the problem that the very right end of the board's vertical line 195 // this fixes the problem that the very right end of the board's vertical line
196 // gets painted over, because it's one pixel shorter than all other keys 196 // gets painted over, because it's one pixel shorter than all other keys
197 p.setPen(keycolor_lines); 197 p.setPen(keycolor_lines);
198 p.drawLine(width() - 1, 0, width() - 1, height()); 198 p.drawLine(width() - 1, 0, width() - 1, height());
199 199
200 } else { 200 } else {
201 201
202 202
203 p.fillRect(0, 0, width(), height(), keycolor); 203 p.fillRect(0, 0, width(), height(), keycolor);
204 204
205 for (row = 1; row <= 5; row++) { 205 for (row = 1; row <= 5; row++) {
206 206
207 int x = 0; 207 int x = 0;
208 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 208 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
209 209
210 p.setPen(keycolor_lines); 210 p.setPen(keycolor_lines);
211 p.drawLine(x, y, x + width(), y); 211 p.drawLine(x, y, x + width(), y);
212 212
213 for (int col = 0; col < keys->numKeys(row); col++) { 213 for (int col = 0; col < keys->numKeys(row); col++) {
214 214
215 QPixmap *pix = keys->pix(row, col); 215 QPixmap *pix = keys->pix(row, col);
216 int keyWidth = keys->width(row, col); 216 int keyWidth = keys->width(row, col);
217 217
218 218
219 int keyWidthPix = defaultKeyWidth * keyWidth; 219 int keyWidthPix = defaultKeyWidth * keyWidth;
220 220
221 if (keys->pressed(row, col)) 221 if (keys->pressed(row, col))
222 p.fillRect(x+1, y+1, keyWidthPix - 1, 222 p.fillRect(x+1, y+1, keyWidthPix - 1,
223 keyHeight - 1, keycolor_pressed); 223 keyHeight - 1, keycolor_pressed);
224 224
225 ushort c = keys->uni(row, col); 225 ushort c = keys->uni(row, col);
226 226
227 if (!pix) { 227 if (!pix) {
228 p.setPen(textcolor); 228 p.setPen(textcolor);
229 p.drawText(x, y, 229 p.drawText(x, y,
230 keyWidthPix, keyHeight, 230 keyWidthPix, keyHeight,
231 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); 231 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c);
232 } 232 }
233 else { 233 else {
234 // center the image in the middle of the key 234 // center the image in the middle of the key
235 p.drawPixmap( x + (keyWidthPix - pix->width())/2, 235 p.drawPixmap( x + (keyWidthPix - pix->width())/2,
236 y + (keyHeight - pix->height())/2 + 1, 236 y + (keyHeight - pix->height())/2 + 1,
237 QPixmap(*pix) ); 237 QPixmap(*pix) );
238 } 238 }
239 239
240 p.setPen(keycolor_lines); 240 p.setPen(keycolor_lines);
241 p.drawLine(x, y, x, y + keyHeight); 241 p.drawLine(x, y, x, y + keyHeight);
242 242
243 x += keyWidthPix; 243 x += keyWidthPix;
244 } 244 }
245 245
246 246
247 } 247 }
248 p.drawLine(0, height() - 1, width(), height() - 1); 248 p.drawLine(0, height() - 1, width(), height() - 1);
249 p.drawLine(width() - 1, 0, width() - 1, height()); 249 p.drawLine(width() - 1, 0, width() - 1, height());
250 } 250 }
251 251
252} 252}
253 253
254 254
255/* Keyboard::mousePressEvent {{{1 */ 255/* Keyboard::mousePressEvent {{{1 */
256void Keyboard::mousePressEvent(QMouseEvent *e) 256void Keyboard::mousePressEvent(QMouseEvent *e)
257{ 257{
258 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; 258 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
259 if (row > 5) row = 5; 259 if (row > 5) row = 5;
260 260
261 // figure out the column 261 // figure out the column
262 int col = 0; 262 int col = 0;
263 for (int w = 0; e->x() >= w; col++) 263 for (int w = 0; e->x() >= w; col++)
264 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys 264 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys
265 w += keys->width(row,col) * defaultKeyWidth; 265 w += keys->width(row,col) * defaultKeyWidth;
266 else break; 266 else break;
267 267
268 if (col <= 0) return; 268 if (col <= 0) return;
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(setMapToDefault()), 289 connect(configdlg, SIGNAL(setMapToDefault()),
290 this, SLOT(setMapToDefault())); 290 this, SLOT(setMapToDefault()));
291 connect(configdlg, SIGNAL(setMapToFile(QString)), 291 connect(configdlg, SIGNAL(setMapToFile(QString)),
292 this, SLOT(setMapToFile(QString))); 292 this, SLOT(setMapToFile(QString)));
293 connect(configdlg, SIGNAL(pickboardToggled(bool)), 293 connect(configdlg, SIGNAL(pickboardToggled(bool)),
294 this, SLOT(togglePickboard(bool))); 294 this, SLOT(togglePickboard(bool)));
295 connect(configdlg, SIGNAL(repeatToggled(bool)), 295 connect(configdlg, SIGNAL(repeatToggled(bool)),
296 this, SLOT(toggleRepeat(bool))); 296 this, SLOT(toggleRepeat(bool)));
297 connect(configdlg, SIGNAL(reloadKeyboard()), 297 connect(configdlg, SIGNAL(reloadKeyboard()),
298 this, SLOT(reloadKeyboard())); 298 this, SLOT(reloadKeyboard()));
299 configdlg->showMaximized(); 299 configdlg->showMaximized();
300 configdlg->show(); 300 configdlg->show();
301 configdlg->raise(); 301 configdlg->raise();
302 } 302 }
303 303
304 } else if (qkeycode == Qt::Key_Control) { 304 } else if (qkeycode == Qt::Key_Control) {
305 ctrl = keys->pressedPtr(row, col); 305
306 need_repaint = TRUE; 306 if (ctrl) {
307 *ctrl = !keys->pressed(row, col); 307
308 *ctrl = 0;
309 ctrl = 0;
310
311 } else {
312
313 ctrl = keys->pressedPtr(row, col);
314 need_repaint = TRUE;
315 *ctrl = !keys->pressed(row, col);
316
317 }
308 318
309 } else if (qkeycode == Qt::Key_Alt) { 319 } else if (qkeycode == Qt::Key_Alt) {
310 alt = keys->pressedPtr(row, col); 320
311 need_repaint = TRUE; 321 if (alt) {
312 *alt = !keys->pressed(row, col); 322 *alt = 0;
323 alt = 0;
324
325 } else {
326
327 alt = keys->pressedPtr(row, col);
328 need_repaint = TRUE;
329 *alt = !keys->pressed(row, col);
330 }
313 331
314 } else if (qkeycode == Qt::Key_Shift) { 332 } else if (qkeycode == Qt::Key_Shift) {
315 need_repaint = TRUE; 333 need_repaint = TRUE;
316 334
317 if (shift) { 335 if (shift) {
318 *shift = 0; 336 *shift = 0;
319 shift = 0; 337 shift = 0;
320 } 338 }
321 else { 339 else {
322 shift = keys->pressedPtr(row, col); 340 shift = keys->pressedPtr(row, col);
323 *shift = 1; 341 *shift = 1;
324 if (lock) { 342 if (lock) {
325 *lock = 0; 343 *lock = 0;
326 lock = 0; 344 lock = 0;
327 } 345 }
328 } 346 }
329 347
330 } else if (qkeycode == Qt::Key_CapsLock) { 348 } else if (qkeycode == Qt::Key_CapsLock) {
331 need_repaint = TRUE; 349 need_repaint = TRUE;
332 350
333 if (lock) { 351 if (lock) {
334 *lock = 0; 352 *lock = 0;
335 lock = 0; 353 lock = 0;
336 } 354 }
337 else { 355 else {
338 lock = keys->pressedPtr(row, col);; 356 lock = keys->pressedPtr(row, col);;
339 *lock = 1; 357 *lock = 1;
340 if (shift) { 358 if (shift) {
341 *shift = 0; 359 *shift = 0;
342 shift = 0; 360 shift = 0;
343 } 361 }
344 } 362 }
345 363
346 } 364 }
347 365
348 } 366 }
349 else { // normal char 367 else { // normal char
350 if ((shift || lock) && keys->shift(unicode)) { 368 if ((shift || lock) && keys->shift(unicode)) {
351 unicode = keys->shift(unicode); 369 unicode = keys->shift(unicode);
352 } 370 }
353 } 371 }
354 372
355 // korean parsing 373 // korean parsing
356 if (keys->lang == "ko") { 374 if (keys->lang == "ko") {
357 375
358 unicode = parseKoreanInput(unicode); 376 unicode = parseKoreanInput(unicode);
359 } 377 }
360 378
361 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); 379 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
362 380
363 if ('A' <= unicode && unicode <= 'z' && modifiers) { 381 if ('A' <= unicode && unicode <= 'z' && modifiers) {
364 382
365 qkeycode = QChar(unicode).upper(); 383 qkeycode = QChar(unicode).upper();
366 unicode = qkeycode - '@'; 384 unicode = qkeycode - '@';
367 } 385 }
368 386
369 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); 387 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false);
370 388
371 // pickboard stuff 389 // pickboard stuff
372 if (usePicks) { 390 if (usePicks) {
373 391
374 KeyboardConfig *dc = picks->dc; 392 KeyboardConfig *dc = picks->dc;
375 393
376 if (dc) { 394 if (dc) {
377 if (qkeycode == Qt::Key_Backspace) { 395 if (qkeycode == Qt::Key_Backspace) {
378 dc->input.remove(dc->input.last()); // remove last input 396 dc->input.remove(dc->input.last()); // remove last input
379 dc->decBackspaces(); 397 dc->decBackspaces();
380 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { 398 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) {
381 dc->input.clear(); 399 dc->input.clear();
382 dc->resetBackspaces(); 400 dc->resetBackspaces();
383 } else { 401 } else {
384 dc->add(QString(QChar(unicode))); 402 dc->add(QString(QChar(unicode)));
385 dc->incBackspaces(); 403 dc->incBackspaces();
386 } 404 }
387 } 405 }
388 picks->repaint(); 406 picks->repaint();
389 } 407 }
390 408
391 409
392 // painting 410 // painting
393 pressed = TRUE; 411 pressed = TRUE;
394 412
395 pressedKeyRow = row; 413 pressedKeyRow = row;
396 pressedKeyCol = col; 414 pressedKeyCol = col;
397 415
398 if (need_repaint) repaint(FALSE); 416 if (need_repaint) repaint(FALSE);
399 else { // just paint the one key pressed 417 else { // just paint the one key pressed
400 418
401 419
402 420
403 QPainter p(this); 421 QPainter p(this);
404 drawKeyboard(p, row, col); 422 drawKeyboard(p, row, col);
405 423
406 } 424 }
407 425
408 if (useRepeat) repeatTimer->start( 800 ); 426 if (useRepeat) repeatTimer->start( 800 );
409 //pressTid = startTimer(80); 427 //pressTid = startTimer(80);
410 428
411} 429}
412 430
413 431
414/* Keyboard::mouseReleaseEvent {{{1 */ 432/* Keyboard::mouseReleaseEvent {{{1 */
415void Keyboard::mouseReleaseEvent(QMouseEvent*) 433void Keyboard::mouseReleaseEvent(QMouseEvent*)
416{ 434{
417 pressed = FALSE; 435 pressed = FALSE;
418 //if ( pressTid == 0 ) 436 //if ( pressTid == 0 )
419#if defined(Q_WS_QWS) || defined(_WS_QWS_) 437#if defined(Q_WS_QWS) || defined(_WS_QWS_)
420 if ( unicode != -1 ) { 438 if ( unicode != -1 ) {
421 emit key( unicode, qkeycode, modifiers, false, false ); 439 emit key( unicode, qkeycode, modifiers, false, false );
422 repeatTimer->stop(); 440 repeatTimer->stop();
423 } 441 }
424#endif 442#endif
425 if (shift && unicode != 0) { 443 if (shift && unicode != 0) {
426 444
427 445
428 *shift = 0; // unpress shift key 446 *shift = 0; // unpress shift key
429 shift = 0; // reset the shift pointer 447 shift = 0; // reset the shift pointer
430 repaint(FALSE); 448 repaint(FALSE);
431 449
432 } 450 }
433 else 451 else
434 452
435 clearHighlight(); 453 clearHighlight();
436} 454}
437 455
438/* Keyboard::timerEvent {{{1 */ 456/* Keyboard::timerEvent {{{1 */
439 457
440/* dont know what this does, but i think it is here so that if your screen 458/* dont know what this does, but i think it is here so that if your screen