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 )
126 if ( !myStatusLabel )
128 myStatusLabel = new QLabel( desktop()->statusBar() );
129 desktop()->statusBar()->addWidget( myStatusLabel, 1 );
130 myStatusLabel->show();
133 myStatusLabel->setText( msg );
135 QTimer::singleShot( msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT( clear() ) );
138 SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const
140 return startApplication( name(), argc, argv );
143 SUIT_Application* SUIT_Application::startApplication( const QString& name, int argc, char** argv ) const
145 SUIT_Session* session = SUIT_Session::session();
149 return session->startApplication( name, argc, argv );
152 void SUIT_Application::setDesktop( SUIT_Desktop* desk )
154 if ( myDesktop == desk )
160 connect( myDesktop, SIGNAL( activated() ), this, SLOT( onDesktopActivated() ) );
163 SUIT_Study* SUIT_Application::createNewStudy()
165 return new SUIT_Study( this );
168 void SUIT_Application::setActiveStudy( SUIT_Study* study )
170 if ( myStudy == study )
176 int SUIT_Application::createTool( const QString& name )
178 if ( !desktop() || !desktop()->toolMgr() )
181 return desktop()->toolMgr()->createToolBar( name );
184 int SUIT_Application::createTool( QAction* a, const int tBar, const int id, const int idx )
186 if ( !desktop() || !desktop()->toolMgr() )
189 int regId = desktop()->toolMgr()->registerAction( a, id );
190 return desktop()->toolMgr()->insert( regId, tBar, idx );
193 int SUIT_Application::createTool( QAction* a, const QString& tBar, const int id, const int idx )
195 if ( !desktop() || !desktop()->toolMgr() )
198 return desktop()->toolMgr()->insert( a, tBar, idx );
201 int SUIT_Application::createTool( const int id, const int tBar, const int idx )
203 if ( !desktop() || !desktop()->toolMgr() )
206 return desktop()->toolMgr()->insert( id, tBar, idx );
209 int SUIT_Application::createTool( const int id, const QString& tBar, const int idx )
211 if ( !desktop() || !desktop()->toolMgr() )
214 return desktop()->toolMgr()->insert( id, tBar, idx );
217 int SUIT_Application::createMenu( const QString& subMenu, const int menu,
218 const int id, const int group, const int index )
220 if ( !desktop() || !desktop()->menuMgr() )
223 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
226 int SUIT_Application::createMenu( const QString& subMenu, const QString& menu,
227 const int id, const int group, const int index )
229 if ( !desktop() || !desktop()->menuMgr() )
232 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
235 int SUIT_Application::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
237 if ( !a || !desktop() || !desktop()->menuMgr() )
240 int regId = desktop()->menuMgr()->registerAction( a, id );
241 return desktop()->menuMgr()->insert( regId, menu, group, index );
244 int SUIT_Application::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
246 if ( !a || !desktop() || !desktop()->menuMgr() )
249 int regId = desktop()->menuMgr()->registerAction( a, id );
250 return desktop()->menuMgr()->insert( regId, menu, group, index );
253 int SUIT_Application::createMenu( const int id, const int menu, const int group, const int index )
255 if ( !desktop() || !desktop()->menuMgr() )
258 return desktop()->menuMgr()->insert( id, menu, group, index );
261 int SUIT_Application::createMenu( const int id, const QString& menu, const int group, const int index )
263 if ( !desktop() || !desktop()->menuMgr() )
266 return desktop()->menuMgr()->insert( id, menu, group, index );
269 void SUIT_Application::setMenuShown( QAction* a, const bool on )
271 setMenuShown( actionId( a ), on );
274 void SUIT_Application::setMenuShown( const int id, const bool on )
276 if ( desktop() && desktop()->menuMgr() )
277 desktop()->menuMgr()->setShown( id, on );
280 void SUIT_Application::setToolShown( QAction* a, const bool on )
282 setToolShown( actionId( a ), on );
285 void SUIT_Application::setToolShown( const int id, const bool on )
287 if ( desktop() && desktop()->toolMgr() )
288 desktop()->toolMgr()->setShown( id, on );
291 void SUIT_Application::setActionShown( QAction* a, const bool on )
293 setMenuShown( a, on );
294 setToolShown( a, on );
297 void SUIT_Application::setActionShown( const int id, const bool on )
299 setMenuShown( id, on );
300 setToolShown( id, on );
303 QAction* SUIT_Application::action( const int id ) const
305 SUIT_Application* that = (SUIT_Application*)this;
306 SUIT_Desktop* desk = that->desktop();
311 if ( desk->menuMgr() )
312 a = desk->menuMgr()->action( id );
313 if ( !a && desk->toolMgr() )
314 a = desk->toolMgr()->action( id );
318 int SUIT_Application::actionId( const QAction* a ) const
320 SUIT_Application* that = (SUIT_Application*)this;
321 SUIT_Desktop* desk = that->desktop();
326 if ( desk->menuMgr() )
327 id = desk->menuMgr()->actionId( a );
328 if ( id == -1 && desk->toolMgr() )
329 id = desk->toolMgr()->actionId( a );
333 QAction* SUIT_Application::createAction( const int id, const QString& text, const QIconSet& icon,
334 const QString& menu, const QString& tip, const int key,
335 QObject* parent, const bool toggle, QObject* reciever, const char* member )
337 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
338 a->setStatusTip( tip );
340 if ( reciever && member )
341 connect( a, SIGNAL( activated() ), reciever, member );
343 registerAction( id, a );
348 void SUIT_Application::registerAction( const int id, QAction* a )
350 if ( desktop() && desktop()->menuMgr() )
351 desktop()->menuMgr()->registerAction( a, id );
353 if ( desktop() && desktop()->toolMgr() )
354 desktop()->toolMgr()->registerAction( a, id );
357 QAction* SUIT_Application::separator()
359 return QtxActionMgr::separator();
362 void SUIT_Application::onDesktopActivated()
364 emit activated( this );