Salome HOME
Fix a bug : wrong dialog icon name
[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 /*!Constructor.*/
10 SalomeApp_EventFilter::SalomeApp_EventFilter()
11 : QObject()
12 {
13   /* VSR 13/01/03 : installing global event filter for the application */
14   qApp->installEventFilter( this );
15 }
16
17 /*!Destructor.*/
18 SalomeApp_EventFilter::~SalomeApp_EventFilter()
19 {
20   qApp->removeEventFilter( this );
21 }
22
23 bool SalomeApp_EventFilter::eventFilter( QObject* o, QEvent* e )
24 {
25   if ( e->type() == SALOME_EVENT )
26   { 
27     SALOME_Event* aSE = (SALOME_Event*)((QCustomEvent*)e)->data();
28     processEvent(aSE);
29     ((QCustomEvent*)e)->setData( 0 );
30     return true;
31   }
32   return QObject::eventFilter( o, e );
33 }
34
35 /*!Process event.*/
36 void SalomeApp_EventFilter::processEvent( SALOME_Event* theEvent )
37 {
38   if(theEvent){
39     theEvent->Execute();
40     // Signal the calling thread that the event has been processed
41     theEvent->processed();
42   }
43 }
44
45 /*!Create new instance of SalomeApp_EventFilter*/
46 void SalomeApp_EventFilter::Init()
47 {
48   if( myFilter==NULL )
49     myFilter = new SalomeApp_EventFilter();
50 }
51
52 /*!Destroy filter.*/
53 void SalomeApp_EventFilter::Destroy()
54 {
55   if( myFilter )
56   {
57     delete myFilter;
58     myFilter = NULL;
59   }
60 }