]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_SwitchOp.cxx
Salome HOME
69fcb3282fb62ec5b1b8439d50c6ca5d324f64a8
[modules/gui.git] / src / LightApp / LightApp_SwitchOp.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "LightApp_SwitchOp.h"
23 #include "LightApp_Module.h"
24 #include "LightApp_Operation.h"
25 #include "LightApp_Dialog.h"
26 #include <CAM_Application.h>
27 #include <SUIT_Operation.h>
28 #include <SUIT_Study.h>
29
30 #include <QEvent>
31 #include <QWidget>
32 #include <QList>
33 #include <QApplication>
34
35 /*!
36  * \brief Constructor
37   * \param theParent - parent of object
38 *
39 * Creates instance of the object. Connects signals and slots. Install eveny filter
40 * on application
41 */
42 LightApp_SwitchOp::LightApp_SwitchOp( LightApp_Module* theModule )
43 : QObject( 0 ),
44   myModule( theModule )
45 {
46   qApp->installEventFilter( this );
47 }
48
49 /*!
50  * \brief Destructor
51 */
52 LightApp_SwitchOp::~LightApp_SwitchOp()
53 {
54   
55 }
56
57 /*!
58  * \brief Get module
59 *
60 * Get module. Module is a parent of this class
61 */
62 LightApp_Module* LightApp_SwitchOp::module() const
63 {
64   return myModule;
65 }
66
67 /*!
68  * \brief Get study
69  * \return Active study of application (in current realisation)
70 *
71 * Get study
72 */
73 SUIT_Study* LightApp_SwitchOp::study() const
74 {
75   return module()->application()->activeStudy();
76 }
77
78 /*!
79  * \brief Get operation by widget
80   * \param theWg - key widget to find operation
81   * \return Pointer to the operations if it is found or zero 
82 *
83 * Find operation containing dialog with given widget
84 */
85 LightApp_Operation* LightApp_SwitchOp::operation( QWidget* theWg ) const
86 {
87   // get dialog from widget
88   LightApp_Dialog* aDlg = 0;
89   QWidget* aParent = theWg;
90   while( aParent && !aParent->inherits( "LightApp_Dialog" ) )
91     aParent = aParent->parentWidget();
92
93   if ( aParent && aParent->inherits( "LightApp_Dialog" ) )
94     aDlg = (LightApp_Dialog*)aParent;
95
96   // try to find operation corresponding to the dialog
97   if ( aDlg != 0 && study() != 0 )
98   {
99     QListIterator<SUIT_Operation*> anIter( study()->operations() );
100     while( anIter.hasNext() )
101     {
102       SUIT_Operation* anOp = anIter.next();
103           
104       if ( anOp &&
105            anOp->inherits( "LightApp_Operation" ) &&
106            ((LightApp_Operation*)anOp)->dlg() == aDlg )
107         return ((LightApp_Operation*)anOp);
108     }
109   }
110
111   return 0;
112 }
113
114 /*!
115  * \brief Event filter
116   * \param theObj - object
117   * \param theEv - event
118 *
119 * Event filter. Catched signals off application. If event concerns to dialog then
120 * corresponding operation is found and activated.
121 */
122 bool LightApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv )
123 {
124   if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) )
125   {
126     QEvent::Type aType = theEv->type();
127     LightApp_Operation* anOp = operation( (QWidget*)theObj );
128     if ( anOp )
129     {
130       switch ( aType )
131       {
132         case QEvent::Enter:
133         {
134           if ( !anOp->isActive() && anOp->isAutoResumed() &&
135                study() && !study()->blockingOperation( anOp ) )
136             study()->resume( anOp );
137         }
138         break;
139         
140         case QEvent::MouseButtonRelease:
141         case QEvent::MouseButtonPress:
142         case QEvent::MouseButtonDblClick:
143         case QEvent::MouseMove:
144         case QEvent::KeyPress:
145         case QEvent::KeyRelease:
146         {
147           if ( !anOp->isActive() )
148             return true;
149         }
150         break;
151         
152       }
153     }
154   }
155
156   return QObject::eventFilter( theObj, theEv );
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176