Qt key handling

Fix the popup versions of qt_yn_function() to handle control
characters by using the same key press event decoding routine
and menus and extended commands.  Moves 'keyValue()' to
qt_key.cpp and its declaration to qt_key.h, requring several
files to start using #include "qt_key.h".

'make depend' update to follow.
This commit is contained in:
PatR
2021-01-08 13:47:34 -08:00
parent 129ff12245
commit 2c02d5daac
6 changed files with 47 additions and 30 deletions
+6 -7
View File
@@ -16,6 +16,7 @@ extern "C" {
#include "qt_post.h"
#include "qt_yndlg.h"
#include "qt_yndlg.moc"
#include "qt_key.h" // for keyValue()
#include "qt_str.h"
// temporary
@@ -369,14 +370,12 @@ void NetHackQtYnDialog::AltChoice(char ans, char res)
}
}
void NetHackQtYnDialog::keyPressEvent(QKeyEvent* event)
void NetHackQtYnDialog::keyPressEvent(QKeyEvent *event)
{
keypress = '\0';
QString text(event->text());
if (text.isEmpty()) /* && event->modifiers()) */
keypress = keyValue(event);
if (!keypress)
return;
keypress = text.at(0).cell();
char *p = NULL;
if (*alt_answer && (p = strchr(alt_answer, keypress)) != 0)
keypress = alt_result[p - alt_answer];
@@ -388,13 +387,13 @@ void NetHackQtYnDialog::keyPressEvent(QKeyEvent* event)
int where = QString::fromLatin1(choices).indexOf(QChar(keypress));
if (allow_count && strchr("#0123456789", keypress)) {
if (text == "#") {
if (keypress == '#') {
// 0 will be preselected; typing anything replaces it
le->setText(QString("0"));
le->home(true);
} else {
// digit will not be preselected; typing another appends
le->setText(text);
le->setText(QChar(keypress));
le->end(false);
}
// (don't know whether this actually does anything useful)