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);
102 QTimer::singleShot(msec <= 0 ? DEFAULT_MESSAGE_DELAY : msec, myStatusLabel, SLOT(clear()));
106 SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const
108 return startApplication( name(), argc, argv );
111 SUIT_Application* SUIT_Application::startApplication( const QString& name, int argc, char** argv ) const
113 SUIT_Session* session = SUIT_Session::session();
117 return session->startApplication( name, argc, argv );
120 void SUIT_Application::setDesktop( SUIT_Desktop* desk )
122 if ( myDesktop == desk )
128 connect( myDesktop, SIGNAL( activated() ), this, SLOT( onDesktopActivated() ) );
131 SUIT_Study* SUIT_Application::createNewStudy()
133 return new SUIT_Study( this );
136 void SUIT_Application::setActiveStudy( SUIT_Study* study )
138 if ( myStudy == study )
144 int SUIT_Application::createTool( const QString& name )
146 if ( !desktop() || !desktop()->toolMgr() )
149 return desktop()->toolMgr()->createToolBar( name );
152 int SUIT_Application::createTool( QAction* a, const int tBar, const int id, const int idx )
154 if ( !desktop() || !desktop()->toolMgr() )
157 int regId = desktop()->toolMgr()->registerAction( a, id );
158 return desktop()->toolMgr()->insert( regId, tBar, idx );
161 int SUIT_Application::createTool( QAction* a, const QString& tBar, const int id, const int idx )
163 if ( !desktop() || !desktop()->toolMgr() )
166 return desktop()->toolMgr()->insert( a, tBar, idx );
169 int SUIT_Application::createTool( const int id, const int tBar, const int idx )
171 if ( !desktop() || !desktop()->toolMgr() )
174 return desktop()->toolMgr()->insert( id, tBar, idx );
177 int SUIT_Application::createTool( const int id, const QString& tBar, const int idx )
179 if ( !desktop() || !desktop()->toolMgr() )
182 return desktop()->toolMgr()->insert( id, tBar, idx );
185 int SUIT_Application::createMenu( const QString& subMenu, const int menu,
186 const int id, const int group, const int index )
188 if ( !desktop() || !desktop()->menuMgr() )
191 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
194 int SUIT_Application::createMenu( const QString& subMenu, const QString& menu,
195 const int id, const int group, const int index )
197 if ( !desktop() || !desktop()->menuMgr() )
200 return desktop()->menuMgr()->insert( subMenu, menu, group, index );
203 int SUIT_Application::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
205 if ( !a || !desktop() || !desktop()->menuMgr() )
208 int regId = desktop()->menuMgr()->registerAction( a, id );
209 return desktop()->menuMgr()->insert( regId, menu, group, index );
212 int SUIT_Application::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
214 if ( !a || !desktop() || !desktop()->menuMgr() )
217 int regId = desktop()->menuMgr()->registerAction( a, id );
218 return desktop()->menuMgr()->insert( regId, menu, group, index );
221 int SUIT_Application::createMenu( const int id, const int menu, const int group, const int index )
223 if ( !desktop() || !desktop()->menuMgr() )
226 return desktop()->menuMgr()->insert( id, menu, group, index );
229 int SUIT_Application::createMenu( const int id, const QString& menu, const int group, const int index )
231 if ( !desktop() || !desktop()->menuMgr() )
234 return desktop()->menuMgr()->insert( id, menu, group, index );
237 void SUIT_Application::setMenuShown( QAction* a, const bool on )
239 setMenuShown( actionId( a ), on );
242 void SUIT_Application::setMenuShown( const int id, const bool on )
244 if ( desktop() && desktop()->menuMgr() )
245 desktop()->menuMgr()->setShown( id, on );
248 void SUIT_Application::setToolShown( QAction* a, const bool on )
250 setToolShown( actionId( a ), on );
253 void SUIT_Application::setToolShown( const int id, const bool on )
255 if ( desktop() && desktop()->toolMgr() )
256 desktop()->toolMgr()->setShown( id, on );
259 QAction* SUIT_Application::action( const int id ) const
261 SUIT_Application* that = (SUIT_Application*)this;
262 SUIT_Desktop* desk = that->desktop();
267 if ( desk->menuMgr() )
268 a = desk->menuMgr()->action( id );
269 if ( !a && desk->toolMgr() )
270 a = desk->toolMgr()->action( id );
274 int SUIT_Application::actionId( const QAction* a ) const
276 SUIT_Application* that = (SUIT_Application*)this;
277 SUIT_Desktop* desk = that->desktop();
282 if ( desk->menuMgr() )
283 id = desk->menuMgr()->actionId( a );
284 if ( id == -1 && desk->toolMgr() )
285 id = desk->toolMgr()->actionId( a );
289 QAction* SUIT_Application::createAction( const int id, const QString& text, const QIconSet& icon,
290 const QString& menu, const QString& tip, const int key,
291 QObject* parent, const bool toggle, QObject* reciever, const char* member )
293 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
294 a->setStatusTip( tip );
296 if ( reciever && member )
297 connect( a, SIGNAL( activated() ), reciever, member );
299 registerAction( id, a );
304 void SUIT_Application::registerAction( const int id, QAction* a )
306 if ( desktop() && desktop()->menuMgr() )
307 desktop()->menuMgr()->registerAction( a, id );
309 if ( desktop() && desktop()->toolMgr() )
310 desktop()->toolMgr()->registerAction( a, id );
313 QAction* SUIT_Application::separator()
315 return QtxActionMgr::separator();
318 void SUIT_Application::onDesktopActivated()
320 emit activated( this );