Back to index

salome-gui  6.5.0
LightApp_SwitchOp.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_SwitchOp.h"
00024 #include "LightApp_Module.h"
00025 #include "LightApp_Operation.h"
00026 #include "LightApp_Dialog.h"
00027 #include <CAM_Application.h>
00028 #include <SUIT_Operation.h>
00029 #include <SUIT_Study.h>
00030 
00031 #include <QEvent>
00032 #include <QWidget>
00033 #include <QList>
00034 #include <QApplication>
00035 
00043 LightApp_SwitchOp::LightApp_SwitchOp( LightApp_Module* theModule )
00044 : QObject( 0 ),
00045   myModule( theModule )
00046 {
00047   qApp->installEventFilter( this );
00048 }
00049 
00053 LightApp_SwitchOp::~LightApp_SwitchOp()
00054 {
00055   
00056 }
00057 
00063 LightApp_Module* LightApp_SwitchOp::module() const
00064 {
00065   return myModule;
00066 }
00067 
00074 SUIT_Study* LightApp_SwitchOp::study() const
00075 {
00076   return module()->application()->activeStudy();
00077 }
00078 
00086 LightApp_Operation* LightApp_SwitchOp::operation( QWidget* theWg ) const
00087 {
00088   // get dialog from widget
00089   LightApp_Dialog* aDlg = 0;
00090   QWidget* aParent = theWg;
00091   while( aParent && !aParent->inherits( "LightApp_Dialog" ) )
00092     aParent = aParent->parentWidget();
00093 
00094   if ( aParent && aParent->inherits( "LightApp_Dialog" ) )
00095     aDlg = (LightApp_Dialog*)aParent;
00096 
00097   // try to find operation corresponding to the dialog
00098   if ( aDlg != 0 && study() != 0 )
00099   {
00100     QListIterator<SUIT_Operation*> anIter( study()->operations() );
00101     while( anIter.hasNext() )
00102     {
00103       SUIT_Operation* anOp = anIter.next();
00104           
00105       if ( anOp &&
00106            anOp->inherits( "LightApp_Operation" ) &&
00107            ((LightApp_Operation*)anOp)->dlg() == aDlg )
00108         return ((LightApp_Operation*)anOp);
00109     }
00110   }
00111 
00112   return 0;
00113 }
00114 
00123 bool LightApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv )
00124 {
00125   if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) )
00126   {
00127     QEvent::Type aType = theEv->type();
00128     LightApp_Operation* anOp = operation( (QWidget*)theObj );
00129     if ( anOp )
00130     {
00131       switch ( aType )
00132       {
00133         case QEvent::Enter:
00134         {
00135           if ( !anOp->isActive() && anOp->isAutoResumed() &&
00136                study() && !study()->blockingOperation( anOp ) )
00137             study()->resume( anOp );
00138         }
00139         break;
00140         
00141         case QEvent::MouseButtonRelease:
00142         case QEvent::MouseButtonPress:
00143         case QEvent::MouseButtonDblClick:
00144         case QEvent::MouseMove:
00145         case QEvent::KeyPress:
00146         case QEvent::KeyRelease:
00147         {
00148           if ( !anOp->isActive() )
00149             return true;
00150         }
00151         break;
00152         
00153       }
00154     }
00155   }
00156 
00157   return QObject::eventFilter( theObj, theEv );
00158 }
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177