MCPcopy Create free account
hub / github.com/NetHack/NetHack / notify

Method notify

win/Qt/qt_bind.cpp:1110–1173  ·  view source on GitHub ↗

event loop callback

Source from the content-addressed store, hash-verified

1108
1109// event loop callback
1110bool NetHackQtBind::notify(QObject *receiver, QEvent *event)
1111{
1112 // Ignore Alt-key navigation to menubar, it's annoying when you
1113 // use Alt-Direction to move around.
1114 if (main && receiver == main && event->type() == QEvent::KeyRelease
1115 && ((QKeyEvent *) event)->key() == Qt::Key_Alt)
1116 return true;
1117
1118 bool result = QApplication::notify(receiver, event);
1119 int evtyp = event->type();
1120
1121 if (evtyp == QEvent::KeyPress) {
1122 QKeyEvent *key_event = (QKeyEvent *) event;
1123
1124 if (!key_event->isAccepted()) {
1125 Qt::KeyboardModifiers mod = key_event->modifiers();
1126 const int k = key_event->key();
1127 for (int i = 0; key_macro[i].key; i++) {
1128 if (key_macro[i].key == k
1129 && ((key_macro[i].state & mod) == key_macro[i].state)) {
1130 // matched macro; put its expansion into the input buffer
1131 keybuffer.Put(!::iflags.num_pad ? key_macro[i].macro
1132 : key_macro[i].numpad_macro);
1133 key_event->accept();
1134 qApp->exit();
1135 return true;
1136 }
1137 }
1138 QString key = key_event->text();
1139 QChar ch = !key.isEmpty() ? key.at(0) : QChar(0);
1140 if (ch > QChar(128))
1141 ch = QChar(0);
1142 // on OSX, ascii control codes are not sent, force them
1143 if (ch == 0 && (mod & Qt::ControlModifier) != 0) {
1144 if (k >= Qt::Key_A && k <= Qt::Key_Underscore)
1145 ch = (QChar) (k - (Qt::Key_A - 1));
1146 }
1147 //raw_printf("notify()=%d \"%s\"", k, visctrl(ch.cell()));
1148 // if we have a valid character, queue it up
1149 if (ch != 0) {
1150 bool alt = ((mod & Qt::AltModifier) != 0
1151 || (k >= Qt::Key_0 && k <= Qt::Key_9
1152 && (mod & Qt::ControlModifier) != 0));
1153 keybuffer.Put(k, ch.cell() + (alt ? 128 : 0), (uint) mod);
1154 key_event->accept();
1155 qApp->exit();
1156 result = true;
1157 }
1158
1159#if 0 /* this was a failed attempt to prevent qt_more() from looping
1160 * after command+q (on OSX) is used to bring up the quit dialog;
1161 * now qt_more() uses an early return if program_state.gameover
1162 * is set */
1163 } else if (evtyp == QEvent::FocusOut
1164 || evtyp == QEvent::ShortcutOverride
1165 || evtyp == QEvent::PlatformSurface) {
1166 // leave qt_nhgetch()'s event loop if focus switches somewhere else
1167 qApp->exit();

Callers

nothing calls this directly

Calls 1

PutMethod · 0.45

Tested by

no test coverage detected