| 380 | } |
| 381 | |
| 382 | void NetHackQtYnDialog::keyPressEvent(QKeyEvent *event) |
| 383 | { |
| 384 | keypress = keyValue(event); |
| 385 | if (!keypress) |
| 386 | return; |
| 387 | |
| 388 | char *p = NULL; |
| 389 | if (*alt_answer && (p = strchr(alt_answer, keypress)) != 0) |
| 390 | keypress = alt_result[p - alt_answer]; |
| 391 | |
| 392 | if (!choices || !*choices || !keypress) { |
| 393 | this->done(1); |
| 394 | |
| 395 | } else { |
| 396 | int where = QString::fromLatin1(choices).indexOf(QChar(keypress)); |
| 397 | |
| 398 | if (allow_count && strchr("#0123456789", keypress)) { |
| 399 | if (keypress == '#') { |
| 400 | // 0 will be preselected; typing anything replaces it |
| 401 | le->setText(QString("0")); |
| 402 | le->home(true); |
| 403 | } else { |
| 404 | // digit will not be preselected; typing another appends |
| 405 | le->setText(QChar(keypress)); |
| 406 | le->end(false); |
| 407 | } |
| 408 | // (don't know whether this actually does anything useful) |
| 409 | le->setAttribute(Qt::WA_KeyboardFocusChange, true); |
| 410 | // this is definitely useful... |
| 411 | le->setFocus(Qt::ActiveWindowFocusReason); |
| 412 | // change default button from 'n' to 'y' |
| 413 | if (y_btn) |
| 414 | y_btn->setDefault(true); |
| 415 | } else if (where != -1) { |
| 416 | this->done(where + 1000); |
| 417 | |
| 418 | } else { |
| 419 | QDialog::keyPressEvent(event); |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | void NetHackQtYnDialog::doneItem(int i) |
| 425 | { |