1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "STD_Application.h"
25 #include "STD_MDIDesktop.h"
27 #include <SUIT_Tools.h>
28 #include <SUIT_Study.h>
29 #include <SUIT_Desktop.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_MessageBox.h>
32 #include <SUIT_ViewManager.h>
33 #include <SUIT_ResourceMgr.h>
35 #include <QtxDockAction.h>
37 #include <QtxActionMenuMgr.h>
38 #include <QtxActionToolMgr.h>
42 #include <QCloseEvent>
43 #include <QFileDialog>
44 #include <QApplication>
46 /*!Create and return new instance of STD_Application*/
47 extern "C" STD_EXPORT SUIT_Application* createApplication()
49 return new STD_Application();
53 STD_Application::STD_Application()
56 myExitConfirm( true ),
59 setDesktop( new STD_MDIDesktop() );
63 STD_Application::~STD_Application()
68 /*! \retval requirement of exit confirmation*/
69 bool STD_Application::exitConfirmation() const
74 /*! Set the requirement of exit confirmation*/
75 void STD_Application::setExitConfirmation( const bool on )
80 /*! \retval QString "StdApplication"*/
81 QString STD_Application::applicationName() const
83 return QString( "StdApplication" );
86 /*!Start STD_Application*/
87 void STD_Application::start()
92 updateCommandsStatus();
93 setEditEnabled( myEditEnabled );
97 SUIT_Application::start();
101 Close the Application
103 void STD_Application::closeApplication()
107 SUIT_Study* study = activeStudy();
111 beforeCloseDoc( study );
113 study->closeDocument();
123 SUIT_Application::closeApplication();
126 /*!Event on closing desktop*/
127 void STD_Application::onDesktopClosing( SUIT_Desktop*, QCloseEvent* e )
129 if ( SUIT_Session::session()->applications().count() < 2 )
135 bool closePermanently;
136 if ( !isPossibleToClose( closePermanently ) )
145 /*!Create actions, menus and tools*/
146 void STD_Application::createActions()
148 SUIT_Desktop* desk = desktop();
149 SUIT_ResourceMgr* resMgr = resourceMgr();
150 if ( !desk || !resMgr )
155 createAction( FileNewId, tr( "TOT_DESK_FILE_NEW" ),
156 resMgr->loadPixmap( "STD", tr( "ICON_FILE_NEW" ) ),
157 tr( "MEN_DESK_FILE_NEW" ), tr( "PRP_DESK_FILE_NEW" ),
158 Qt::CTRL+Qt::Key_N, desk, false, this, SLOT( onNewDoc() ) );
160 createAction( FileOpenId, tr( "TOT_DESK_FILE_OPEN" ),
161 resMgr->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ),
162 tr( "MEN_DESK_FILE_OPEN" ), tr( "PRP_DESK_FILE_OPEN" ),
163 Qt::CTRL+Qt::Key_O, desk, false, this, SLOT( onOpenDoc() ) );
165 createAction( FileReopenId, tr( "TOT_DESK_FILE_REOPEN" ), QIcon(),
166 tr( "MEN_DESK_FILE_REOPEN" ), tr( "PRP_DESK_FILE_REOPEN" ),
167 0, desk, false, this, SLOT( onReopenDoc() ) );
169 createAction( FileCloseId, tr( "TOT_DESK_FILE_CLOSE" ),
170 resMgr->loadPixmap( "STD", tr( "ICON_FILE_CLOSE" ) ),
171 tr( "MEN_DESK_FILE_CLOSE" ), tr( "PRP_DESK_FILE_CLOSE" ),
172 Qt::CTRL+Qt::Key_W, desk, false, this, SLOT( onCloseDoc() ) );
174 createAction( FileExitId, tr( "TOT_DESK_FILE_EXIT" ), QIcon(),
175 tr( "MEN_DESK_FILE_EXIT" ), tr( "PRP_DESK_FILE_EXIT" ),
176 Qt::CTRL+Qt::Key_Q, desk, false, this, SLOT( onExit() ) );
178 createAction( FileSaveId, tr( "TOT_DESK_FILE_SAVE" ),
179 resMgr->loadPixmap( "STD", tr( "ICON_FILE_SAVE" ) ),
180 tr( "MEN_DESK_FILE_SAVE" ), tr( "PRP_DESK_FILE_SAVE" ),
181 Qt::CTRL+Qt::Key_S, desk, false, this, SLOT( onSaveDoc() ) );
183 createAction( FileSaveAsId, tr( "TOT_DESK_FILE_SAVEAS" ), QIcon(),
184 tr( "MEN_DESK_FILE_SAVEAS" ), tr( "PRP_DESK_FILE_SAVEAS" ),
185 Qt::CTRL+Qt::SHIFT+Qt::Key_S, desk, false, this, SLOT( onSaveAsDoc() ) );
187 createAction( EditCopyId, tr( "TOT_DESK_EDIT_COPY" ),
188 resMgr->loadPixmap( "STD", tr( "ICON_EDIT_COPY" ) ),
189 tr( "MEN_DESK_EDIT_COPY" ), tr( "PRP_DESK_EDIT_COPY" ),
190 Qt::CTRL+Qt::Key_C, desk, false, this, SLOT( onCopy() ) );
192 createAction( EditPasteId, tr( "TOT_DESK_EDIT_PASTE" ),
193 resMgr->loadPixmap( "STD", tr( "ICON_EDIT_PASTE" ) ),
194 tr( "MEN_DESK_EDIT_PASTE" ), tr( "PRP_DESK_EDIT_PASTE" ),
195 Qt::CTRL+Qt::Key_V, desk, false, this, SLOT( onPaste() ) );
197 QAction* a = createAction( ViewStatusBarId, tr( "TOT_DESK_VIEW_STATUSBAR" ),
198 QIcon(), tr( "MEN_DESK_VIEW_STATUSBAR" ),
199 tr( "PRP_DESK_VIEW_STATUSBAR" ), Qt::ALT+Qt::SHIFT+Qt::Key_S, desk, true );
200 a->setChecked( desk->statusBar()->isVisibleTo( desk ) );
201 connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onViewStatusBar( bool ) ) );
203 createAction( NewWindowId, tr( "TOT_DESK_NEWWINDOW" ), QIcon(),
204 tr( "MEN_DESK_NEWWINDOW" ), tr( "PRP_DESK_NEWWINDOW" ), 0, desk );
206 createAction( HelpAboutId, tr( "TOT_DESK_HELP_ABOUT" ), QIcon(),
207 tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ),
208 Qt::ALT+Qt::SHIFT+Qt::Key_A, desk, false, this, SLOT( onHelpAbout() ) );
211 QtxDockAction* dwa = new QtxDockAction( tr( "TOT_DOCKWINDOWS" ), tr( "MEN_DESK_VIEW_DOCKWINDOWS" ), desk );
212 dwa->setDockType( QtxDockAction::DockWidget );
213 registerAction( ViewWindowsId, dwa );
215 QtxDockAction* tba = new QtxDockAction( tr( "TOT_TOOLBARS" ), tr( "MEN_DESK_VIEW_TOOLBARS" ), desk );
216 tba->setDockType( QtxDockAction::ToolBar );
217 registerAction( ViewToolBarsId, tba );
221 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, MenuFileId, 0 );
222 // Let the application developers insert some menus between Edit and View
223 int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, MenuEditId, 5 );
224 int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1, MenuViewId, 10 );
225 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, MenuHelpId, 1000 );
229 createMenu( FileNewId, fileMenu, 0 );
230 createMenu( FileOpenId, fileMenu, 0 );
231 createMenu( FileReopenId, fileMenu, 0 );
232 createMenu( FileSaveId, fileMenu, 5 );
233 createMenu( FileSaveAsId, fileMenu, 5 );
234 createMenu( FileCloseId, fileMenu, 5 );
235 createMenu( separator(), fileMenu, -1, 5 );
237 createMenu( separator(), fileMenu );
238 createMenu( FileExitId, fileMenu );
240 createMenu( EditCopyId, editMenu );
241 createMenu( EditPasteId, editMenu );
242 createMenu( separator(), editMenu );
244 createMenu( ViewToolBarsId, viewMenu, 0 );
245 createMenu( ViewWindowsId, viewMenu, 0 );
246 createMenu( separator(), viewMenu, -1, 10 );
247 createMenu( ViewStatusBarId, viewMenu, 10 );
248 createMenu( separator(), viewMenu );
250 createMenu( HelpAboutId, helpMenu );
251 createMenu( separator(), helpMenu );
255 int stdTBar = createTool( tr( "INF_DESK_TOOLBAR_STANDARD" ), // title (language-dependant)
256 QString( "SalomeStandard" ) ); // name (language-independant)
260 createTool( FileNewId, stdTBar );
261 createTool( FileOpenId, stdTBar );
262 createTool( FileSaveId, stdTBar );
263 createTool( FileCloseId, stdTBar );
264 createTool( separator(), stdTBar );
265 createTool( EditCopyId, stdTBar );
266 createTool( EditPasteId, stdTBar );
269 /*!Opens new application*/
270 void STD_Application::onNewDoc()
272 onNewDoc( QString() );
275 /*!Opens new application*/
276 bool STD_Application::onNewDoc( const QString& name )
278 QApplication::setOverrideCursor( Qt::WaitCursor );
281 if ( !activeStudy() )
284 res = activeStudy()->createDocument( name );
286 studyCreated( activeStudy() );
289 SUIT_Study* st = activeStudy();
296 SUIT_Application* aApp = startApplication( 0, 0 );
297 if ( aApp->inherits( "STD_Application" ) )
298 res = ((STD_Application*)aApp)->onNewDoc( name );
301 aApp->createEmptyStudy();
302 res = aApp->activeStudy()->createDocument( name );
305 aApp->closeApplication();
308 QApplication::restoreOverrideCursor();
313 /*!Put file name from file dialog to onOpenDoc(const QString&) function*/
314 void STD_Application::onOpenDoc()
316 // It is preferrable to use OS-specific file dialog box here !!!
317 QString aName = getFileName( true, QString(), getFileFilter(), QString(), 0 );
318 if ( aName.isNull() )
324 /*! \retval true, if document was opened successful, else false.*/
325 bool STD_Application::onOpenDoc( const QString& aName )
327 QApplication::setOverrideCursor( Qt::WaitCursor );
329 bool res = openAction( openChoice( aName ), aName );
331 QApplication::restoreOverrideCursor();
336 /*! Reload document from the file.*/
337 bool STD_Application::onReopenDoc()
341 SUIT_Study* study = activeStudy();
342 if ( study && study->isSaved() ) {
343 // ask user for the confirmation
344 if ( SUIT_MessageBox::question( desktop(), tr( "REOPEN_STUDY" ), tr( "REOPEN_QUESTION" ),
345 SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No
346 ) == SUIT_MessageBox::No )
349 // remember study name
350 QString studyName = study->studyName();
353 beforeCloseDoc( study );
354 study->closeDocument( true );
356 // update views / windows / status bar / title
359 updateDesktopTitle();
360 updateCommandsStatus();
366 // post closing actions
369 // reload study from the file
370 res = useFile( studyName ) && activeStudy();
372 // if reloading is failed, close the desktop
381 /*!Virtual function. Not implemented here.*/
382 void STD_Application::beforeCloseDoc( SUIT_Study* )
386 /*!Virtual function. Not implemented here.*/
387 void STD_Application::afterCloseDoc()
391 /*!Close document, if it's possible.*/
392 void STD_Application::onCloseDoc( bool ask )
397 /*!Close document, if it's possible.*/
398 bool STD_Application::closeDoc( bool ask )
400 bool closePermanently = true;
402 if ( ask && !isPossibleToClose( closePermanently ) )
405 return closeActiveDoc( closePermanently );
409 bool STD_Application::closeActiveDoc( bool permanently )
411 SUIT_Study* study = activeStudy();
412 if ( !study ) // no active study
415 beforeCloseDoc( study );
418 study->closeDocument( permanently );
425 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
426 for ( int i = 0; i < apps.count(); i++ )
427 aNbStudies += apps.at( i )->getNbStudies();
436 updateDesktopTitle();
437 updateCommandsStatus();
440 // IPAL19532: deleting study should be performed after calling setDesktop(0)
450 /*!Check the application on closing.
451 * \retval true if possible, else false
453 bool STD_Application::isPossibleToClose( bool& closePermanently )
457 activeStudy()->abortAllOperations();
458 if ( activeStudy()->isModified() )
460 QString sName = activeStudy()->studyName().trimmed();
461 return closeAction( closeChoice( sName ), closePermanently );
467 int STD_Application::closeChoice( const QString& docName )
469 int answer = SUIT_MessageBox::question( desktop(), tr( "CLOSE_STUDY" ), tr( "CLOSE_QUESTION" ),
470 SUIT_MessageBox::Save | SUIT_MessageBox::Discard | SUIT_MessageBox::Cancel,
471 SUIT_MessageBox::Save );
473 int res = CloseCancel;
474 if ( answer == SUIT_MessageBox::Save )
476 else if ( answer == SUIT_MessageBox::Discard )
482 bool STD_Application::closeAction( const int choice, bool& closePermanently )
488 if ( activeStudy()->isSaved() )
490 else if ( !onSaveAsDoc() )
503 int STD_Application::openChoice( const QString& aName )
505 SUIT_Session* aSession = SUIT_Session::session();
507 bool isAlreadyOpen = false;
508 QList<SUIT_Application*> aAppList = aSession->applications();
509 for ( QList<SUIT_Application*>::iterator it = aAppList.begin(); it != aAppList.end() && !isAlreadyOpen; ++it )
510 isAlreadyOpen = (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName;
511 return isAlreadyOpen ? OpenExist : OpenNew;
514 bool STD_Application::openAction( const int choice, const QString& aName )
521 SUIT_Application* aApp = 0;
522 SUIT_Session* aSession = SUIT_Session::session();
523 QList<SUIT_Application*> aAppList = aSession->applications();
524 for ( QList<SUIT_Application*>::iterator it = aAppList.begin(); it != aAppList.end() && !aApp; ++it )
526 if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName )
530 aApp->desktop()->activateWindow();
536 if ( !activeStudy() )
537 res = useFile( aName );
540 SUIT_Application* aApp = startApplication( 0, 0 );
542 res = aApp->useFile( aName );
544 aApp->closeApplication();
555 /*!Save document if all ok, else error message.*/
556 void STD_Application::onSaveDoc()
558 if ( !activeStudy() )
562 if ( activeStudy()->isSaved() )
564 putInfo( tr( "INF_DOC_SAVING" ) + activeStudy()->studyName() );
566 QApplication::setOverrideCursor( Qt::WaitCursor );
568 isOk = activeStudy()->saveDocument();
570 QApplication::restoreOverrideCursor();
575 // displaying a message box as SUIT_Validator in case file can't be written (the most frequent case)
576 SUIT_MessageBox::critical( desktop(), tr( "ERR_ERROR" ),
577 tr( "INF_DOC_SAVING_FAILS" ).arg( activeStudy()->studyName() ) );
580 putInfo( tr( "INF_DOC_SAVED" ).arg( "" ) );
584 studySaved( activeStudy() );
589 /*! \retval TRUE, if doument saved successful, else FALSE.*/
590 bool STD_Application::onSaveAsDoc()
592 SUIT_Study* study = activeStudy();
599 QString aName = getFileName( false, study->studyName(), getFileFilter(), QString(), 0 );
600 if ( aName.isNull() )
603 QApplication::setOverrideCursor( Qt::WaitCursor );
605 putInfo( tr( "INF_DOC_SAVING" ) + aName );
606 isOk = study->saveDocumentAs( aName );
608 putInfo( isOk ? tr( "INF_DOC_SAVED" ).arg( aName ) : "" );
610 QApplication::restoreOverrideCursor();
613 SUIT_MessageBox::critical( desktop(), tr( "ERROR" ), tr( "INF_DOC_SAVING_FAILS" ).arg( aName ) );
616 studySaved( activeStudy() );
621 /*!Closing session.*/
622 void STD_Application::onExit()
624 int aAnswer = SUIT_MessageBox::Ok;
625 if ( exitConfirmation() )
626 aAnswer = SUIT_MessageBox::question( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ),
627 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel, SUIT_MessageBox::Cancel );
628 if ( aAnswer == SUIT_MessageBox::Ok )
629 SUIT_Session::session()->closeSession();
632 /*!Virtual slot. Not implemented here.*/
633 void STD_Application::onCopy()
637 /*!Virtual slot. Not implemented here.*/
638 void STD_Application::onPaste()
642 /*!Sets \a theEnable for menu manager and for tool manager.*/
643 void STD_Application::setEditEnabled( bool theEnable )
645 myEditEnabled = theEnable;
647 QtxActionMenuMgr* mMgr = desktop()->menuMgr();
648 QtxActionToolMgr* tMgr = desktop()->toolMgr();
650 for ( int i = EditCopyId; i <= EditPasteId; i++ )
652 mMgr->setShown( mMgr->actionId(action(i)), myEditEnabled );
653 tMgr->setShown( tMgr->actionId(action(i)), myEditEnabled );
657 /*!\retval true, if document opened successful, else false.*/
658 bool STD_Application::useFile(const QString& theFileName)
660 bool res = SUIT_Application::useFile( theFileName );
663 studyOpened( activeStudy() );
668 /*!Update desktop title.*/
669 void STD_Application::updateDesktopTitle()
671 QString aTitle = applicationName();
672 QString aVer = applicationVersion();
673 if ( !aVer.isEmpty() )
674 aTitle += QString( " " ) + aVer;
678 QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false );
679 if ( !sName.isEmpty() )
680 aTitle += QString( " - [%1]" ).arg( sName );
683 desktop()->setWindowTitle( aTitle );
686 /*!Update commands status.*/
687 void STD_Application::updateCommandsStatus()
689 SUIT_Application::updateCommandsStatus();
691 bool aHasStudy = activeStudy() != 0;
692 bool aSaved = aHasStudy && activeStudy()->isSaved();
693 bool aModified = aHasStudy && activeStudy()->isModified();
694 bool aIsNeedToSave = aHasStudy && ( !aSaved || aModified );
696 if ( action( FileReopenId ) )
697 action( FileReopenId )->setEnabled( aSaved );
698 if ( action( FileSaveId ) )
699 action( FileSaveId )->setEnabled( aIsNeedToSave );
700 if ( action( FileSaveAsId ) )
701 action( FileSaveAsId )->setEnabled( aHasStudy );
702 if ( action( FileCloseId ) )
703 action( FileCloseId )->setEnabled( aHasStudy );
704 if ( action( NewWindowId ) )
705 action( NewWindowId )->setEnabled( aHasStudy );
708 /*!\retval SUIT_ViewManager by viewer manager type name.*/
709 SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const
711 SUIT_ViewManager* vm = 0;
712 for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end() && !vm; ++it )
714 if ( (*it)->getType() == vmType )
720 /*! \param vmType - input view manager type name
721 * \param lst - output list of view managers with types \a vmType.
723 void STD_Application::viewManagers( const QString& vmType, ViewManagerList& lst ) const
725 for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end(); ++it )
727 if ( (*it)->getType() == vmType )
732 /*!\param lst - output list of all view managers.*/
733 void STD_Application::viewManagers( ViewManagerList& lst ) const
735 for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end(); ++it )
739 /*!\retval ViewManagerList - const list of all view managers.*/
740 ViewManagerList STD_Application::viewManagers() const
747 /*!\retval SUIT_ViewManager - return pointer to active view manager.*/
748 SUIT_ViewManager* STD_Application::activeViewManager() const
750 return myActiveViewMgr;
753 /*!Add view manager to view managers list, if it not already there.*/
754 void STD_Application::addViewManager( SUIT_ViewManager* vm )
759 if ( !containsViewManager( vm ) )
761 myViewMgrs.append( vm );
762 connect( vm, SIGNAL( activated( SUIT_ViewManager* ) ),
763 this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
764 vm->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
766 emit viewManagerAdded( vm );
769 if ( !activeViewManager() && myViewMgrs.count() == 1 )
770 setActiveViewManager( vm );
774 /*!Remove view manager from view managers list.*/
775 void STD_Application::removeViewManager( SUIT_ViewManager* vm )
782 emit viewManagerRemoved( vm );
784 vm->disconnectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
785 disconnect( vm, SIGNAL( activated( SUIT_ViewManager* ) ),
786 this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
787 myViewMgrs.removeAll( vm );
789 if ( myActiveViewMgr == vm )
793 /*!Remove all view managers from view managers list.*/
794 void STD_Application::clearViewManagers()
799 for ( QList<SUIT_ViewManager*>::iterator it = lst.begin(); it != lst.end(); ++it )
801 QPointer<SUIT_ViewManager> vm = *it;
802 removeViewManager( vm );
807 /*!\retval TRUE, if view manager \a vm, already in view manager list (\a myViewMgrs).*/
808 bool STD_Application::containsViewManager( SUIT_ViewManager* vm ) const
810 return myViewMgrs.contains( vm );
813 /*!Private slot, sets active manager to \vm, if \vm in view managers list.*/
814 void STD_Application::onViewManagerActivated( SUIT_ViewManager* vm )
816 setActiveViewManager( vm );
819 /*!Sets status bar show, if \on = true, else status bar hide.*/
820 void STD_Application::onViewStatusBar( bool on )
823 desktop()->statusBar()->show();
825 desktop()->statusBar()->hide();
828 /*!Call SUIT_MessageBox::info1(...) with about information.*/
829 void STD_Application::onHelpAbout()
831 SUIT_MessageBox::information( desktop(), tr( "About" ), tr( "ABOUT_INFO" ) );
834 /*!Create empty study. \n
835 * Create new view manager and adding it to view managers list.
837 void STD_Application::createEmptyStudy()
839 SUIT_Application::createEmptyStudy();
842 /*!Sets active manager to \vm, if \vm in view managers list.*/
843 void STD_Application::setActiveViewManager( SUIT_ViewManager* vm )
845 if ( !containsViewManager( vm ) )
848 myActiveViewMgr = vm;
849 emit viewManagerActivated( vm );
853 void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextMenuEvent* e )
855 QtxMenu* popup = new QtxMenu();
856 // fill popup by own items
858 contextMenuPopup( client->popupClientType(), popup, title );
859 popup->setTitleText( title );
861 popup->addSeparator();
862 // add items from popup client
863 client->contextMenuPopup( popup );
865 SUIT_Tools::simplifySeparators( popup );
867 if ( !popup->actions().isEmpty() )
868 popup->exec( e->globalPos() );
872 /*!\retval QString - return file name from dialog.*/
873 QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters,
874 const QString& caption, QWidget* parent )
879 return QFileDialog::getOpenFileName( parent, caption, initial, filters );
884 QString anOldPath = initial;
889 // It is preferrable to use OS-specific file dialog box here !!!
890 aName = QFileDialog::getSaveFileName( parent, caption, anOldPath, filters, &aUsedFilter );
892 if ( aName.isNull() )
896 int aEnd = aUsedFilter.lastIndexOf( ')' );
897 int aStart = aUsedFilter.lastIndexOf( '(', aEnd );
898 QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 );
902 QRegExp rx( "[\b\\*]*\\.([\\w]+)" );
903 while ( ( idx = rx.indexIn( wcStr, idx ) ) != -1 )
905 extList.append( rx.cap( 1 ) );
906 idx += rx.matchedLength();
909 if ( !extList.isEmpty() && !extList.contains( SUIT_Tools::extension( aName ) ) )
910 aName += QString( ".%1" ).arg( extList.first() );
912 if ( QFileInfo( aName ).exists() )
914 int aAnswer = SUIT_MessageBox::question( desktop(), tr( "TIT_FILE_SAVEAS" ),
915 tr( "MSG_FILE_EXISTS" ).arg( aName ),
916 SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel, SUIT_MessageBox::Yes );
917 if ( aAnswer == SUIT_MessageBox::Cancel )
922 else if ( aAnswer == SUIT_MessageBox::No ) // not save to this file
923 anOldPath = aName; // not to return to the same initial dir at each "while" step
924 else // overwrite the existing file
935 /*!\retval QString - return directory name from dialog.*/
936 QString STD_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
941 return QFileDialog::getExistingDirectory( parent, caption, initial );
946 \param desk - new desktop
948 void STD_Application::setDesktop( SUIT_Desktop* desk )
950 SUIT_Application::setDesktop( desk );
953 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
954 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ), Qt::UniqueConnection );
959 Allow to load preferences before the desktop will be shown.
961 void STD_Application::loadPreferences()
966 Allow to save preferences before the application will be closed.
968 void STD_Application::savePreferences()
973 Custom activity after study is created
974 Updates desktop and actions
976 void STD_Application::studyCreated( SUIT_Study* )
978 updateDesktopTitle();
979 updateCommandsStatus();
983 Custom activity after study is opened
984 Updates desktop and actions
986 void STD_Application::studyOpened( SUIT_Study* )
988 updateDesktopTitle();
989 updateCommandsStatus();
993 Custom activity after study is opened
994 Updates desktop and actions
996 void STD_Application::studySaved( SUIT_Study* )
998 updateDesktopTitle();
999 updateCommandsStatus();
1003 Return index of the view ma
1005 int STD_Application::viewManagerId( const SUIT_ViewManager* theManager) const
1007 return myViewMgrs.indexOf(const_cast<SUIT_ViewManager*>(theManager));