1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
22 * Copyright (C) 2005 CEA/DEN, EDF R&D
26 * File : LightApp_SwitchOp.h
27 * Author : Sergey LITONIN
31 #include "LightApp_SwitchOp.h"
32 #include "LightApp_Module.h"
33 #include "LightApp_Operation.h"
34 #include "LightApp_Dialog.h"
35 #include <CAM_Application.h>
36 #include <SUIT_Operation.h>
37 #include <SUIT_Study.h>
41 #include <qapplication.h>
45 * \param theParent - parent of object
47 * Creates instance of the object. Connects signals and slots. Install eveny filter
50 LightApp_SwitchOp::LightApp_SwitchOp( LightApp_Module* theModule )
54 qApp->installEventFilter( this );
60 LightApp_SwitchOp::~LightApp_SwitchOp()
68 * Get module. Module is a parent of this class
70 LightApp_Module* LightApp_SwitchOp::module() const
77 * \return Active study of application (in current realisation)
81 SUIT_Study* LightApp_SwitchOp::study() const
83 return module()->application()->activeStudy();
87 * \brief Get operation by widget
88 * \param theWg - key widget to find operation
89 * \return Pointer to the operations if it is found or zero
91 * Find operation containing dialog with given widget
93 LightApp_Operation* LightApp_SwitchOp::operation( QWidget* theWg ) const
95 // get dialog from widget
96 LightApp_Dialog* aDlg = 0;
97 QWidget* aParent = theWg;
98 while( aParent && !aParent->inherits( "LightApp_Dialog" ) )
99 aParent = aParent->parentWidget();
101 if ( aParent && aParent->inherits( "LightApp_Dialog" ) )
102 aDlg = (LightApp_Dialog*)aParent;
104 // try to find operation corresponding to the dialog
105 if ( aDlg != 0 && study() != 0 )
107 QPtrListIterator<SUIT_Operation> anIter( study()->operations() );
108 while( SUIT_Operation* anOp = anIter.current() )
110 if ( anOp->inherits( "LightApp_Operation" ) &&
111 ((LightApp_Operation*)anOp)->dlg() == aDlg )
112 return ((LightApp_Operation*)anOp);
121 * \brief Event filter
122 * \param theObj - object
123 * \param theEv - event
125 * Event filter. Catched signals off application. If event concerns to dialog then
126 * corresponding operation is found and activated.
128 bool LightApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv )
130 if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) )
132 QEvent::Type aType = theEv->type();
133 LightApp_Operation* anOp = operation( (QWidget*)theObj );
140 if ( !anOp->isActive() && anOp->isAutoResumed() &&
141 study() && !study()->blockingOperation( anOp ) )
142 study()->resume( anOp );
146 case QEvent::MouseButtonRelease:
147 case QEvent::MouseButtonPress:
148 case QEvent::MouseButtonDblClick:
149 case QEvent::MouseMove:
150 case QEvent::KeyPress:
151 case QEvent::KeyRelease:
153 if ( !anOp->isActive() )
162 return QObject::eventFilter( theObj, theEv );