Changeset 859

Show
Ignore:
Timestamp:
06/04/07 05:31:03 (2 years ago)
Author:
ok_computer
Message:

Adding a work-around for corrupt key event text when the SDL widget is active. This appears to be related to some sort of timing issue with the Qt event loop. Lower-case keys are transposed to upper-case. This is most marked when playback is active.

Note that the work-around is not active by default.

Location:
trunk/jahwidgets/src/qt3
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/jahwidgets/src/qt3/python/application.cpp

    r826 r859  
    6868        .def( "processEventsCallback", &jw::_application::processEventsCallback ) 
    6969        .def( "hasPendingEventsCallback", &jw::_application::hasPendingEventsCallback ) 
     70        .def( "setFixupKeyEvents", &jw::_application::setFixupKeyEvents ) 
    7071        ; 
    7172} 
  • trunk/jahwidgets/src/qt3/wrapper/application.cpp

    r828 r859  
    5252}; 
    5353 
     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. 
     59class Application : public QApplication 
     60{ 
     61public: 
     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 
    54104/// trivial opaque wrapper for QApplication 
    55105application::application() 
     
    59109         
    60110        static EventLoop el; 
    61         static QApplication app( dummy_argc, dummy_argv ); 
     111        static Application app( dummy_argc, dummy_argv ); 
    62112        el.app_ = this; 
    63113 
     
    180230} 
    181231 
     232void application::setFixupKeyEvents( bool fix ) 
     233{ 
     234        dynamic_cast<Application*>(qApp)->fixupKeyEvents = fix; 
     235} 
     236 
    182237} } 
  • trunk/jahwidgets/src/qt3/wrapper/application.hpp

    r826 r859  
    4343    virtual bool hasPendingEventsCallback(); 
    4444 
     45        /// Indicate that we want the app to work-around corrupt key-events. 
     46        /// The default is not to apply this work-around 
     47        void setFixupKeyEvents( bool ); 
     48 
    4549public slots: 
    4650    /// Called just before the app quits. Subclasses can override to receive notification