From 4a61ab0e9677cc6fcb7c494ab7b440bdb4cfa864 Mon Sep 17 00:00:00 2001 From: sln Date: Tue, 23 Aug 2005 08:15:24 +0000 Subject: [PATCH] Auxiliary class for switching between started operations --- src/SalomeApp/SalomeApp_SwitchOp.cxx | 164 +++++++++++++++++++++++++++ src/SalomeApp/SalomeApp_SwitchOp.h | 71 ++++++++++++ 2 files changed, 235 insertions(+) create mode 100755 src/SalomeApp/SalomeApp_SwitchOp.cxx create mode 100755 src/SalomeApp/SalomeApp_SwitchOp.h diff --git a/src/SalomeApp/SalomeApp_SwitchOp.cxx b/src/SalomeApp/SalomeApp_SwitchOp.cxx new file mode 100755 index 000000000..cb0d33397 --- /dev/null +++ b/src/SalomeApp/SalomeApp_SwitchOp.cxx @@ -0,0 +1,164 @@ +/** +* SALOME SalomeApp +* +* Copyright (C) 2005 CEA/DEN, EDF R&D +* +* +* +* File : SalomeApp_SwitchOp.h +* Author : Sergey LITONIN +* Module : SALOME +*/ + +#include "SalomeApp_SwitchOp.h" +#include "SalomeApp_Module.h" +#include "SalomeApp_Operation.h" +#include "SalomeApp_Dialog.h" +#include +#include +#include +#include +#include +#include +#include + +/*! + * \brief Constructor + * \param theParent - parent of object +* +* Creates instance of the object. Connects signals and slots. Install eveny filter +* on application +*/ +SalomeApp_SwitchOp::SalomeApp_SwitchOp( SalomeApp_Module* theModule ) +: QObject( 0 ), + myModule( theModule ) +{ + qApp->installEventFilter( this ); +} + +/*! + * \brief Destructor +*/ +SalomeApp_SwitchOp::~SalomeApp_SwitchOp() +{ + +} + +/*! + * \brief Get module +* +* Get module. Module is a parent of this class +*/ +SalomeApp_Module* SalomeApp_SwitchOp::module() const +{ + return myModule; +} + +/*! + * \brief Get study + * \return Active study of application (in current realisation) +* +* Get study +*/ +SUIT_Study* SalomeApp_SwitchOp::study() const +{ + return module()->application()->activeStudy(); +} + +/*! + * \brief Get operation by widget + * \param theWg - key widget to find operation + * \return Pointer to the operations if it is found or zero +* +* Find operation containing dialog with given widget +*/ +SalomeApp_Operation* SalomeApp_SwitchOp::operation( QWidget* theWg ) const +{ + // get dialog from widget + SalomeApp_Dialog* aDlg = 0; + QWidget* aParent = theWg; + while( aParent && !aParent->inherits( "SalomeApp_Dialog" ) ) + aParent = aParent->parentWidget(); + + if ( aParent && aParent->inherits( "SalomeApp_Dialog" ) ) + aDlg = (SalomeApp_Dialog*)aParent; + + // try to find operation corresponding to the dialog + if ( aDlg != 0 && study() != 0 ) + { + QPtrListIterator anIter( study()->operations() ); + while( SUIT_Operation* anOp = anIter.current() ) + { + if ( anOp->inherits( "SalomeApp_Operation" ) && + ((SalomeApp_Operation*)anOp)->dlg() == aDlg ) + return ((SalomeApp_Operation*)anOp); + ++anIter; + } + } + + return 0; +} + +/*! + * \brief Event filter + * \param theObj - object + * \param theEv - event +* +* Event filter. Catched signals off application. If event concerns to dialog then +* corresponding operation is found and activated. +*/ +bool SalomeApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv ) +{ + if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) ) + { + QEvent::Type aType = theEv->type(); + SalomeApp_Operation* anOp = operation( (QWidget*)theObj ); + if ( anOp ) + { + switch ( aType ) + { + case QEvent::Enter: + { + if ( !anOp->isActive() && anOp->isAutoResumed() && + study() && !study()->blockingOperation( anOp ) ) + study()->resume( anOp ); + } + break; + + case QEvent::MouseButtonRelease: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: + case QEvent::MouseMove: + case QEvent::KeyPress: + case QEvent::KeyRelease: + { + if ( !anOp->isActive() ) + return true; + } + break; + + } + } + } + + return QObject::eventFilter( theObj, theEv ); +} + + + + + + + + + + + + + + + + + + + diff --git a/src/SalomeApp/SalomeApp_SwitchOp.h b/src/SalomeApp/SalomeApp_SwitchOp.h new file mode 100755 index 000000000..9b69905fe --- /dev/null +++ b/src/SalomeApp/SalomeApp_SwitchOp.h @@ -0,0 +1,71 @@ +/** +* SALOME SalomeApp +* +* Copyright (C) 2005 CEA/DEN, EDF R&D +* +* +* +* File : SalomeApp_SwitchOp.h +* Author : Sergey LITONIN +* Module : SALOME +*/ + + + +#ifndef SalomeApp_SwitchOp_H +#define SalomeApp_SwitchOp_H + +#include + +class SalomeApp_Module; +class SalomeApp_Operation; +class QEvent; +class SUIT_Study; + +/*! + * \brief This class is intended for controling switching between operation + * + * Several operation may be launched simultaneously. This class is intended for + * controlling switching between such operations. This class works with operations having + * dialogs (activation of other operations is performed by SUIT_Study). When several + * operations is launched simultaneously corresponding dialogs are shown on the screen. + * Only one operation from the launched ones can be active (active operation). Other + * operations are suspended. As result only one dialog from shown ones can be active too. + * Other dialogs are disabled. This class installs event filter on application. When mouse + * cursor is moved above disabled dialog corresponding event is catched by this class. + * It finds corresponding operation and verify whether operation can be resumed (see + * SUIT_Study::isDenied( SUIT_Operation* ) method). If yes then current active + * operation is suspended and new operation activated. Module contains this class as a + * field. Then module is created instance of this class created too. + */ +class SalomeApp_SwitchOp : public QObject +{ + Q_OBJECT + +public: + + SalomeApp_SwitchOp( SalomeApp_Module* ); + virtual ~SalomeApp_SwitchOp(); + + // Redefined from base class + bool eventFilter( QObject*, QEvent* ); + +private: + + SalomeApp_Module* module() const; + SalomeApp_Operation* operation( QWidget* ) const; + SUIT_Study* study() const; + +private: + + SalomeApp_Module* myModule; + +}; + +#endif + + + + + + -- 2.39.2