| | 54 | // We subclass QApplication only to workaround a bug on windows with key events. |
| | 55 | // It appears that in-corporating playback into the app's event loop is causing some timing issues with Qt keyboard event handling (note that the problems could also be due to SDL interferring with the event, but this doesn't appear to be the case). The symptons are thus: |
| | 56 | // * When a clip is not playing most key event text is correct, although occasionaly a lowercase char becomes uppercase |
| | 57 | // * When playing back most chars are transposed to upper case. |
| | 58 | // Only the key event's text is incorrect; the key code and modifier appear to always be ok. |
| | 59 | class Application : public QApplication |
| | 60 | { |
| | 61 | public: |
| | 62 | Application ( int & argc, char ** argv ) |
| | 63 | : QApplication( argc, argv ), |
| | 64 | fixupKeyEvents( false ) |
| | 65 | {} |
| | 66 | |
| | 67 | // We only need to check the key events on win32 |
| | 68 | #if defined( Q_OS_WIN32 ) |
| | 69 | virtual bool notify( QObject* receiver, QEvent* event ) |
| | 70 | { |
| | 71 | // Check key events, and ensure that their text is correct |
| | 72 | if ( fixupKeyEvents |
| | 73 | && (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) ) |
| | 74 | { |
| | 75 | QKeyEvent* ke = dynamic_cast<QKeyEvent*>(event); |
| | 76 | if ( (ke->state() & Qt::ShiftButton) != Qt::ShiftButton |
| | 77 | // Qt always stores letters as uppercase |
| | 78 | && ke->key() >= 'A' && ke->key() <= 'Z' |
| | 79 | && ke->text().length() == 1 ) |
| | 80 | { |
| | 81 | //qDebug( "Correcting QKeyEvent: %s", ke->text().latin1() ); |
| | 82 | |
| | 83 | // Create a new event with the correct text |
| | 84 | QKeyEvent correctEvent( ke->type(), |
| | 85 | ke->key(), |
| | 86 | ke->ascii(), |
| | 87 | ke->state(), |
| | 88 | // Note that this is NOT unicode safe... |
| | 89 | QChar( char(ke->key() + 32) ), |
| | 90 | ke->isAutoRepeat(), |
| | 91 | ke->count() ); |
| | 92 | return QApplication::notify( receiver, &correctEvent ); |
| | 93 | } |
| | 94 | } |
| | 95 | |
| | 96 | return QApplication::notify( receiver, event ); |
| | 97 | } |
| | 98 | #endif |
| | 99 | |
| | 100 | // Flag to switch on/off the keyevent fixup |
| | 101 | bool fixupKeyEvents; |
| | 102 | }; |
| | 103 | |