Salome HOME
Columns in object browser
[modules/gui.git] / src / SalomeApp / SalomeApp_EventFilter.cxx
1
2 #include "SalomeApp_EventFilter.h"
3 #include <SALOME_Event.hxx>
4
5 #include <qapplication.h>
6
7 SalomeApp_EventFilter* SalomeApp_EventFilter::myFilter = NULL;
8
9 SalomeApp_EventFilter::SalomeApp_EventFilter()
10 : QObject()
11 {
12   /* VSR 13/01/03 : installing global event filter for the application */
13   qApp->installEventFilter( this );
14 }
15
16 SalomeApp_EventFilter::~SalomeApp_EventFilter()
17 {
18   qApp->removeEventFilter( this );
19 }
20
21 bool SalomeApp_EventFilter::eventFilter( QObject* o, QEvent* e )
22 {
23   if ( e->type() == SALOME_EVENT )
24   { 
25     SALOME_Event* aSE = (SALOME_Event*)((QCustomEvent*)e)->data();
26     processEvent(aSE);
27     ((QCustomEvent*)e)->setData( 0 );
28     return true;
29   }
30   return QObject::eventFilter( o, e );
31 }
32
33 void SalomeApp_EventFilter::processEvent( SALOME_Event* theEvent )
34 {
35   if(theEvent){
36     theEvent->Execute();
37     // Signal the calling thread that the event has been processed
38     theEvent->processed();
39   }
40 }
41
42 void SalomeApp_EventFilter::Init()
43 {
44   if( myFilter==NULL )
45     myFilter = new SalomeApp_EventFilter();
46 }
47
48 void SalomeApp_EventFilter::Destroy()
49 {
50   if( myFilter )
51   {
52     delete myFilter;
53     myFilter = NULL;
54   }
55 }