1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "LightApp_SwitchOp.h"
24 #include "LightApp_Module.h"
25 #include "LightApp_Operation.h"
26 #include "LightApp_Dialog.h"
27 #include <CAM_Application.h>
28 #include <SUIT_Operation.h>
29 #include <SUIT_Study.h>
34 #include <QApplication>
38 * \param theParent - parent of object
40 * Creates instance of the object. Connects signals and slots. Install eveny filter
43 LightApp_SwitchOp::LightApp_SwitchOp( LightApp_Module* theModule )
47 qApp->installEventFilter( this );
53 LightApp_SwitchOp::~LightApp_SwitchOp()
61 * Get module. Module is a parent of this class
63 LightApp_Module* LightApp_SwitchOp::module() const
70 * \return Active study of application (in current realisation)
74 SUIT_Study* LightApp_SwitchOp::study() const
76 return module()->application()->activeStudy();
80 * \brief Get operation by widget
81 * \param theWg - key widget to find operation
82 * \return Pointer to the operations if it is found or zero
84 * Find operation containing dialog with given widget
86 LightApp_Operation* LightApp_SwitchOp::operation( QWidget* theWg ) const
88 // get dialog from widget
89 LightApp_Dialog* aDlg = 0;
90 QWidget* aParent = theWg;
91 while( aParent && !aParent->inherits( "LightApp_Dialog" ) )
92 aParent = aParent->parentWidget();
94 if ( aParent && aParent->inherits( "LightApp_Dialog" ) )
95 aDlg = (LightApp_Dialog*)aParent;
97 // try to find operation corresponding to the dialog
98 if ( aDlg != 0 && study() != 0 )
100 QListIterator<SUIT_Operation*> anIter( study()->operations() );
101 while( anIter.hasNext() )
103 SUIT_Operation* anOp = anIter.next();
106 anOp->inherits( "LightApp_Operation" ) &&
107 ((LightApp_Operation*)anOp)->dlg() == aDlg )
108 return ((LightApp_Operation*)anOp);
116 * \brief Event filter
117 * \param theObj - object
118 * \param theEv - event
120 * Event filter. Catched signals off application. If event concerns to dialog then
121 * corresponding operation is found and activated.
123 bool LightApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv )
125 if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) )
127 QEvent::Type aType = theEv->type();
128 LightApp_Operation* anOp = operation( (QWidget*)theObj );
135 if ( !anOp->isActive() && anOp->isAutoResumed() &&
136 study() && !study()->blockingOperation( anOp ) )
137 study()->resume( anOp );
140 case QEvent::MouseButtonRelease:
141 case QEvent::MouseButtonPress:
142 case QEvent::MouseButtonDblClick:
143 case QEvent::MouseMove:
144 case QEvent::KeyPress:
145 case QEvent::KeyRelease:
147 if ( !anOp->isActive() )
157 return QObject::eventFilter( theObj, theEv );