1 #include "SUIT_Application.h"
3 #include "SUIT_Session.h"
4 #include "SUIT_Desktop.h"
5 #include "SUIT_ResourceMgr.h"
7 #include <qstatusbar.h>
10 #include <QtxActionMenuMgr.h>
11 #include <QtxActionToolMgr.h>
13 SUIT_Application::SUIT_Application()
20 SUIT_Application::~SUIT_Application()
26 SUIT_Desktop* SUIT_Application::desktop()
31 bool SUIT_Application::isPossibleToClose()
36 void SUIT_Application::closeApplication()
38 emit applicationClosed( this );
41 SUIT_Study* SUIT_Application::activeStudy() const
46 QString SUIT_Application::applicationVersion() const
51 void SUIT_Application::start()
57 bool SUIT_Application::useFile( const QString& theFileName )
61 return activeStudy()->openDocument( theFileName );
65 bool SUIT_Application::useStudy( const QString& theName )
70 void SUIT_Application::createEmptyStudy()
73 setActiveStudy( createNewStudy() );
76 int SUIT_Application::getNbStudies() const
78 return activeStudy() ? 1 : 0;
81 SUIT_ResourceMgr* SUIT_Application::resourceMgr() const
83 if ( !SUIT_Session::session() )
86 return SUIT_Session::session()->resourceMgr();
89 #define DEFAULT_MESSAGE_DELAY 3000
90 void SUIT_Application::putInfo ( const QString& msg, const int msec )
93 desktop()->statusBar()->message( msg, msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec );
96 SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const
98 return startApplication( name(), argc, argv );
101 SUIT_Application* SUIT_Application::startApplication( const QString& name, int argc, char** argv ) const
103 SUIT_Session* session = SUIT_Session::session();
107 return session->startApplication( name, argc, argv );
110 void SUIT_Application::setDesktop( SUIT_Desktop* desk )
112 if ( myDesktop == desk )
118 connect( myDesktop, SIGNAL( activated() ), this, SLOT( onDesktopActivated() ) );
121 SUIT_Study* SUIT_Application::createNewStudy()
123 return new SUIT_Study( this );
126 void SUIT_Application::setActiveStudy( SUIT_Study* study )
128 if ( myStudy == study )
134 int SUIT_Application::createTool( const QString& name )
136 if ( !desktop() || !desktop()->toolMgr() )
139 return desktop()->toolMgr()->createToolBar( name );
142 int SUIT_Application::createTool( QAction* a, const int tBar, const int id, const int idx )
144 if ( !desktop() || !desktop()->toolMgr() )
147 int regId = desktop()->toolMgr()->registerAction( a, id );
148 return desktop()->toolMgr()->insert( regId, tBar, idx );
151 int SUIT_Application::createTool( QAction* a, const QString& tBar, const int id, const int idx )
153 if ( !desktop() || !desktop()->toolMgr() )
156 return desktop()->toolMgr()->insert( a, tBar, idx );
159 int SUIT_Application::createTool( const int id, const int tBar, const int idx )
161 if ( !desktop() || !desktop()->toolMgr() )
164 return desktop()->toolMgr()->insert( id, tBar, idx );
167 int SUIT_Application::createTool( const int id, const QString& tBar, const int idx )
169 if ( !desktop() || !desktop()->toolMgr() )
172 return desktop()->toolMgr()->insert( id, tBar, idx );
175 int SUIT_Application::createMenu( const QString& subMenu, const int menu,
176 const int id, const int group, const int index )
178 if ( !desktop() || !desktop()->menuMgr() )
181 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
184 int SUIT_Application::createMenu( const QString& subMenu, const QString& menu,
185 const int id, const int group, const int index )
187 if ( !desktop() || !desktop()->menuMgr() )
190 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
193 int SUIT_Application::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
195 if ( !a || !desktop() || !desktop()->menuMgr() )
198 int regId = desktop()->menuMgr()->registerAction( a, id );
199 return desktop()->menuMgr()->insert( regId, menu, group, index );
202 int SUIT_Application::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
204 if ( !a || !desktop() || !desktop()->menuMgr() )
207 int regId = desktop()->menuMgr()->registerAction( a, id );
208 return desktop()->menuMgr()->insert( regId, menu, group, index );
211 int SUIT_Application::createMenu( const int id, const int menu, const int group, const int index )
213 if ( !desktop() || !desktop()->menuMgr() )
216 return desktop()->menuMgr()->insert( id, menu, group, index );
219 int SUIT_Application::createMenu( const int id, const QString& menu, const int group, const int index )
221 if ( !desktop() || !desktop()->menuMgr() )
224 return desktop()->menuMgr()->insert( id, menu, group, index );
227 void SUIT_Application::setMenuShown( QAction* a, const bool on )
229 setMenuShown( actionId( a ), on );
232 void SUIT_Application::setMenuShown( const int id, const bool on )
234 if ( desktop() && desktop()->menuMgr() )
235 desktop()->menuMgr()->setShown( id, on );
238 void SUIT_Application::setToolShown( QAction* a, const bool on )
240 setToolShown( actionId( a ), on );
243 void SUIT_Application::setToolShown( const int id, const bool on )
245 if ( desktop() && desktop()->toolMgr() )
246 desktop()->toolMgr()->setShown( id, on );
249 QAction* SUIT_Application::action( const int id ) const
251 SUIT_Application* that = (SUIT_Application*)this;
252 SUIT_Desktop* desk = that->desktop();
257 if ( desk->menuMgr() )
258 a = desk->menuMgr()->action( id );
259 if ( !a && desk->toolMgr() )
260 a = desk->toolMgr()->action( id );
264 int SUIT_Application::actionId( const QAction* a ) const
266 SUIT_Application* that = (SUIT_Application*)this;
267 SUIT_Desktop* desk = that->desktop();
272 if ( desk->menuMgr() )
273 id = desk->menuMgr()->actionId( a );
274 if ( id == -1 && desk->toolMgr() )
275 id = desk->toolMgr()->actionId( a );
279 QAction* SUIT_Application::createAction( const int id, const QString& text, const QIconSet& icon,
280 const QString& menu, const QString& tip, const int key,
281 QObject* parent, const bool toggle, QObject* reciever, const char* member )
283 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
284 a->setStatusTip( tip );
286 if ( reciever && member )
287 connect( a, SIGNAL( activated() ), reciever, member );
289 registerAction( id, a );
294 void SUIT_Application::registerAction( const int id, QAction* a )
296 if ( desktop() && desktop()->menuMgr() )
297 desktop()->menuMgr()->registerAction( a, id );
299 if ( desktop() && desktop()->toolMgr() )
300 desktop()->toolMgr()->registerAction( a, id );
303 QAction* SUIT_Application::separator()
305 return QtxActionMgr::separator();
308 void SUIT_Application::onDesktopActivated()
310 emit activated( this );