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()
31 SUIT_Desktop* SUIT_Application::desktop()
36 bool SUIT_Application::isPossibleToClose()
41 void SUIT_Application::closeApplication()
43 emit applicationClosed( this );
46 SUIT_Study* SUIT_Application::activeStudy() const
51 QString SUIT_Application::applicationVersion() const
56 void SUIT_Application::start()
62 bool SUIT_Application::useFile( const QString& theFileName )
65 SUIT_Study* study = activeStudy();
67 bool status = study ? study->openDocument( theFileName ) : false;
78 bool SUIT_Application::useStudy( const QString& theName )
83 void SUIT_Application::createEmptyStudy()
86 setActiveStudy( createNewStudy() );
89 int SUIT_Application::getNbStudies() const
91 return activeStudy() ? 1 : 0;
94 SUIT_ResourceMgr* SUIT_Application::resourceMgr() const
96 if ( !SUIT_Session::session() )
99 return SUIT_Session::session()->resourceMgr();
102 #define DEFAULT_MESSAGE_DELAY 3000
103 void SUIT_Application::putInfo ( const QString& msg, const int msec )
106 //desktop()->statusBar()->message( msg, msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec );
107 if ( !myStatusLabel ) {
108 myStatusLabel = new QLabel (desktop()->statusBar());
109 desktop()->statusBar()->addWidget(myStatusLabel, /*int stretch = */1);
111 myStatusLabel->setText(msg);
113 QTimer::singleShot(msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT(clear()));
117 SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const
119 return startApplication( name(), argc, argv );
122 SUIT_Application* SUIT_Application::startApplication( const QString& name, int argc, char** argv ) const
124 SUIT_Session* session = SUIT_Session::session();
128 return session->startApplication( name, argc, argv );
131 void SUIT_Application::setDesktop( SUIT_Desktop* desk )
133 if ( myDesktop == desk )
139 connect( myDesktop, SIGNAL( activated() ), this, SLOT( onDesktopActivated() ) );
142 SUIT_Study* SUIT_Application::createNewStudy()
144 return new SUIT_Study( this );
147 void SUIT_Application::setActiveStudy( SUIT_Study* study )
149 if ( myStudy == study )
155 int SUIT_Application::createTool( const QString& name )
157 if ( !desktop() || !desktop()->toolMgr() )
160 return desktop()->toolMgr()->createToolBar( name );
163 int SUIT_Application::createTool( QAction* a, const int tBar, const int id, const int idx )
165 if ( !desktop() || !desktop()->toolMgr() )
168 int regId = desktop()->toolMgr()->registerAction( a, id );
169 return desktop()->toolMgr()->insert( regId, tBar, idx );
172 int SUIT_Application::createTool( QAction* a, const QString& tBar, const int id, const int idx )
174 if ( !desktop() || !desktop()->toolMgr() )
177 return desktop()->toolMgr()->insert( a, tBar, idx );
180 int SUIT_Application::createTool( const int id, const int tBar, const int idx )
182 if ( !desktop() || !desktop()->toolMgr() )
185 return desktop()->toolMgr()->insert( id, tBar, idx );
188 int SUIT_Application::createTool( const int id, const QString& tBar, const int idx )
190 if ( !desktop() || !desktop()->toolMgr() )
193 return desktop()->toolMgr()->insert( id, tBar, idx );
196 int SUIT_Application::createMenu( const QString& subMenu, const int menu,
197 const int id, const int group, const int index )
199 if ( !desktop() || !desktop()->menuMgr() )
202 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
205 int SUIT_Application::createMenu( const QString& subMenu, const QString& menu,
206 const int id, const int group, const int index )
208 if ( !desktop() || !desktop()->menuMgr() )
211 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
214 int SUIT_Application::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
216 if ( !a || !desktop() || !desktop()->menuMgr() )
219 int regId = desktop()->menuMgr()->registerAction( a, id );
220 return desktop()->menuMgr()->insert( regId, menu, group, index );
223 int SUIT_Application::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
225 if ( !a || !desktop() || !desktop()->menuMgr() )
228 int regId = desktop()->menuMgr()->registerAction( a, id );
229 return desktop()->menuMgr()->insert( regId, menu, group, index );
232 int SUIT_Application::createMenu( const int id, const int menu, const int group, const int index )
234 if ( !desktop() || !desktop()->menuMgr() )
237 return desktop()->menuMgr()->insert( id, menu, group, index );
240 int SUIT_Application::createMenu( const int id, const QString& menu, const int group, const int index )
242 if ( !desktop() || !desktop()->menuMgr() )
245 return desktop()->menuMgr()->insert( id, menu, group, index );
248 void SUIT_Application::setMenuShown( QAction* a, const bool on )
250 setMenuShown( actionId( a ), on );
253 void SUIT_Application::setMenuShown( const int id, const bool on )
255 if ( desktop() && desktop()->menuMgr() )
256 desktop()->menuMgr()->setShown( id, on );
259 void SUIT_Application::setToolShown( QAction* a, const bool on )
261 setToolShown( actionId( a ), on );
264 void SUIT_Application::setToolShown( const int id, const bool on )
266 if ( desktop() && desktop()->toolMgr() )
267 desktop()->toolMgr()->setShown( id, on );
270 void SUIT_Application::setActionShown( QAction* a, const bool on )
272 setMenuShown( a, on );
273 setToolShown( a, on );
276 void SUIT_Application::setActionShown( const int id, const bool on )
278 setMenuShown( id, on );
279 setToolShown( id, on );
282 QAction* SUIT_Application::action( const int id ) const
284 SUIT_Application* that = (SUIT_Application*)this;
285 SUIT_Desktop* desk = that->desktop();
290 if ( desk->menuMgr() )
291 a = desk->menuMgr()->action( id );
292 if ( !a && desk->toolMgr() )
293 a = desk->toolMgr()->action( id );
297 int SUIT_Application::actionId( const QAction* a ) const
299 SUIT_Application* that = (SUIT_Application*)this;
300 SUIT_Desktop* desk = that->desktop();
305 if ( desk->menuMgr() )
306 id = desk->menuMgr()->actionId( a );
307 if ( id == -1 && desk->toolMgr() )
308 id = desk->toolMgr()->actionId( a );
312 QAction* SUIT_Application::createAction( const int id, const QString& text, const QIconSet& icon,
313 const QString& menu, const QString& tip, const int key,
314 QObject* parent, const bool toggle, QObject* reciever, const char* member )
316 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
317 a->setStatusTip( tip );
319 if ( reciever && member )
320 connect( a, SIGNAL( activated() ), reciever, member );
322 registerAction( id, a );
327 void SUIT_Application::registerAction( const int id, QAction* a )
329 if ( desktop() && desktop()->menuMgr() )
330 desktop()->menuMgr()->registerAction( a, id );
332 if ( desktop() && desktop()->toolMgr() )
333 desktop()->toolMgr()->registerAction( a, id );
336 QAction* SUIT_Application::separator()
338 return QtxActionMgr::separator();
341 void SUIT_Application::onDesktopActivated()
343 emit activated( this );