Back to index

salome-gui  6.5.0
LightApp_EventFilter.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "LightApp_EventFilter.h"
00024 
00025 #include <SUIT_Desktop.h>
00026 
00027 #include <QApplication>
00028 
00029 #include <SALOME_Event.h>
00030 
00031 LightApp_EventFilter* LightApp_EventFilter::myFilter = NULL;
00032 
00034 LightApp_EventFilter::LightApp_EventFilter()
00035 : QObject()
00036 {
00037   qApp->installEventFilter( this );
00038 }
00039 
00041 LightApp_EventFilter::~LightApp_EventFilter()
00042 {
00043   qApp->removeEventFilter( this );
00044 }
00045 
00049 bool LightApp_EventFilter::eventFilter( QObject* o, QEvent* e )
00050 {
00051   if ( e->type() == QEvent::WindowActivate && o->inherits("QDialog") )
00052     {
00053       QWidget* parent = ((QWidget*)o)->parentWidget();
00054       
00055       SUIT_Desktop* aDesktop = 0;
00056       
00057       while( parent )
00058         {
00059           aDesktop = dynamic_cast<SUIT_Desktop*>(parent);
00060           if ( aDesktop )
00061             break;
00062           parent = parent->parentWidget();
00063         }
00064       
00065       if ( aDesktop )
00066         aDesktop->emitActivated();
00067     }
00068 
00069   else if(e->type() == SALOME_EVENT)
00070     {
00071       SALOME_Event* aSE = (SALOME_Event*)((SALOME_CustomEvent*)e)->data();
00072       processEvent(aSE);
00073       ((SALOME_CustomEvent*)e)->setData( 0 );
00074       return true;
00075     }
00076   
00077   return QObject::eventFilter( o, e );
00078 }
00079 
00081 void LightApp_EventFilter::processEvent( SALOME_Event* theEvent )
00082 {
00083   if(theEvent)
00084     theEvent->ExecutePostedEvent();
00085 }
00086 
00087 
00089 void LightApp_EventFilter::Init()
00090 {
00091   if( myFilter==NULL )
00092     myFilter = new LightApp_EventFilter();
00093 }
00094 
00096 void LightApp_EventFilter::Destroy()
00097 {
00098   if( myFilter )
00099   {
00100     delete myFilter;
00101     myFilter = NULL;
00102   }
00103 }