1 #include "SUIT_Application.h"
3 #include "SUIT_Session.h"
4 #include "SUIT_Desktop.h"
5 #include "SUIT_ResourceMgr.h"
9 #include <qstatusbar.h>
11 #include <QtxAction.h>
12 #include <QtxActionMenuMgr.h>
13 #include <QtxActionToolMgr.h>
15 SUIT_Application::SUIT_Application()
23 SUIT_Application::~SUIT_Application()
29 SUIT_Desktop* SUIT_Application::desktop()
34 bool SUIT_Application::isPossibleToClose()
39 void SUIT_Application::closeApplication()
41 emit applicationClosed( this );
44 SUIT_Study* SUIT_Application::activeStudy() const
49 QString SUIT_Application::applicationVersion() const
54 void SUIT_Application::start()
60 bool SUIT_Application::useFile( const QString& theFileName )
64 return activeStudy()->openDocument( theFileName );
68 bool SUIT_Application::useStudy( const QString& theName )
73 void SUIT_Application::createEmptyStudy()
76 setActiveStudy( createNewStudy() );
79 int SUIT_Application::getNbStudies() const
81 return activeStudy() ? 1 : 0;
84 SUIT_ResourceMgr* SUIT_Application::resourceMgr() const
86 if ( !SUIT_Session::session() )
89 return SUIT_Session::session()->resourceMgr();
92 #define DEFAULT_MESSAGE_DELAY 3000
93 void SUIT_Application::putInfo ( const QString& msg, const int msec )
96 //desktop()->statusBar()->message( msg, msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec );
97 if ( !myStatusLabel ) {
98 myStatusLabel = new QLabel (desktop()->statusBar());
99 desktop()->statusBar()->addWidget(myStatusLabel, /*int stretch = */1);
101 myStatusLabel->setText(msg);
103 QTimer::singleShot(msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT(clear()));
107 SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const
109 return startApplication( name(), argc, argv );
112 SUIT_Application* SUIT_Application::startApplication( const QString& name, int argc, char** argv ) const
114 SUIT_Session* session = SUIT_Session::session();
118 return session->startApplication( name, argc, argv );
121 void SUIT_Application::setDesktop( SUIT_Desktop* desk )
123 if ( myDesktop == desk )
129 connect( myDesktop, SIGNAL( activated() ), this, SLOT( onDesktopActivated() ) );
132 SUIT_Study* SUIT_Application::createNewStudy()
134 return new SUIT_Study( this );
137 void SUIT_Application::setActiveStudy( SUIT_Study* study )
139 if ( myStudy == study )
145 int SUIT_Application::createTool( const QString& name )
147 if ( !desktop() || !desktop()->toolMgr() )
150 return desktop()->toolMgr()->createToolBar( name );
153 int SUIT_Application::createTool( QAction* a, const int tBar, const int id, const int idx )
155 if ( !desktop() || !desktop()->toolMgr() )
158 int regId = desktop()->toolMgr()->registerAction( a, id );
159 return desktop()->toolMgr()->insert( regId, tBar, idx );
162 int SUIT_Application::createTool( QAction* a, const QString& tBar, const int id, const int idx )
164 if ( !desktop() || !desktop()->toolMgr() )
167 return desktop()->toolMgr()->insert( a, tBar, idx );
170 int SUIT_Application::createTool( const int id, const int tBar, const int idx )
172 if ( !desktop() || !desktop()->toolMgr() )
175 return desktop()->toolMgr()->insert( id, tBar, idx );
178 int SUIT_Application::createTool( const int id, const QString& tBar, const int idx )
180 if ( !desktop() || !desktop()->toolMgr() )
183 return desktop()->toolMgr()->insert( id, tBar, idx );
186 int SUIT_Application::createMenu( const QString& subMenu, const int menu,
187 const int id, const int group, const int index )
189 if ( !desktop() || !desktop()->menuMgr() )
192 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
195 int SUIT_Application::createMenu( const QString& subMenu, const QString& menu,
196 const int id, const int group, const int index )
198 if ( !desktop() || !desktop()->menuMgr() )
201 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
204 int SUIT_Application::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
206 if ( !a || !desktop() || !desktop()->menuMgr() )
209 int regId = desktop()->menuMgr()->registerAction( a, id );
210 return desktop()->menuMgr()->insert( regId, menu, group, index );
213 int SUIT_Application::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
215 if ( !a || !desktop() || !desktop()->menuMgr() )
218 int regId = desktop()->menuMgr()->registerAction( a, id );
219 return desktop()->menuMgr()->insert( regId, menu, group, index );
222 int SUIT_Application::createMenu( const int id, const int menu, const int group, const int index )
224 if ( !desktop() || !desktop()->menuMgr() )
227 return desktop()->menuMgr()->insert( id, menu, group, index );
230 int SUIT_Application::createMenu( const int id, const QString& menu, const int group, const int index )
232 if ( !desktop() || !desktop()->menuMgr() )
235 return desktop()->menuMgr()->insert( id, menu, group, index );
238 void SUIT_Application::setMenuShown( QAction* a, const bool on )
240 setMenuShown( actionId( a ), on );
243 void SUIT_Application::setMenuShown( const int id, const bool on )
245 if ( desktop() && desktop()->menuMgr() )
246 desktop()->menuMgr()->setShown( id, on );
249 void SUIT_Application::setToolShown( QAction* a, const bool on )
251 setToolShown( actionId( a ), on );
254 void SUIT_Application::setToolShown( const int id, const bool on )
256 if ( desktop() && desktop()->toolMgr() )
257 desktop()->toolMgr()->setShown( id, on );
260 QAction* SUIT_Application::action( const int id ) const
262 SUIT_Application* that = (SUIT_Application*)this;
263 SUIT_Desktop* desk = that->desktop();
268 if ( desk->menuMgr() )
269 a = desk->menuMgr()->action( id );
270 if ( !a && desk->toolMgr() )
271 a = desk->toolMgr()->action( id );
275 int SUIT_Application::actionId( const QAction* a ) const
277 SUIT_Application* that = (SUIT_Application*)this;
278 SUIT_Desktop* desk = that->desktop();
283 if ( desk->menuMgr() )
284 id = desk->menuMgr()->actionId( a );
285 if ( id == -1 && desk->toolMgr() )
286 id = desk->toolMgr()->actionId( a );
290 QAction* SUIT_Application::createAction( const int id, const QString& text, const QIconSet& icon,
291 const QString& menu, const QString& tip, const int key,
292 QObject* parent, const bool toggle, QObject* reciever, const char* member )
294 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
295 a->setStatusTip( tip );
297 if ( reciever && member )
298 connect( a, SIGNAL( activated() ), reciever, member );
300 registerAction( id, a );
305 void SUIT_Application::registerAction( const int id, QAction* a )
307 if ( desktop() && desktop()->menuMgr() )
308 desktop()->menuMgr()->registerAction( a, id );
310 if ( desktop() && desktop()->toolMgr() )
311 desktop()->toolMgr()->registerAction( a, id );
314 QAction* SUIT_Application::separator()
316 return QtxActionMgr::separator();
319 void SUIT_Application::onDesktopActivated()
321 emit activated( this );