4 * Copyright (C) 2005 CEA/DEN, EDF R&D
8 * File : SalomeApp_SwitchOp.h
9 * Author : Sergey LITONIN
13 #include "SalomeApp_SwitchOp.h"
14 #include "SalomeApp_Module.h"
15 #include "SalomeApp_Operation.h"
16 #include "SalomeApp_Dialog.h"
17 #include <CAM_Application.h>
18 #include <SUIT_Operation.h>
19 #include <SUIT_Study.h>
23 #include <qapplication.h>
27 * \param theParent - parent of object
29 * Creates instance of the object. Connects signals and slots. Install eveny filter
32 SalomeApp_SwitchOp::SalomeApp_SwitchOp( SalomeApp_Module* theModule )
36 qApp->installEventFilter( this );
42 SalomeApp_SwitchOp::~SalomeApp_SwitchOp()
50 * Get module. Module is a parent of this class
52 SalomeApp_Module* SalomeApp_SwitchOp::module() const
59 * \return Active study of application (in current realisation)
63 SUIT_Study* SalomeApp_SwitchOp::study() const
65 return module()->application()->activeStudy();
69 * \brief Get operation by widget
70 * \param theWg - key widget to find operation
71 * \return Pointer to the operations if it is found or zero
73 * Find operation containing dialog with given widget
75 SalomeApp_Operation* SalomeApp_SwitchOp::operation( QWidget* theWg ) const
77 // get dialog from widget
78 SalomeApp_Dialog* aDlg = 0;
79 QWidget* aParent = theWg;
80 while( aParent && !aParent->inherits( "SalomeApp_Dialog" ) )
81 aParent = aParent->parentWidget();
83 if ( aParent && aParent->inherits( "SalomeApp_Dialog" ) )
84 aDlg = (SalomeApp_Dialog*)aParent;
86 // try to find operation corresponding to the dialog
87 if ( aDlg != 0 && study() != 0 )
89 QPtrListIterator<SUIT_Operation> anIter( study()->operations() );
90 while( SUIT_Operation* anOp = anIter.current() )
92 if ( anOp->inherits( "SalomeApp_Operation" ) &&
93 ((SalomeApp_Operation*)anOp)->dlg() == aDlg )
94 return ((SalomeApp_Operation*)anOp);
103 * \brief Event filter
104 * \param theObj - object
105 * \param theEv - event
107 * Event filter. Catched signals off application. If event concerns to dialog then
108 * corresponding operation is found and activated.
110 bool SalomeApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv )
112 if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) )
114 QEvent::Type aType = theEv->type();
115 SalomeApp_Operation* anOp = operation( (QWidget*)theObj );
122 if ( !anOp->isActive() && anOp->isAutoResumed() &&
123 study() && !study()->blockingOperation( anOp ) )
124 study()->resume( anOp );
128 case QEvent::MouseButtonRelease:
129 case QEvent::MouseButtonPress:
130 case QEvent::MouseButtonDblClick:
131 case QEvent::MouseMove:
132 case QEvent::KeyPress:
133 case QEvent::KeyRelease:
135 if ( !anOp->isActive() )
144 return QObject::eventFilter( theObj, theEv );