Back to index

salome-gui  6.5.0
SALOME_EventFilter.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "SALOME_EventFilter.h"
00021 #include "SALOME_Event.h"
00022 
00023 #include <QApplication>
00024 
00025 SALOME_EventFilter* SALOME_EventFilter::myFilter = NULL;
00026 
00028 SALOME_EventFilter::SALOME_EventFilter()
00029 : QObject()
00030 {
00031   /* VSR 13/01/03 : installing global event filter for the application */
00032   qApp->installEventFilter( this );
00033 }
00034 
00036 SALOME_EventFilter::~SALOME_EventFilter()
00037 {
00038   qApp->removeEventFilter( this );
00039 }
00040 
00044 bool SALOME_EventFilter::eventFilter( QObject* o, QEvent* e )
00045 {
00046   if ( e->type() == SALOME_EVENT )
00047   { 
00048     SALOME_Event* aSE = (SALOME_Event*)((SALOME_CustomEvent*)e)->data();
00049     processEvent(aSE);
00050     ((SALOME_CustomEvent*)e)->setData( 0 );
00051     return true;
00052   }
00053   return QObject::eventFilter( o, e );
00054 }
00055 
00057 void SALOME_EventFilter::processEvent( SALOME_Event* theEvent )
00058 {
00059   if(theEvent)
00060     theEvent->ExecutePostedEvent();
00061 }
00062 
00064 void SALOME_EventFilter::Init()
00065 {
00066   if( myFilter==NULL )
00067     myFilter = new SALOME_EventFilter();
00068 }
00069 
00071 void SALOME_EventFilter::Destroy()
00072 {
00073   if( myFilter )
00074   {
00075     delete myFilter;
00076     myFilter = NULL;
00077   }
00078 }