1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 #include "SUIT_Application.h"
21 #include "SUIT_Session.h"
22 #include "SUIT_Desktop.h"
23 #include "SUIT_ResourceMgr.h"
27 #include <qstatusbar.h>
29 #include <QtxAction.h>
30 #include <QtxActionMenuMgr.h>
31 #include <QtxActionToolMgr.h>
33 SUIT_Application::SUIT_Application()
41 SUIT_Application::~SUIT_Application()
49 SUIT_Desktop* SUIT_Application::desktop()
54 bool SUIT_Application::isPossibleToClose()
59 void SUIT_Application::closeApplication()
61 emit applicationClosed( this );
64 SUIT_Study* SUIT_Application::activeStudy() const
69 QString SUIT_Application::applicationVersion() const
74 void SUIT_Application::start()
80 bool SUIT_Application::useFile( const QString& theFileName )
83 SUIT_Study* study = activeStudy();
85 bool status = study ? study->openDocument( theFileName ) : false;
96 bool SUIT_Application::useStudy( const QString& theName )
101 void SUIT_Application::createEmptyStudy()
103 if ( !activeStudy() )
104 setActiveStudy( createNewStudy() );
107 int SUIT_Application::getNbStudies() const
109 return activeStudy() ? 1 : 0;
112 SUIT_ResourceMgr* SUIT_Application::resourceMgr() const
114 if ( !SUIT_Session::session() )
117 return SUIT_Session::session()->resourceMgr();
120 #define DEFAULT_MESSAGE_DELAY 3000
121 void SUIT_Application::putInfo ( const QString& msg, const int msec )
124 //desktop()->statusBar()->message( msg, msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec );
125 if ( !myStatusLabel ) {
126 myStatusLabel = new QLabel (desktop()->statusBar());
127 desktop()->statusBar()->addWidget(myStatusLabel, /*int stretch = */1);
129 myStatusLabel->setText(msg);
131 QTimer::singleShot(msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT(clear()));
135 SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const
137 return startApplication( name(), argc, argv );
140 SUIT_Application* SUIT_Application::startApplication( const QString& name, int argc, char** argv ) const
142 SUIT_Session* session = SUIT_Session::session();
146 return session->startApplication( name, argc, argv );
149 void SUIT_Application::setDesktop( SUIT_Desktop* desk )
151 if ( myDesktop == desk )
157 connect( myDesktop, SIGNAL( activated() ), this, SLOT( onDesktopActivated() ) );
160 SUIT_Study* SUIT_Application::createNewStudy()
162 return new SUIT_Study( this );
165 void SUIT_Application::setActiveStudy( SUIT_Study* study )
167 if ( myStudy == study )
173 int SUIT_Application::createTool( const QString& name )
175 if ( !desktop() || !desktop()->toolMgr() )
178 return desktop()->toolMgr()->createToolBar( name );
181 int SUIT_Application::createTool( QAction* a, const int tBar, const int id, const int idx )
183 if ( !desktop() || !desktop()->toolMgr() )
186 int regId = desktop()->toolMgr()->registerAction( a, id );
187 return desktop()->toolMgr()->insert( regId, tBar, idx );
190 int SUIT_Application::createTool( QAction* a, const QString& tBar, const int id, const int idx )
192 if ( !desktop() || !desktop()->toolMgr() )
195 return desktop()->toolMgr()->insert( a, tBar, idx );
198 int SUIT_Application::createTool( const int id, const int tBar, const int idx )
200 if ( !desktop() || !desktop()->toolMgr() )
203 return desktop()->toolMgr()->insert( id, tBar, idx );
206 int SUIT_Application::createTool( const int id, const QString& tBar, const int idx )
208 if ( !desktop() || !desktop()->toolMgr() )
211 return desktop()->toolMgr()->insert( id, tBar, idx );
214 int SUIT_Application::createMenu( const QString& subMenu, const int menu,
215 const int id, const int group, const int index )
217 if ( !desktop() || !desktop()->menuMgr() )
220 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
223 int SUIT_Application::createMenu( const QString& subMenu, const QString& menu,
224 const int id, const int group, const int index )
226 if ( !desktop() || !desktop()->menuMgr() )
229 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
232 int SUIT_Application::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
234 if ( !a || !desktop() || !desktop()->menuMgr() )
237 int regId = desktop()->menuMgr()->registerAction( a, id );
238 return desktop()->menuMgr()->insert( regId, menu, group, index );
241 int SUIT_Application::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
243 if ( !a || !desktop() || !desktop()->menuMgr() )
246 int regId = desktop()->menuMgr()->registerAction( a, id );
247 return desktop()->menuMgr()->insert( regId, menu, group, index );
250 int SUIT_Application::createMenu( const int id, const int menu, const int group, const int index )
252 if ( !desktop() || !desktop()->menuMgr() )
255 return desktop()->menuMgr()->insert( id, menu, group, index );
258 int SUIT_Application::createMenu( const int id, const QString& menu, const int group, const int index )
260 if ( !desktop() || !desktop()->menuMgr() )
263 return desktop()->menuMgr()->insert( id, menu, group, index );
266 void SUIT_Application::setMenuShown( QAction* a, const bool on )
268 setMenuShown( actionId( a ), on );
271 void SUIT_Application::setMenuShown( const int id, const bool on )
273 if ( desktop() && desktop()->menuMgr() )
274 desktop()->menuMgr()->setShown( id, on );
277 void SUIT_Application::setToolShown( QAction* a, const bool on )
279 setToolShown( actionId( a ), on );
282 void SUIT_Application::setToolShown( const int id, const bool on )
284 if ( desktop() && desktop()->toolMgr() )
285 desktop()->toolMgr()->setShown( id, on );
288 void SUIT_Application::setActionShown( QAction* a, const bool on )
290 setMenuShown( a, on );
291 setToolShown( a, on );
294 void SUIT_Application::setActionShown( const int id, const bool on )
296 setMenuShown( id, on );
297 setToolShown( id, on );
300 QAction* SUIT_Application::action( const int id ) const
302 SUIT_Application* that = (SUIT_Application*)this;
303 SUIT_Desktop* desk = that->desktop();
308 if ( desk->menuMgr() )
309 a = desk->menuMgr()->action( id );
310 if ( !a && desk->toolMgr() )
311 a = desk->toolMgr()->action( id );
315 int SUIT_Application::actionId( const QAction* a ) const
317 SUIT_Application* that = (SUIT_Application*)this;
318 SUIT_Desktop* desk = that->desktop();
323 if ( desk->menuMgr() )
324 id = desk->menuMgr()->actionId( a );
325 if ( id == -1 && desk->toolMgr() )
326 id = desk->toolMgr()->actionId( a );
330 QAction* SUIT_Application::createAction( const int id, const QString& text, const QIconSet& icon,
331 const QString& menu, const QString& tip, const int key,
332 QObject* parent, const bool toggle, QObject* reciever, const char* member )
334 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
335 a->setStatusTip( tip );
337 if ( reciever && member )
338 connect( a, SIGNAL( activated() ), reciever, member );
340 registerAction( id, a );
345 void SUIT_Application::registerAction( const int id, QAction* a )
347 if ( desktop() && desktop()->menuMgr() )
348 desktop()->menuMgr()->registerAction( a, id );
350 if ( desktop() && desktop()->toolMgr() )
351 desktop()->toolMgr()->registerAction( a, id );
354 QAction* SUIT_Application::separator()
356 return QtxActionMgr::separator();
359 void SUIT_Application::onDesktopActivated()
361 emit activated( this );