Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/gui.git] / src / SUITApp / SUITApp_Application.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
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.
7 // 
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "SUITApp_Application.h"
20
21 #include "SUIT_Session.h"
22 #include "SUIT_MessageBox.h"
23 #include "SUIT_ExceptionHandler.h"
24
25 #include <qdir.h>
26 #include <qfileinfo.h>
27
28 #ifdef WIN32
29 #include <windows.h>
30 #include <winbase.h>
31 #else
32 #include <unistd.h>
33 #endif
34
35 /*!
36   Constructor
37 */
38 SUITApp_Application::SUITApp_Application( int& argc, char** argv, SUIT_ExceptionHandler* hand )
39 : QApplication( argc, argv ),
40 myExceptHandler( hand )
41 {
42   QString path = QFileInfo( argv[0] ).dirPath() + QDir::separator() + "../../resources";
43   path = QDir::convertSeparators( QDir( path ).canonicalPath() );
44
45   QTranslator* strTbl = new QTranslator( 0 );
46   if ( strTbl->load( "SUITApp_msg_en.po", path  ) )
47     installTranslator( strTbl );
48   else
49     delete strTbl;
50 }
51
52 /*!
53   Constructor
54 */
55 SUITApp_Application::SUITApp_Application( int& argc, char** argv, Type type, SUIT_ExceptionHandler* hand )
56 : QApplication( argc, argv, type ),
57 myExceptHandler( hand )
58 {
59     QTranslator* strTbl = new QTranslator( 0 );
60     strTbl->load( "resources\\SUITApp_msg_en.po" );
61     installTranslator( strTbl );
62 }
63
64 /*!
65   Sends event to receiver
66   \return the value that is returned from the receiver's event handler
67   \param e - event
68   \param receiver - receiver
69 */
70 bool SUITApp_Application::notify( QObject* receiver, QEvent* e )
71 {
72 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) < 0x060101
73   // Disable GUI user actions while python command is executed
74   if (SUIT_Session::IsPythonExecuted()) {
75     // Disable mouse and keyboard events
76     QEvent::Type aType = e->type();
77     if (aType == QEvent::MouseButtonPress || aType == QEvent::MouseButtonRelease ||
78         aType == QEvent::MouseButtonDblClick || aType == QEvent::MouseMove ||
79         aType == QEvent::Wheel || aType == QEvent::ContextMenu ||
80         aType == QEvent::KeyPress || aType == QEvent::KeyRelease ||
81         aType == QEvent::Accel || aType == QEvent::AccelOverride)
82       return false;
83   }
84 #endif
85
86   return myExceptHandler ? myExceptHandler->handle( receiver, e ) :
87                            QApplication::notify( receiver, e );
88 }
89
90 /*!
91   Changes exception handler
92   \param hand - new handler
93 */
94 void SUITApp_Application::setHandler( SUIT_ExceptionHandler* hand )
95 {
96         myExceptHandler = hand;
97 }
98
99 /*!
100   \return exception handler
101 */
102 SUIT_ExceptionHandler* SUITApp_Application::handler() const
103 {
104   return myExceptHandler;
105 }