Changeset 880

Show
Ignore:
Timestamp:
07/06/07 09:29:15 (2 years ago)
Author:
timdewhirst
Message:

jahwidgets
- optimization: allow property changes on the gui thread to make a
direct call

Location:
trunk/jahwidgets/src/qt3/wrapper
Files:
2 modified

Legend:

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

    r859 r880  
    2222#include <functional> 
    2323 
     24// local 
     25#include "utils/thread_util.hpp" 
     26 
    2427namespace jahwidgets { namespace qt3 { 
    2528 
     
    5255}; 
    5356 
    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. 
     57// We subclass QApplication only to workaround a bug on windows with 
     58// key events.  It appears that in-corporating playback into the app's 
     59// event loop is causing some timing issues with Qt keyboard event 
     60// handling (note that the problems could also be due to SDL 
     61// interferring with the event, but this doesn't appear to be the 
     62// case). The symptons are thus:  
     63// * When a clip is not playing most key event text is correct, 
     64//   although occasionaly a lowercase char becomes uppercase 
     65// * When playing back most chars are transposed to upper case.  Only 
     66//   the key event's text is incorrect; the key code and modifier appear 
     67//   to always be ok. 
    5968class Application : public QApplication 
    6069{ 
     
    111120        static Application app( dummy_argc, dummy_argv ); 
    112121        el.app_ = this; 
     122         
     123        initialize_gui_thread(); 
    113124 
    114125#if defined( Q_OS_MACX ) && !defined(DEBUG) 
  • trunk/jahwidgets/src/qt3/wrapper/property_adapter.hpp

    r843 r880  
    1515#include "utils/string_utils.hpp" 
    1616#include "utils/image_utils.hpp" 
     17#include "utils/thread_util.hpp" 
    1718 
    1819// boost 
     
    6768                  m_slotMemFn( const_cast< NAME##_adapter* >( this ), &internal_adapter::onWidgetChanged )                      \ 
    6869        {                                                                                                                                                                                                               \ 
    69         owner->installEventFilter( this );                                                                  \ 
    70                                                                                                             \ 
     70                owner->installEventFilter( this );                                                                                                                                      \ 
     71                                                                                                                                                                                                                        \ 
    7172                if ( isQtPropertyWritable() )                                                                                                                                           \ 
    7273                {                                                                                                                                                                                                       \ 
    73                         m_observer = boost::shared_ptr< pcos::observer >( new MemFnObserver< NAME##_adapter >                   \ 
     74                  m_observer = boost::shared_ptr< pcos::observer >( new MemFnObserver< NAME##_adapter >                         \ 
    7475                        ( const_cast< NAME##_adapter* >( this ),                                                                                                                \ 
    7576                          &NAME##_adapter::onPropertyChanged ) );                                                                                                               \ 
    7677                        m_pcosProperty.attach( m_observer );                                                                                                                    \ 
    7778                }                                                                                                                                                                                                       \ 
    78                                                                                                                                                                                     \ 
    79                 QString signature = QString( "%1%2" ).arg( qtprop ).arg( "_changed()" );                            \ 
    80                 if ( !doesSignalExist( signature ) ) {                                                                                          \ 
    81                         signature = signalSignatureForProp( qtprop );                                                                   \ 
    82                 }                                                                                                                                                               \ 
    83                                                                                                                                                                                     \ 
     79                                                                                                                                                                                                                        \ 
     80                QString signature = QString( "%1%2" ).arg( qtprop ).arg( "_changed()" );                                                        \ 
     81                if ( !doesSignalExist( signature ) ) {                                                                                                                          \ 
     82                        signature = signalSignatureForProp( qtprop );                                                                                                   \ 
     83                }                                                                                                                                                                                                       \ 
     84                                                                                                                                                                                                                        \ 
    8485                QString signal = QString( "%1%2" ).arg( QSIGNAL_CODE ).arg( signature );                                                        \ 
    8586                if ( doesSignalExist( signature ) )                                                                                                                                     \ 
    8687                {                                                                                                                                                                                                       \ 
    87                         if ( !signature.endsWith( "_changed()" ) )                                                                          \ 
    88                                 qDebug( "connecting Qt signal %s -> %s", signature.latin1(), qtprop );                      \ 
    89                                                                                                                                                                                     \ 
    90                         m_slotMemFn.connect( m_notifier, signal, SLOT( notify() ) );                                    \ 
    91                 }                                                                                                                                                                   \ 
     88                        if ( !signature.endsWith( "_changed()" ) )                                                                                                              \ 
     89                                qDebug( "connecting Qt signal %s -> %s", signature.latin1(), qtprop );                                          \ 
     90                                                                                                                                                                                                                        \ 
     91                        m_slotMemFn.connect( m_notifier, signal, SLOT( notify() ) );                                                                    \ 
     92                }                                                                                                                                                                                                       \ 
    9293        }                                                                                                                                                                                                               \ 
    9394                                                                                                                                                                                                                        \ 
     
    9899                m_pcosProperty.unblock( m_observer );                                                                                                                           \ 
    99100        }                                                                                                                                                                                                               \ 
    100                                                                                                             \ 
    101 protected:                                                                                                  \ 
    102     bool eventFilter( QObject*, QEvent* e )                                                                 \ 
    103     {                                                                                                       \ 
    104                 if ( (int)e->type() == WH_PROPERTY )                                                                \ 
    105                 {                                                                                                   \ 
    106                         PropertyEvent* pe = static_cast< PropertyEvent* >( e );                                         \ 
    107                         m_owner->setProperty( pe->name_, pe->value_ );                                                  \ 
    108                         return true;                                                                                    \ 
    109                 }                                                                                                   \ 
    110                                                                                                             \ 
    111                 return false;                                                                                       \ 
    112         }                                                                                                       \ 
    113                                                                                                             \ 
     101                                                                                                                                                                                                                        \ 
     102protected:                                                                                                                                                                                                      \ 
     103        bool eventFilter( QObject*, QEvent* e )                                                                                                                                 \ 
     104        {                                                                                                                                                                                                               \ 
     105                if ( (int)e->type() == WH_PROPERTY )                                                                                                                            \ 
     106                {                                                                                                                                                                                                       \ 
     107                        PropertyEvent* pe = static_cast< PropertyEvent* >( e );                                                                                 \ 
     108                        m_owner->setProperty( pe->name_, pe->value_ );                                                                                                  \ 
     109                        return true;                                                                                                                                                                    \ 
     110                }                                                                                                                                                                                                       \ 
     111                                                                                                                                                                                                                        \ 
     112                return false;                                                                                                                                                                           \ 
     113        }                                                                                                                                                                                                               \ 
     114                                                                                                                                                                                                                        \ 
    114115private:                                                                                                                                                                                                        \ 
    115116        void onPropertyChanged()                                                                                                                                                                \ 
    116         {                                                                                                                           \ 
    117                 QApplication::postEvent( m_owner,                                                                   \ 
    118                                                                  new PropertyEvent( m_qtPropertyName,                                       \ 
    119                                                                                                         CONVERT_FROM( m_pcosProperty.value< TYPE >() ) ) );     \ 
    120         }                                                                                                       \ 
     117        {                                                                                                                                                                                                               \ 
     118                if ( !is_gui_thread() )                                                                                                                                                         \ 
     119                        QApplication::postEvent( m_owner,                                                                                                                               \ 
     120                                                                         new PropertyEvent( m_qtPropertyName,                                                                   \ 
     121                                                                                                                CONVERT_FROM( m_pcosProperty.value< TYPE >() ) ) ); \ 
     122                else                                                                                                                                                                                            \ 
     123                        m_owner->setProperty( m_qtPropertyName, CONVERT_FROM( m_pcosProperty.value< TYPE >() ) );               \ 
     124        }                                                                                                                                                                                                               \ 
    121125                                                                                                                                                                                                                        \ 
    122126        boost::shared_ptr< pcos::observer > m_observer;                                                                                                                 \ 
     
    124128}; 
    125129 
    126 #define DEFINE_INTERNAL_ADAPTER_SPECIALIZATION( name, variantAccessor ) DEFINE_INTERNAL_ADAPTER_SPECIALIZATION2( name, name, variantAccessor ) 
    127  
    128 /// \note if any new types are required to be mapped from pcos to python, this 
    129 /// section must be updated accordingly 
    130  
    131 DEFINE_INTERNAL_ADAPTER_SPECIALIZATION( int, toInt ) 
    132 DEFINE_INTERNAL_ADAPTER_SPECIALIZATION( double, toDouble ) 
    133 DEFINE_INTERNAL_ADAPTER_SPECIALIZATION( bool, toBool ) 
    134  
    135 #undef CONVERT_TO 
    136 #undef CONVERT_FROM 
    137 #define CONVERT_TO( a ) QStringToWString::convert( a ) 
    138 #define CONVERT_FROM( a ) WStringToQString::convert( a ) 
    139 DEFINE_INTERNAL_ADAPTER_SPECIALIZATION2( string, pl::wstring, toString ) 
    140  
    141 #undef CONVERT_TO 
    142 #undef CONVERT_FROM 
    143 #define CONVERT_TO( a ) QStringListToWStringList::convert( a ) 
    144 #define CONVERT_FROM( a ) WStringListToQStringList::convert( a ) 
    145 DEFINE_INTERNAL_ADAPTER_SPECIALIZATION2( stringlist, pl::wstring_list, toStringList ) 
    146130 
    147131static pcos::int_list QValueListIntToPcosIntList( const QValueList<QVariant>& value_list ) 
     
    169153} 
    170154 
     155static il::image_type_ptr qpixmap_to_image_type_ptr( const QPixmap& p ) 
     156{ 
     157        return qimage_to_image( p.convertToImage() ); 
     158} 
     159 
     160static QPixmap image_type_ptr_to_qpixmap( il::image_type_ptr im ) 
     161{ 
     162        QPixmap result; 
     163        result.convertFromImage( image_to_qimage( im ) ); 
     164        return result; 
     165} 
     166 
     167#define DEFINE_INTERNAL_ADAPTER_SPECIALIZATION( name, variantAccessor ) DEFINE_INTERNAL_ADAPTER_SPECIALIZATION2( name, name, variantAccessor ) 
     168 
     169/// \note if any new types are required to be mapped from pcos to python, this 
     170/// section must be updated accordingly 
     171 
     172DEFINE_INTERNAL_ADAPTER_SPECIALIZATION( int, toInt ) 
     173DEFINE_INTERNAL_ADAPTER_SPECIALIZATION( double, toDouble ) 
     174DEFINE_INTERNAL_ADAPTER_SPECIALIZATION( bool, toBool ) 
     175 
     176#undef CONVERT_TO 
     177#undef CONVERT_FROM 
     178#define CONVERT_TO( a ) QStringToWString::convert( a ) 
     179#define CONVERT_FROM( a ) WStringToQString::convert( a ) 
     180DEFINE_INTERNAL_ADAPTER_SPECIALIZATION2( string, pl::wstring, toString ) 
     181 
     182#undef CONVERT_TO 
     183#undef CONVERT_FROM 
     184#define CONVERT_TO( a ) QStringListToWStringList::convert( a ) 
     185#define CONVERT_FROM( a ) WStringListToQStringList::convert( a ) 
     186DEFINE_INTERNAL_ADAPTER_SPECIALIZATION2( stringlist, pl::wstring_list, toStringList ) 
     187 
    171188#undef CONVERT_TO 
    172189#undef CONVERT_FROM 
     
    175192DEFINE_INTERNAL_ADAPTER_SPECIALIZATION2( intlist, pcos::int_list, toList ) 
    176193 
    177 static il::image_type_ptr qpixmap_to_image_type_ptr( const QPixmap& p ) 
    178 { 
    179         return qimage_to_image( p.convertToImage() ); 
    180 } 
    181  
    182 static QPixmap image_type_ptr_to_qpixmap( il::image_type_ptr im ) 
    183 { 
    184         QPixmap result; 
    185         result.convertFromImage( image_to_qimage( im ) ); 
    186         return result; 
    187 } 
    188  
    189194#undef CONVERT_TO 
    190195#undef CONVERT_FROM