1 // Copyright (C) 2007-2016 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" ),
207 resMgr->loadPixmap( "STD", tr( "ICON_DESK_ABOUT" ) ),
208 tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ),
209 Qt::ALT+Qt::SHIFT+Qt::Key_A, desk, false, this, SLOT( onHelpAbout() ) );
212 QtxDockAction* dwa = new QtxDockAction( tr( "TOT_DOCKWINDOWS" ), tr( "MEN_DESK_VIEW_DOCKWINDOWS" ), desk );
213 dwa->setDockType( QtxDockAction::DockWidget );
214 registerAction( ViewWindowsId, dwa );
216 QtxDockAction* tba = new QtxDockAction( tr( "TOT_TOOLBARS" ), tr( "MEN_DESK_VIEW_TOOLBARS" ), desk );
217 tba->setDockType( QtxDockAction::ToolBar );
218 registerAction( ViewToolBarsId, tba );
222 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, MenuFileId, 0 );
223 // Let the application developers insert some menus between Edit and View
224 int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, MenuEditId, 5 );
225 int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1, MenuViewId, 10 );
226 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, MenuHelpId, 1000 );
230 createMenu( FileNewId, fileMenu, 0 );
231 createMenu( FileOpenId, fileMenu, 0 );
232 createMenu( FileReopenId, fileMenu, 0 );
233 createMenu( FileSaveId, fileMenu, 5 );
234 createMenu( FileSaveAsId, fileMenu, 5 );
235 createMenu( FileCloseId, fileMenu, 5 );
236 createMenu( separator(), fileMenu, -1, 5 );
238 createMenu( separator(), fileMenu );
239 createMenu( FileExitId, fileMenu );
241 createMenu( EditCopyId, editMenu );
242 createMenu( EditPasteId, editMenu );
243 createMenu( separator(), editMenu );
245 createMenu( ViewToolBarsId, viewMenu, 0 );
246 createMenu( ViewWindowsId, viewMenu, 0 );
247 createMenu( separator(), viewMenu, -1, 10 );
248 createMenu( ViewStatusBarId, viewMenu, 10 );
249 createMenu( separator(), viewMenu );
251 createMenu( HelpAboutId, helpMenu );
252 createMenu( separator(), helpMenu );
256 int stdTBar = createTool( tr( "INF_DESK_TOOLBAR_STANDARD" ), // title (language-dependant)
257 QString( "SalomeStandard" ) ); // name (language-independant)
261 createTool( FileNewId, stdTBar );
262 createTool( FileOpenId, stdTBar );
263 createTool( FileSaveId, stdTBar );
264 createTool( FileCloseId, stdTBar );
265 createTool( separator(), stdTBar );
266 createTool( EditCopyId, stdTBar );
267 createTool( EditPasteId, stdTBar );
270 /*!Opens new application*/
271 void STD_Application::onNewDoc()
273 onNewDoc( QString() );
276 /*!Opens new application*/
277 bool STD_Application::onNewDoc( const QString& name )
279 QApplication::setOverrideCursor( Qt::WaitCursor );
282 if ( !activeStudy() )
285 res = activeStudy()->createDocument( name );
287 studyCreated( activeStudy() );
290 SUIT_Study* st = activeStudy();
297 SUIT_Application* aApp = startApplication( 0, 0 );
298 if ( aApp->inherits( "STD_Application" ) )
299 res = ((STD_Application*)aApp)->onNewDoc( name );
302 aApp->createEmptyStudy();
303 res = aApp->activeStudy()->createDocument( name );
306 aApp->closeApplication();
309 QApplication::restoreOverrideCursor();
314 /*!Put file name from file dialog to onOpenDoc(const QString&) function*/
315 void STD_Application::onOpenDoc()
317 // It is preferrable to use OS-specific file dialog box here !!!
318 QString aName = getFileName( true, QString(), getFileFilter( true ), QString(), 0 );
319 if ( aName.isNull() )
325 /*! \retval \c true, if document was opened successful, else \c false.*/
326 bool STD_Application::onOpenDoc( const QString& aName )
328 if ( !abortAllOperations() )
331 QApplication::setOverrideCursor( Qt::WaitCursor );
333 bool res = openAction( openChoice( aName ), aName );
335 QApplication::restoreOverrideCursor();
340 /*! Reload document from the file.*/
341 bool STD_Application::onReopenDoc()
345 SUIT_Study* study = activeStudy();
346 if ( study && study->isSaved() ) {
347 // ask user for the confirmation
348 if ( SUIT_MessageBox::question( desktop(), tr( "REOPEN_STUDY" ), tr( "REOPEN_QUESTION" ),
349 SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No
350 ) == SUIT_MessageBox::No )
353 // remember study name
354 QString studyName = study->studyName();
357 beforeCloseDoc( study );
358 study->closeDocument( true );
360 // update views / windows / status bar / title
368 // post closing actions
372 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
373 for ( int i = 0; i < apps.count(); i++ )
374 aNbStudies += apps.at( i )->getNbStudies();
376 // reload study from the file
377 res = useFile( studyName ) && activeStudy();
379 // if reloading is failed, close the desktop
380 if ( aNbStudies && !res )
384 updateDesktopTitle();
385 updateCommandsStatus();
391 /*!Virtual function. Not implemented here.*/
392 void STD_Application::beforeCloseDoc( SUIT_Study* )
396 /*!Virtual function. Not implemented here.*/
397 void STD_Application::afterCloseDoc()
401 /*!Close document, if it's possible.*/
402 void STD_Application::onCloseDoc( bool ask )
407 /*!Close document, if it's possible.*/
408 bool STD_Application::closeDoc( bool ask )
410 bool closePermanently = true;
412 if ( ask && !isPossibleToClose( closePermanently ) )
415 return closeActiveDoc( closePermanently );
419 bool STD_Application::closeActiveDoc( bool permanently )
421 SUIT_Study* study = activeStudy();
422 if ( !study ) // no active study
425 beforeCloseDoc( study );
428 study->closeDocument( permanently );
435 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
436 for ( int i = 0; i < apps.count(); i++ )
437 aNbStudies += apps.at( i )->getNbStudies();
446 updateDesktopTitle();
447 updateCommandsStatus();
450 // IPAL19532: deleting study should be performed after calling setDesktop(0)
460 /*!Check the application on closing.
461 * \retval \c true if possible, else \c false
463 bool STD_Application::isPossibleToClose( bool& closePermanently )
467 activeStudy()->abortAllOperations();
468 if ( activeStudy()->isModified() )
470 QString sName = activeStudy()->studyName().trimmed();
471 return closeAction( closeChoice( sName ), closePermanently );
477 int STD_Application::closeChoice( const QString& docName )
479 int answer = SUIT_MessageBox::question( desktop(), tr( "CLOSE_STUDY" ), tr( "CLOSE_QUESTION" ),
480 SUIT_MessageBox::Save | SUIT_MessageBox::Discard | SUIT_MessageBox::Cancel,
481 SUIT_MessageBox::Save );
483 int res = CloseCancel;
484 if ( answer == SUIT_MessageBox::Save )
486 else if ( answer == SUIT_MessageBox::Discard )
492 bool STD_Application::closeAction( const int choice, bool& closePermanently )
498 if ( activeStudy()->isSaved() )
500 else if ( !onSaveAsDoc() )
513 int STD_Application::openChoice( const QString& aName )
515 SUIT_Session* aSession = SUIT_Session::session();
517 bool isAlreadyOpen = false;
518 QList<SUIT_Application*> aAppList = aSession->applications();
519 for ( QList<SUIT_Application*>::iterator it = aAppList.begin(); it != aAppList.end() && !isAlreadyOpen; ++it )
520 isAlreadyOpen = (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName;
521 return isAlreadyOpen ? OpenExist : OpenNew;
524 bool STD_Application::openAction( const int choice, const QString& aName )
531 SUIT_Application* aApp = 0;
532 SUIT_Session* aSession = SUIT_Session::session();
533 QList<SUIT_Application*> aAppList = aSession->applications();
534 for ( QList<SUIT_Application*>::iterator it = aAppList.begin(); it != aAppList.end() && !aApp; ++it )
536 if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName )
540 aApp->desktop()->activateWindow();
546 if ( !activeStudy() )
547 res = useFile( aName );
550 SUIT_Application* aApp = startApplication( 0, 0 );
552 res = aApp->useFile( aName );
554 aApp->closeApplication();
565 /*!Save document if all ok, else error message.*/
566 void STD_Application::onSaveDoc()
568 if ( !activeStudy() )
571 if ( !abortAllOperations() )
575 if ( activeStudy()->isSaved() )
577 putInfo( tr( "INF_DOC_SAVING" ) + activeStudy()->studyName() );
579 QApplication::setOverrideCursor( Qt::WaitCursor );
581 isOk = activeStudy()->saveDocument();
583 QApplication::restoreOverrideCursor();
588 // displaying a message box as SUIT_Validator in case file can't be written (the most frequent case)
589 SUIT_MessageBox::critical( desktop(), tr( "ERR_ERROR" ),
590 tr( "INF_DOC_SAVING_FAILS" ).arg( activeStudy()->studyName() ) );
593 putInfo( tr( "INF_DOC_SAVED" ).arg( "" ) );
597 studySaved( activeStudy() );
602 /*! \retval \c true, if document saved successfully, else \c false.*/
603 bool STD_Application::onSaveAsDoc()
605 SUIT_Study* study = activeStudy();
609 if ( !abortAllOperations() )
615 QString aName = getFileName( false, study->studyName(), getFileFilter( false ), QString(), 0 );
616 if ( aName.isNull() )
619 QApplication::setOverrideCursor( Qt::WaitCursor );
621 putInfo( tr( "INF_DOC_SAVING" ) + aName );
622 isOk = study->saveDocumentAs( aName );
624 putInfo( isOk ? tr( "INF_DOC_SAVED" ).arg( aName ) : "" );
626 QApplication::restoreOverrideCursor();
629 SUIT_MessageBox::critical( desktop(), tr( "ERROR" ), tr( "INF_DOC_SAVING_FAILS" ).arg( aName ) );
632 studySaved( activeStudy() );
637 /*!Closing session.*/
638 void STD_Application::onExit()
640 int aAnswer = SUIT_MessageBox::Ok;
641 if ( exitConfirmation() )
642 aAnswer = SUIT_MessageBox::question( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ),
643 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel, SUIT_MessageBox::Cancel );
644 if ( aAnswer == SUIT_MessageBox::Ok )
645 SUIT_Session::session()->closeSession();
648 /*!Virtual slot. Not implemented here.*/
649 void STD_Application::onCopy()
653 /*!Virtual slot. Not implemented here.*/
654 void STD_Application::onPaste()
658 /*!Sets \a theEnable for menu manager and for tool manager.*/
659 void STD_Application::setEditEnabled( bool theEnable )
661 myEditEnabled = theEnable;
663 QtxActionMenuMgr* mMgr = desktop()->menuMgr();
664 QtxActionToolMgr* tMgr = desktop()->toolMgr();
666 for ( int i = EditCopyId; i <= EditPasteId; i++ )
668 mMgr->setShown( mMgr->actionId(action(i)), myEditEnabled );
669 tMgr->setShown( tMgr->actionId(action(i)), myEditEnabled );
673 /*!\retval \c true, if document opened successfully, else \c false.*/
674 bool STD_Application::useFile(const QString& theFileName)
676 bool res = SUIT_Application::useFile( theFileName );
679 studyOpened( activeStudy() );
684 /*!Update desktop title.*/
685 void STD_Application::updateDesktopTitle()
687 QString aTitle = applicationName();
688 QString aVer = applicationVersion();
689 if ( !aVer.isEmpty() )
690 aTitle += QString( " " ) + aVer;
694 QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false );
695 if ( !sName.isEmpty() )
696 aTitle += QString( " - [%1]" ).arg( sName );
699 desktop()->setWindowTitle( aTitle );
702 /*!Update commands status.*/
703 void STD_Application::updateCommandsStatus()
705 SUIT_Application::updateCommandsStatus();
707 bool aHasStudy = activeStudy() != 0;
708 bool aSaved = aHasStudy && activeStudy()->isSaved();
709 bool aModified = aHasStudy && activeStudy()->isModified();
710 bool aIsNeedToSave = aHasStudy && ( !aSaved || aModified );
712 if ( action( FileReopenId ) )
713 action( FileReopenId )->setEnabled( aSaved );
714 if ( action( FileSaveId ) )
715 action( FileSaveId )->setEnabled( aIsNeedToSave );
716 if ( action( FileSaveAsId ) )
717 action( FileSaveAsId )->setEnabled( aHasStudy );
718 if ( action( FileCloseId ) )
719 action( FileCloseId )->setEnabled( aHasStudy );
720 if ( action( NewWindowId ) )
721 action( NewWindowId )->setEnabled( aHasStudy );
724 /*!\retval SUIT_ViewManager by viewer manager type name.*/
725 SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const
727 SUIT_ViewManager* vm = 0;
728 for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end() && !vm; ++it )
730 if ( (*it)->getType() == vmType && !(*it)->getDetached())
736 /*! \param vmType - input view manager type name
737 * \param lst - output list of view managers with types \a vmType.
739 void STD_Application::viewManagers( const QString& vmType, ViewManagerList& lst ) const
741 for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end(); ++it )
743 if ( (*it)->getType() == vmType )
748 /*!\param lst - output list of all view managers.*/
749 void STD_Application::viewManagers( ViewManagerList& lst ) const
751 for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end(); ++it )
755 /*!\retval ViewManagerList - const list of all view managers.*/
756 ViewManagerList STD_Application::viewManagers() const
763 /*!\retval SUIT_ViewManager - return pointer to active view manager.*/
764 SUIT_ViewManager* STD_Application::activeViewManager() const
766 return myActiveViewMgr;
769 /*!Add view manager to view managers list, if it not already there.*/
770 void STD_Application::addViewManager( SUIT_ViewManager* vm )
775 if ( !containsViewManager( vm ) )
777 myViewMgrs.append( vm );
778 connect( vm, SIGNAL( activated( SUIT_ViewManager* ) ),
779 this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
780 vm->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
782 emit viewManagerAdded( vm );
785 if ( !activeViewManager() && myViewMgrs.count() == 1 )
786 setActiveViewManager( vm );
790 /*!Remove view manager from view managers list.*/
791 void STD_Application::removeViewManager( SUIT_ViewManager* vm )
798 emit viewManagerRemoved( vm );
800 vm->disconnectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
801 disconnect( vm, SIGNAL( activated( SUIT_ViewManager* ) ),
802 this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
803 myViewMgrs.removeAll( vm );
805 if ( myActiveViewMgr == vm )
809 /*!Remove all view managers from view managers list.*/
810 void STD_Application::clearViewManagers()
815 for ( QList<SUIT_ViewManager*>::iterator it = lst.begin(); it != lst.end(); ++it )
817 QPointer<SUIT_ViewManager> vm = *it;
818 removeViewManager( vm );
823 /*!\retval \c true, if view manager \a vm, already in view manager list (\a myViewMgrs).*/
824 bool STD_Application::containsViewManager( SUIT_ViewManager* vm ) const
826 return myViewMgrs.contains( vm );
829 /*!Private slot, sets active manager to \vm, if \vm in view managers list.*/
830 void STD_Application::onViewManagerActivated( SUIT_ViewManager* vm )
832 setActiveViewManager( vm );
835 /*!Shows status bar, if on is \c true, else hides status bar.*/
836 void STD_Application::onViewStatusBar( bool on )
839 desktop()->statusBar()->show();
841 desktop()->statusBar()->hide();
844 /*!Call SUIT_MessageBox::info1(...) with about information.*/
845 void STD_Application::onHelpAbout()
847 SUIT_MessageBox::information( desktop(), tr( "About" ), tr( "ABOUT_INFO" ) );
850 /*!Create empty study. \n
851 * Create new view manager and adding it to view managers list.
853 void STD_Application::createEmptyStudy()
855 SUIT_Application::createEmptyStudy();
858 /*!Sets active manager to \vm, if \vm in view managers list.*/
859 void STD_Application::setActiveViewManager( SUIT_ViewManager* vm )
861 if ( !containsViewManager( vm ) )
864 myActiveViewMgr = vm;
865 emit viewManagerActivated( vm );
869 void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextMenuEvent* e )
871 QtxMenu* popup = new QtxMenu();
872 // fill popup by own items
874 contextMenuPopup( client->popupClientType(), popup, title );
875 popup->setTitleText( title );
877 popup->addSeparator();
878 // add items from popup client
879 client->contextMenuPopup( popup );
881 SUIT_Tools::simplifySeparators( popup );
883 if ( !popup->actions().isEmpty() )
884 popup->exec( e->globalPos() );
888 /*!\retval QString - return file extension(s).*/
889 QString STD_Application::getFileFilter( bool /*open*/ ) const
894 /*!\retval QString - return file name from dialog.*/
895 QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters,
896 const QString& caption, QWidget* parent )
901 return QFileDialog::getOpenFileName( parent, caption, initial, filters );
906 QString anOldPath = initial;
911 // It is preferrable to use OS-specific file dialog box here !!!
912 aName = QFileDialog::getSaveFileName( parent, caption, anOldPath, filters, &aUsedFilter );
914 if ( aName.isNull() )
918 int aEnd = aUsedFilter.lastIndexOf( ')' );
919 int aStart = aUsedFilter.lastIndexOf( '(', aEnd );
920 QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 );
924 QRegExp rx( "[\b\\*]*\\.([\\w]+)" );
925 while ( ( idx = rx.indexIn( wcStr, idx ) ) != -1 )
927 extList.append( rx.cap( 1 ) );
928 idx += rx.matchedLength();
931 if ( !extList.isEmpty() && !extList.contains( SUIT_Tools::extension( aName ) ) )
932 aName += QString( ".%1" ).arg( extList.first() );
934 if ( QFileInfo( aName ).exists() )
936 int aAnswer = SUIT_MessageBox::question( desktop(), tr( "TIT_FILE_SAVEAS" ),
937 tr( "MSG_FILE_EXISTS" ).arg( aName ),
938 SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel, SUIT_MessageBox::Yes );
939 if ( aAnswer == SUIT_MessageBox::Cancel )
944 else if ( aAnswer == SUIT_MessageBox::No ) // not save to this file
945 anOldPath = aName; // not to return to the same initial dir at each "while" step
946 else // overwrite the existing file
957 /*!\retval QString - return directory name from dialog.*/
958 QString STD_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
963 return QFileDialog::getExistingDirectory( parent, caption, initial );
968 \param desk - new desktop
970 void STD_Application::setDesktop( SUIT_Desktop* desk )
972 SUIT_Application::setDesktop( desk );
975 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
976 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ), Qt::UniqueConnection );
981 Allow to load preferences before the desktop will be shown.
983 void STD_Application::loadPreferences()
988 Allow to save preferences before the application will be closed.
990 void STD_Application::savePreferences()
995 Custom activity after study is created
996 Updates desktop and actions
998 void STD_Application::studyCreated( SUIT_Study* )
1000 updateDesktopTitle();
1001 updateCommandsStatus();
1005 Custom activity after study is opened
1006 Updates desktop and actions
1008 void STD_Application::studyOpened( SUIT_Study* )
1010 updateDesktopTitle();
1011 updateCommandsStatus();
1015 Custom activity after study is opened
1016 Updates desktop and actions
1018 void STD_Application::studySaved( SUIT_Study* )
1020 updateDesktopTitle();
1021 updateCommandsStatus();
1025 Return index of the view ma
1027 int STD_Application::viewManagerId( const SUIT_ViewManager* theManager) const
1029 return myViewMgrs.indexOf(const_cast<SUIT_ViewManager*>(theManager));
1033 \brief Abort active operations if there are any
1034 \return \c false if some operation cannot be aborted
1036 bool STD_Application::abortAllOperations()