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 SUIT_Study* SUIT_Application::activeStudy() const
41 void SUIT_Application::start()
47 void SUIT_Application::useFile( const QString& theFileName )
51 activeStudy()->openDocument( theFileName );
54 void SUIT_Application::createEmptyStudy()
57 setActiveStudy( createNewStudy() );
60 int SUIT_Application::getNbStudies() const
62 return activeStudy() ? 1 : 0;
65 SUIT_ResourceMgr* SUIT_Application::resourceMgr() const
67 if ( !SUIT_Session::session() )
70 return SUIT_Session::session()->resourceMgr();
73 #define DEFAULT_MESSAGE_DELAY 3000
74 void SUIT_Application::putInfo ( const QString& msg, const int msec )
77 desktop()->statusBar()->message( msg, msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec );
80 SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const
82 return startApplication( name(), argc, argv );
85 SUIT_Application* SUIT_Application::startApplication( const QString& name, int argc, char** argv ) const
87 SUIT_Session* session = SUIT_Session::session();
91 return session->startApplication( name, argc, argv );
94 void SUIT_Application::setDesktop( SUIT_Desktop* desk )
96 if ( myDesktop == desk )
103 SUIT_Study* SUIT_Application::createNewStudy()
105 return new SUIT_Study( this );
108 void SUIT_Application::setActiveStudy( SUIT_Study* study )
110 if ( myStudy == study )
116 int SUIT_Application::createTool( const QString& name )
118 if ( !desktop() || !desktop()->toolMgr() )
121 return desktop()->toolMgr()->createToolBar( name );
124 int SUIT_Application::createTool( QAction* a, const int tBar, const int id, const int idx )
126 if ( !desktop() || !desktop()->toolMgr() )
129 int regId = desktop()->toolMgr()->registerAction( a, id );
130 return desktop()->toolMgr()->insert( regId, tBar, idx );
133 int SUIT_Application::createTool( QAction* a, const QString& tBar, const int id, const int idx )
135 if ( !desktop() || !desktop()->toolMgr() )
138 return desktop()->toolMgr()->insert( a, tBar, idx );
141 int SUIT_Application::createTool( const int id, const int tBar, const int idx )
143 if ( !desktop() || !desktop()->toolMgr() )
146 return desktop()->toolMgr()->insert( id, tBar, idx );
149 int SUIT_Application::createTool( const int id, const QString& tBar, const int idx )
151 if ( !desktop() || !desktop()->toolMgr() )
154 return desktop()->toolMgr()->insert( id, tBar, idx );
157 int SUIT_Application::createMenu( const QString& subMenu, const int menu,
158 const int id, const int group, const int index )
160 if ( !desktop() || !desktop()->menuMgr() )
163 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
166 int SUIT_Application::createMenu( const QString& subMenu, const QString& menu,
167 const int id, const int group, const int index )
169 if ( !desktop() || !desktop()->menuMgr() )
172 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
175 int SUIT_Application::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
177 if ( !a || !desktop() || !desktop()->menuMgr() )
180 int regId = desktop()->menuMgr()->registerAction( a, id );
181 return desktop()->menuMgr()->insert( regId, menu, group, index );
184 int SUIT_Application::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
186 if ( !a || !desktop() || !desktop()->menuMgr() )
189 int regId = desktop()->menuMgr()->registerAction( a, id );
190 return desktop()->menuMgr()->insert( regId, menu, group, index );
193 int SUIT_Application::createMenu( const int id, const int menu, const int group, const int index )
195 if ( !desktop() || !desktop()->menuMgr() )
198 return desktop()->menuMgr()->insert( id, menu, group, index );
201 int SUIT_Application::createMenu( const int id, const QString& menu, const int group, const int index )
203 if ( !desktop() || !desktop()->menuMgr() )
206 return desktop()->menuMgr()->insert( id, menu, group, index );
209 void SUIT_Application::setMenuShown( QAction* a, const bool on )
211 setMenuShown( actionId( a ), on );
214 void SUIT_Application::setMenuShown( const int id, const bool on )
216 if ( desktop() && desktop()->menuMgr() )
217 desktop()->menuMgr()->setShown( id, on );
220 void SUIT_Application::setToolShown( QAction* a, const bool on )
222 setToolShown( actionId( a ), on );
225 void SUIT_Application::setToolShown( const int id, const bool on )
227 if ( desktop() && desktop()->toolMgr() )
228 desktop()->toolMgr()->setShown( id, on );
231 QAction* SUIT_Application::action( const int id ) const
233 SUIT_Application* that = (SUIT_Application*)this;
234 SUIT_Desktop* desk = that->desktop();
239 if ( desk->menuMgr() )
240 a = desk->menuMgr()->action( id );
241 if ( !a && desk->toolMgr() )
242 a = desk->toolMgr()->action( id );
246 int SUIT_Application::actionId( const QAction* a ) const
248 SUIT_Application* that = (SUIT_Application*)this;
249 SUIT_Desktop* desk = that->desktop();
254 if ( desk->menuMgr() )
255 id = desk->menuMgr()->actionId( a );
256 if ( id == -1 && desk->toolMgr() )
257 id = desk->toolMgr()->actionId( a );
261 QAction* SUIT_Application::createAction( const int id, const QString& text, const QIconSet& icon,
262 const QString& menu, const QString& tip, const int key,
263 QObject* parent, const bool toggle, QObject* reciever, const char* member )
265 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
266 a->setStatusTip( tip );
268 if ( reciever && member )
269 connect( a, SIGNAL( activated() ), reciever, member );
271 registerAction( id, a );
276 void SUIT_Application::registerAction( const int id, QAction* a )
278 if ( desktop() && desktop()->menuMgr() )
279 desktop()->menuMgr()->registerAction( a, id );
281 if ( desktop() && desktop()->toolMgr() )
282 desktop()->toolMgr()->registerAction( a, id );
285 QAction* SUIT_Application::separator()
287 return QtxActionMgr::separator();