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/ or email : webmaster.salome@opencascade.com
20 #include "LightApp_SwitchOp.h"
21 #include "LightApp_Module.h"
22 #include "LightApp_Operation.h"
23 #include "LightApp_Dialog.h"
24 #include <CAM_Application.h>
25 #include <SUIT_Operation.h>
26 #include <SUIT_Study.h>
30 #include <qapplication.h>
34 * \param theParent - parent of object
36 * Creates instance of the object. Connects signals and slots. Install eveny filter
39 LightApp_SwitchOp::LightApp_SwitchOp( LightApp_Module* theModule )
43 qApp->installEventFilter( this );
49 LightApp_SwitchOp::~LightApp_SwitchOp()
57 * Get module. Module is a parent of this class
59 LightApp_Module* LightApp_SwitchOp::module() const
66 * \return Active study of application (in current realisation)
70 SUIT_Study* LightApp_SwitchOp::study() const
72 return module()->application()->activeStudy();
76 * \brief Get operation by widget
77 * \param theWg - key widget to find operation
78 * \return Pointer to the operations if it is found or zero
80 * Find operation containing dialog with given widget
82 LightApp_Operation* LightApp_SwitchOp::operation( QWidget* theWg ) const
84 // get dialog from widget
85 LightApp_Dialog* aDlg = 0;
86 QWidget* aParent = theWg;
87 while( aParent && !aParent->inherits( "LightApp_Dialog" ) )
88 aParent = aParent->parentWidget();
90 if ( aParent && aParent->inherits( "LightApp_Dialog" ) )
91 aDlg = (LightApp_Dialog*)aParent;
93 // try to find operation corresponding to the dialog
94 if ( aDlg != 0 && study() != 0 )
96 QPtrListIterator<SUIT_Operation> anIter( study()->operations() );
97 while( SUIT_Operation* anOp = anIter.current() )
99 if ( anOp->inherits( "LightApp_Operation" ) &&
100 ((LightApp_Operation*)anOp)->dlg() == aDlg )
101 return ((LightApp_Operation*)anOp);
110 * \brief Event filter
111 * \param theObj - object
112 * \param theEv - event
114 * Event filter. Catched signals off application. If event concerns to dialog then
115 * corresponding operation is found and activated.
117 bool LightApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv )
119 if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) )
121 QEvent::Type aType = theEv->type();
122 LightApp_Operation* anOp = operation( (QWidget*)theObj );
129 if ( !anOp->isActive() && anOp->isAutoResumed() &&
130 study() && !study()->blockingOperation( anOp ) )
131 study()->resume( anOp );
135 case QEvent::MouseButtonRelease:
136 case QEvent::MouseButtonPress:
137 case QEvent::MouseButtonDblClick:
138 case QEvent::MouseMove:
139 case QEvent::KeyPress:
140 case QEvent::KeyRelease:
142 if ( !anOp->isActive() )
151 return QObject::eventFilter( theObj, theEv );