WvStreams
|
00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * A Qt object that invokes its callback whenever it receives 00006 * an event. This is useful for deferring processing to the 00007 * Qt event loop. Use it to avoid problems resulting from the 00008 * non-reentrant nature of WvStream::execute(). 00009 */ 00010 #include "wvqthook.moc" 00011 00012 WvQtHook::WvQtHook(WvQtHookCallback _callback) : 00013 callback(_callback) 00014 { 00015 } 00016 00017 00018 void WvQtHook::setcallback(WvQtHookCallback _callback) 00019 { 00020 callback = _callback; 00021 } 00022 00023 00024 bool WvQtHook::event(QEvent *event) 00025 { 00026 if (! callback) 00027 return false; 00028 QEvent::Type eventtype = event->type(); 00029 if (eventtype < QEvent::User || eventtype > QEvent::MaxUser) 00030 return false; 00031 QCustomEvent *ce = static_cast<QCustomEvent*>(event); 00032 callback(*this, eventtype - QEvent::User, ce->data()); 00033 return true; 00034 } 00035 00036 00037 void WvQtHook::post(int type, void *data) 00038 { 00039 // event must be allocated on heap for postEvent 00040 QEvent::Type eventtype = QEvent::Type(QEvent::User + type); 00041 QCustomEvent *event = new QCustomEvent(eventtype, data); 00042 QApplication::postEvent(this, event); 00043 } 00044 00045 00046 void WvQtHook::send(int type, void *data) 00047 { 00048 QEvent::Type eventtype = QEvent::Type(QEvent::User + type); 00049 QCustomEvent event(eventtype, data); 00050 QApplication::sendEvent(this, & event); 00051 }