1 // Copyright (C) 2007-2022 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()
57 myExitConfirm( true ),
60 setDesktop( new STD_MDIDesktop() );
64 STD_Application::~STD_Application()
69 /*! \retval requirement of exit confirmation*/
70 bool STD_Application::exitConfirmation() const
75 /*! Set the requirement of exit confirmation*/
76 void STD_Application::setExitConfirmation( const bool on )
81 /*! \retval QString "StdApplication"*/
82 QString STD_Application::applicationName() const
84 return QString( "StdApplication" );
87 /*!Start STD_Application*/
88 void STD_Application::start()
94 updateCommandsStatus();
95 setEditEnabled( myEditEnabled );
99 SUIT_Application::start();
103 Close the Application
105 void STD_Application::closeApplication()
109 SUIT_Study* study = activeStudy();
113 beforeCloseDoc( study );
115 study->closeDocument();
125 SUIT_Application::closeApplication();
128 /*!Event on closing desktop*/
129 void STD_Application::onDesktopClosing( SUIT_Desktop*, QCloseEvent* e )
131 if ( SUIT_Session::session()->applications().count() < 2 )
137 bool closePermanently;
138 if ( !isPossibleToClose( closePermanently ) )
147 /*!Create actions, menus and tools*/
148 void STD_Application::createActions()
150 SUIT_Desktop* desk = desktop();
151 SUIT_ResourceMgr* resMgr = resourceMgr();
152 if ( !desk || !resMgr )
157 createAction( FileNewId, tr( "TOT_DESK_FILE_NEW" ),
158 resMgr->loadPixmap( "STD", tr( "ICON_FILE_NEW" ) ),
159 tr( "MEN_DESK_FILE_NEW" ), tr( "PRP_DESK_FILE_NEW" ),
160 Qt::CTRL+Qt::Key_N, desk, false, this, SLOT( onNewDoc() ) );
162 createAction( FileOpenId, tr( "TOT_DESK_FILE_OPEN" ),
163 resMgr->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ),
164 tr( "MEN_DESK_FILE_OPEN" ), tr( "PRP_DESK_FILE_OPEN" ),
165 Qt::CTRL+Qt::Key_O, desk, false, this, SLOT( onOpenDoc() ) );
167 createAction( FileReopenId, tr( "TOT_DESK_FILE_REOPEN" ), QIcon(),
168 tr( "MEN_DESK_FILE_REOPEN" ), tr( "PRP_DESK_FILE_REOPEN" ),
169 0, desk, false, this, SLOT( onReopenDoc() ) );
171 createAction( FileCloseId, tr( "TOT_DESK_FILE_CLOSE" ),
172 resMgr->loadPixmap( "STD", tr( "ICON_FILE_CLOSE" ) ),
173 tr( "MEN_DESK_FILE_CLOSE" ), tr( "PRP_DESK_FILE_CLOSE" ),
174 Qt::CTRL+Qt::Key_W, desk, false, this, SLOT( onCloseDoc() ) );
175 //no need in this action for mono-study application as it is same as NewDoc
176 action( FileCloseId )->setVisible( false );
178 createAction( FileExitId, tr( "TOT_DESK_FILE_EXIT" ), QIcon(),
179 tr( "MEN_DESK_FILE_EXIT" ), tr( "PRP_DESK_FILE_EXIT" ),
180 Qt::CTRL+Qt::Key_Q, desk, false, this, SLOT( onExit() ) );
182 createAction( FileSaveId, tr( "TOT_DESK_FILE_SAVE" ),
183 resMgr->loadPixmap( "STD", tr( "ICON_FILE_SAVE" ) ),
184 tr( "MEN_DESK_FILE_SAVE" ), tr( "PRP_DESK_FILE_SAVE" ),
185 Qt::CTRL+Qt::Key_S, desk, false, this, SLOT( onSaveDoc() ) );
187 createAction( FileSaveAsId, tr( "TOT_DESK_FILE_SAVEAS" ), QIcon(),
188 tr( "MEN_DESK_FILE_SAVEAS" ), tr( "PRP_DESK_FILE_SAVEAS" ),
189 Qt::CTRL+Qt::SHIFT+Qt::Key_S, desk, false, this, SLOT( onSaveAsDoc() ) );
191 createAction( EditCopyId, tr( "TOT_DESK_EDIT_COPY" ),
192 resMgr->loadPixmap( "STD", tr( "ICON_EDIT_COPY" ) ),
193 tr( "MEN_DESK_EDIT_COPY" ), tr( "PRP_DESK_EDIT_COPY" ),
194 Qt::CTRL+Qt::Key_C, desk, false, this, SLOT( onCopy() ) );
196 createAction( EditPasteId, tr( "TOT_DESK_EDIT_PASTE" ),
197 resMgr->loadPixmap( "STD", tr( "ICON_EDIT_PASTE" ) ),
198 tr( "MEN_DESK_EDIT_PASTE" ), tr( "PRP_DESK_EDIT_PASTE" ),
199 Qt::CTRL+Qt::Key_V, desk, false, this, SLOT( onPaste() ) );
201 QAction* a = createAction( ViewStatusBarId, tr( "TOT_DESK_VIEW_STATUSBAR" ),
202 QIcon(), tr( "MEN_DESK_VIEW_STATUSBAR" ),
203 tr( "PRP_DESK_VIEW_STATUSBAR" ), Qt::ALT+Qt::SHIFT+Qt::Key_S, desk, true );
204 a->setChecked( desk->statusBar()->isVisibleTo( desk ) );
205 connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onViewStatusBar( bool ) ) );
207 createAction( NewWindowId, tr( "TOT_DESK_NEWWINDOW" ), QIcon(),
208 tr( "MEN_DESK_NEWWINDOW" ), tr( "PRP_DESK_NEWWINDOW" ), 0, desk );
210 createAction( HelpAboutId, tr( "TOT_DESK_HELP_ABOUT" ),
211 resMgr->loadPixmap( "STD", tr( "ICON_DESK_ABOUT" ) ),
212 tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ),
213 Qt::ALT+Qt::SHIFT+Qt::Key_A, desk, false, this, SLOT( onHelpAbout() ) );
216 QtxDockAction* dwa = new QtxDockAction( tr( "TOT_DOCKWINDOWS" ), tr( "MEN_DESK_VIEW_DOCKWINDOWS" ), desk );
217 dwa->setDockType( QtxDockAction::DockWidget );
218 registerAction( ViewWindowsId, dwa );
220 QtxDockAction* tba = new QtxDockAction( tr( "TOT_TOOLBARS" ), tr( "MEN_DESK_VIEW_TOOLBARS" ), desk );
221 tba->setDockType( QtxDockAction::ToolBar );
222 registerAction( ViewToolBarsId, tba );
226 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, MenuFileId, 0 );
227 // Let the application developers insert some menus between Edit and View
228 int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, MenuEditId, 5 );
229 int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1, MenuViewId, 10 );
230 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, MenuHelpId, 1000 );
234 createMenu( FileNewId, fileMenu, 0 );
235 createMenu( FileOpenId, fileMenu, 0 );
236 createMenu( FileReopenId, fileMenu, 0 );
237 createMenu( FileSaveId, fileMenu, 5 );
238 createMenu( FileSaveAsId, fileMenu, 5 );
239 createMenu( FileCloseId, fileMenu, 5 );
240 createMenu( separator(), fileMenu, -1, 5 );
242 createMenu( separator(), fileMenu );
243 createMenu( FileExitId, fileMenu );
245 createMenu( EditCopyId, editMenu );
246 createMenu( EditPasteId, editMenu );
247 createMenu( separator(), editMenu );
249 createMenu( ViewToolBarsId, viewMenu, 0 );
250 createMenu( ViewWindowsId, viewMenu, 0 );
251 createMenu( separator(), viewMenu, -1, 10 );
252 createMenu( ViewStatusBarId, viewMenu, 10 );
253 createMenu( separator(), viewMenu );
255 createMenu( HelpAboutId, helpMenu );
256 createMenu( separator(), helpMenu );
260 int stdTBar = createTool( tr( "INF_DESK_TOOLBAR_STANDARD" ), // title (language-dependant)
261 QString( "SalomeStandard" ) ); // name (language-independant)
265 createTool( FileNewId, stdTBar );
266 createTool( FileOpenId, stdTBar );
267 createTool( FileSaveId, stdTBar );
268 createTool( FileCloseId, stdTBar );
269 createTool( separator(), stdTBar );
270 createTool( EditCopyId, stdTBar );
271 createTool( EditPasteId, stdTBar );
277 void STD_Application::customize()
281 /*!Opens new application*/
282 void STD_Application::onNewDoc()
284 onNewDoc( QString() );
287 /*!Opens new application*/
288 bool STD_Application::onNewDoc( const QString& name )
290 QApplication::setOverrideCursor( Qt::WaitCursor );
293 if ( !activeStudy() )
296 res = activeStudy()->createDocument( name );
298 studyCreated( activeStudy() );
301 SUIT_Study* st = activeStudy();
308 SUIT_Application* aApp = startApplication( 0, 0 );
309 if ( aApp->inherits( "STD_Application" ) )
310 res = ((STD_Application*)aApp)->onNewDoc( name );
313 aApp->createEmptyStudy();
314 res = aApp->activeStudy()->createDocument( name );
317 aApp->closeApplication();
320 QApplication::restoreOverrideCursor();
325 /*!Put file name from file dialog to onOpenDoc(const QString&) function*/
326 void STD_Application::onOpenDoc()
328 // It is preferrable to use OS-specific file dialog box here !!!
329 QString aName = getFileName( true, QString(), getFileFilter( true ), QString(), 0 );
330 if ( aName.isNull() )
336 /*! \retval \c true, if document was opened successful, else \c false.*/
337 bool STD_Application::onOpenDoc( const QString& aName )
339 if ( !abortAllOperations() )
342 QApplication::setOverrideCursor( Qt::WaitCursor );
344 bool res = openAction( openChoice( aName ), aName );
346 QApplication::restoreOverrideCursor();
351 /*! Reload document from the file.*/
352 bool STD_Application::onReopenDoc()
356 SUIT_Study* study = activeStudy();
357 if ( study && study->isSaved() ) {
358 // ask user for the confirmation
359 if ( SUIT_MessageBox::question( desktop(), tr( "REOPEN_STUDY" ), tr( "REOPEN_QUESTION" ),
360 SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No
361 ) == SUIT_MessageBox::No )
364 // remember study name
365 QString studyName = study->studyName();
368 beforeCloseDoc( study );
369 study->closeDocument( true );
371 // update views / windows / status bar / title
379 // post closing actions
382 // reload study from the file
383 res = useFile( studyName ) && activeStudy();
385 // if reloading is failed, close the desktop
386 if ( activeStudy() && !res )
390 updateDesktopTitle();
391 updateCommandsStatus();
397 /*!Virtual function. Not implemented here.*/
398 void STD_Application::beforeCloseDoc( SUIT_Study* )
402 /*!Virtual function. Not implemented here.*/
403 void STD_Application::afterCloseDoc()
407 /*!Close document, if it's possible.*/
408 void STD_Application::onCloseDoc( bool ask )
413 /*!Close document, if it's possible.*/
414 bool STD_Application::closeDoc( bool ask )
416 bool closePermanently = true;
418 if ( ask && !isPossibleToClose( closePermanently ) )
421 return closeActiveDoc( closePermanently );
425 bool STD_Application::closeActiveDoc( bool permanently )
427 SUIT_Study* study = activeStudy();
428 if ( !study ) // no active study
431 beforeCloseDoc( study );
434 study->closeDocument( permanently );
441 QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
442 for ( int i = 0; i < apps.count(); i++ )
443 aNbStudies += apps.at( i )->getNbStudies();
452 updateDesktopTitle();
453 updateCommandsStatus();
456 // IPAL19532: deleting study should be performed after calling setDesktop(0)
466 /*!Check the application on closing.
467 * \retval \c true if possible, else \c false
469 bool STD_Application::isPossibleToClose( bool& closePermanently )
473 activeStudy()->abortAllOperations();
474 if ( activeStudy()->isModified() )
476 QString sName = activeStudy()->studyName().trimmed();
477 return closeAction( closeChoice( sName ), closePermanently );
483 int STD_Application::closeChoice( const QString& /*docName*/ )
485 int answer = SUIT_MessageBox::question( desktop(), tr( "CLOSE_STUDY" ), tr( "CLOSE_QUESTION" ),
486 SUIT_MessageBox::Save | SUIT_MessageBox::Discard | SUIT_MessageBox::Cancel,
487 SUIT_MessageBox::Save );
489 int res = CloseCancel;
490 if ( answer == SUIT_MessageBox::Save )
492 else if ( answer == SUIT_MessageBox::Discard )
498 bool STD_Application::closeAction( const int choice, bool& /*closePermanently*/ )
504 if ( activeStudy()->isSaved() )
506 else if ( !onSaveAsDoc() )
519 int STD_Application::openChoice( const QString& aName )
521 SUIT_Session* aSession = SUIT_Session::session();
523 bool isAlreadyOpen = false;
524 QList<SUIT_Application*> aAppList = aSession->applications();
525 for ( QList<SUIT_Application*>::iterator it = aAppList.begin(); it != aAppList.end() && !isAlreadyOpen; ++it )
526 isAlreadyOpen = (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName;
527 return isAlreadyOpen ? OpenExist : OpenNew;
530 bool STD_Application::openAction( const int choice, const QString& aName )
537 SUIT_Application* aApp = 0;
538 SUIT_Session* aSession = SUIT_Session::session();
539 QList<SUIT_Application*> aAppList = aSession->applications();
540 for ( QList<SUIT_Application*>::iterator it = aAppList.begin(); it != aAppList.end() && !aApp; ++it )
542 if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName )
546 aApp->desktop()->activateWindow();
552 if ( !activeStudy() )
553 res = useFile( aName );
556 SUIT_Application* aApp = startApplication( 0, 0 );
558 res = aApp->useFile( aName );
560 aApp->closeApplication();
571 /*!Save document if all ok, else error message.*/
572 bool STD_Application::onSaveDoc()
574 if ( !activeStudy() )
577 if ( !abortAllOperations() )
581 if ( activeStudy()->isSaved() )
583 putInfo( tr( "INF_DOC_SAVING" ) + activeStudy()->studyName() );
585 QApplication::setOverrideCursor( Qt::WaitCursor );
587 isOk = activeStudy()->saveDocument();
589 QApplication::restoreOverrideCursor();
594 // displaying a message box as SUIT_Validator in case file can't be written (the most frequent case)
595 SUIT_MessageBox::critical( desktop(), tr( "ERR_ERROR" ),
596 tr( "INF_DOC_SAVING_FAILS" ).arg( activeStudy()->studyName() ) );
599 putInfo( tr( "INF_DOC_SAVED" ).arg( "" ) );
603 studySaved( activeStudy() );
605 isOk = onSaveAsDoc();
609 /*! \retval \c true, if document saved successfully, else \c false.*/
610 bool STD_Application::onSaveAsDoc()
612 SUIT_Study* study = activeStudy();
616 if ( !abortAllOperations() )
622 QString aName = getFileName( false, study->studyName(), getFileFilter( false ), QString(), 0 );
623 if ( aName.isNull() )
626 QApplication::setOverrideCursor( Qt::WaitCursor );
628 putInfo( tr( "INF_DOC_SAVING" ) + aName );
629 isOk = study->saveDocumentAs( aName );
631 putInfo( isOk ? tr( "INF_DOC_SAVED" ).arg( aName ) : "" );
633 QApplication::restoreOverrideCursor();
636 SUIT_MessageBox::critical( desktop(), tr( "ERROR" ), tr( "INF_DOC_SAVING_FAILS" ).arg( aName ) );
639 studySaved( activeStudy() );
644 /*!Closing session.*/
645 void STD_Application::onExit()
647 int aAnswer = SUIT_MessageBox::Ok;
648 if ( exitConfirmation() )
649 aAnswer = SUIT_MessageBox::question( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ),
650 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel, SUIT_MessageBox::Cancel );
651 if ( aAnswer == SUIT_MessageBox::Ok )
652 SUIT_Session::session()->closeSession();
655 /*!Virtual slot. Not implemented here.*/
656 void STD_Application::onCopy()
660 /*!Virtual slot. Not implemented here.*/
661 void STD_Application::onPaste()
665 /*!Sets \a theEnable for menu manager and for tool manager.*/
666 void STD_Application::setEditEnabled( bool theEnable )
668 myEditEnabled = theEnable;
670 QtxActionMenuMgr* mMgr = desktop()->menuMgr();
671 QtxActionToolMgr* tMgr = desktop()->toolMgr();
673 for ( int i = EditCopyId; i <= EditPasteId; i++ )
675 mMgr->setShown( mMgr->actionId(action(i)), myEditEnabled );
676 tMgr->setShown( tMgr->actionId(action(i)), myEditEnabled );
680 /*!\retval \c true, if document opened successfully, else \c false.*/
681 bool STD_Application::useFile(const QString& theFileName)
683 bool res = SUIT_Application::useFile( theFileName );
686 studyOpened( activeStudy() );
691 /*!Update desktop title.*/
692 void STD_Application::updateDesktopTitle()
694 QString aTitle = applicationName();
695 QString aVer = applicationVersion();
696 if ( !aVer.isEmpty() )
697 aTitle += QString( " " ) + aVer;
701 QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false );
702 if ( !sName.isEmpty() )
703 aTitle += QString( " - [%1]" ).arg( sName );
706 desktop()->setWindowTitle( aTitle );
709 /*!Update commands status.*/
710 void STD_Application::updateCommandsStatus()
712 SUIT_Application::updateCommandsStatus();
714 bool aHasStudy = activeStudy() != 0;
715 bool aSaved = aHasStudy && activeStudy()->isSaved();
716 bool aModified = aHasStudy && activeStudy()->isModified();
717 bool aIsNeedToSave = aHasStudy && ( !aSaved || aModified );
719 if ( action( FileReopenId ) )
720 action( FileReopenId )->setEnabled( aSaved );
721 if ( action( FileSaveId ) )
722 action( FileSaveId )->setEnabled( aIsNeedToSave );
723 if ( action( FileSaveAsId ) )
724 action( FileSaveAsId )->setEnabled( aHasStudy );
725 if ( action( FileCloseId ) )
726 action( FileCloseId )->setEnabled( aHasStudy );
727 if ( action( NewWindowId ) )
728 action( NewWindowId )->setEnabled( aHasStudy );
732 \brief Show notification with specified text and title.
734 Notification will be automatically hidden after specified \a timeout
735 (given in milliseconds). If \a timeout is zero, the notification
736 is not automatically hidden; it can be only closed by the user manually.
738 \param text - Notification text
739 \param title - Notification title
740 \param timeout - Timeout in milliseconds
741 \return Notification's unique identifier
743 int STD_Application::showNotification(const QString& message, const QString& title, int timeout)
746 QtxNotify* ntfMgr = notifyMgr();
752 SUIT_ResourceMgr* aResMgr = resourceMgr();
754 delay = aResMgr->integerValue("notification", "timeout", 0) * 1000;
756 uid = ntfMgr->showNotification(message, title, qMax(delay, 0));
762 \brief Close notifications with specified text.
763 \param text - Notification text
765 void STD_Application::hideNotification(const QString& message)
767 QtxNotify* ntfMgr = notifyMgr();
769 ntfMgr->hideNotification(message);
773 \brief Closes the notifications with specified identifier.
774 \param id - Notification identifier
776 void STD_Application::hideNotification(int id)
778 QtxNotify* ntfMgr = notifyMgr();
780 ntfMgr->hideNotification(id);
783 /*!\retval SUIT_ViewManager by viewer manager type name.*/
784 SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const
786 SUIT_ViewManager* vm = 0;
787 for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end() && !vm; ++it )
789 bool keepDetached = property("keep_detached").toBool();
790 if ( (*it)->getType() == vmType && (!(*it)->getDetached() || keepDetached))
796 /*! \param vmType - input view manager type name
797 * \param lst - output list of view managers with types \a vmType.
799 void STD_Application::viewManagers( const QString& vmType, ViewManagerList& lst ) const
801 for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end(); ++it )
803 if ( (*it)->getType() == vmType )
808 /*!\param lst - output list of all view managers.*/
809 void STD_Application::viewManagers( ViewManagerList& lst ) const
811 for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end(); ++it )
815 /*!\retval ViewManagerList - const list of all view managers.*/
816 ViewManagerList STD_Application::viewManagers() const
823 /*!\retval SUIT_ViewManager - return pointer to active view manager.*/
824 SUIT_ViewManager* STD_Application::activeViewManager() const
826 return myActiveViewMgr;
829 /*!Add view manager to view managers list, if it not already there.*/
830 void STD_Application::addViewManager( SUIT_ViewManager* vm )
835 if ( !containsViewManager( vm ) )
837 myViewMgrs.append( vm );
838 connect( vm, SIGNAL( activated( SUIT_ViewManager* ) ),
839 this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
840 vm->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
842 emit viewManagerAdded( vm );
845 if ( !activeViewManager() && myViewMgrs.count() == 1 )
846 setActiveViewManager( vm );
850 /*!Remove view manager from view managers list.*/
851 void STD_Application::removeViewManager( SUIT_ViewManager* vm )
858 emit viewManagerRemoved( vm );
860 vm->disconnectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
861 disconnect( vm, SIGNAL( activated( SUIT_ViewManager* ) ),
862 this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
863 myViewMgrs.removeAll( vm );
865 if ( myActiveViewMgr == vm )
869 /*!Remove all view managers from view managers list.*/
870 void STD_Application::clearViewManagers()
875 for ( QList<SUIT_ViewManager*>::iterator it = lst.begin(); it != lst.end(); ++it )
877 QPointer<SUIT_ViewManager> vm = *it;
878 removeViewManager( vm );
883 /*!\retval \c true, if view manager \a vm, already in view manager list (\a myViewMgrs).*/
884 bool STD_Application::containsViewManager( SUIT_ViewManager* vm ) const
886 return myViewMgrs.contains( vm );
889 /*!Private slot, sets active manager to \vm, if \vm in view managers list.*/
890 void STD_Application::onViewManagerActivated( SUIT_ViewManager* vm )
892 setActiveViewManager( vm );
895 /*!Shows status bar, if on is \c true, else hides status bar.*/
896 void STD_Application::onViewStatusBar( bool on )
899 desktop()->statusBar()->show();
901 desktop()->statusBar()->hide();
904 /*!Call SUIT_MessageBox::info1(...) with about information.*/
905 void STD_Application::onHelpAbout()
907 SUIT_MessageBox::information( desktop(), tr( "About" ), tr( "ABOUT_INFO" ) );
910 /*!Create empty study. \n
911 * Create new view manager and adding it to view managers list.
913 void STD_Application::createEmptyStudy()
915 SUIT_Application::createEmptyStudy();
918 /*!Sets active manager to \vm, if \vm in view managers list.*/
919 void STD_Application::setActiveViewManager( SUIT_ViewManager* vm )
921 if ( !containsViewManager( vm ) )
924 myActiveViewMgr = vm;
925 emit viewManagerActivated( vm );
929 void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextMenuEvent* e )
931 QtxMenu* popup = new QtxMenu();
932 // fill popup by own items
934 contextMenuPopup( client->popupClientType(), popup, title );
935 popup->setTitleText( title );
937 popup->addSeparator();
938 // add items from popup client
939 client->contextMenuPopup( popup );
941 SUIT_Tools::simplifySeparators( popup );
943 if ( !popup->actions().isEmpty() )
944 popup->exec( e->globalPos() );
948 /*!\retval QString - return file extension(s).*/
949 QString STD_Application::getFileFilter( bool /*open*/ ) const
954 /*!\retval QString - return file name from dialog.*/
955 QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters,
956 const QString& caption, QWidget* parent )
961 return QFileDialog::getOpenFileName( parent, caption, initial, filters );
966 QString anOldPath = initial;
971 // It is preferrable to use OS-specific file dialog box here !!!
972 aName = QFileDialog::getSaveFileName( parent, caption, anOldPath, filters, &aUsedFilter );
974 if ( aName.isNull() )
978 int aEnd = aUsedFilter.lastIndexOf( ')' );
979 int aStart = aUsedFilter.lastIndexOf( '(', aEnd );
980 QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 );
984 QRegExp rx( "[\b\\*]*\\.([\\w]+)" );
985 while ( ( idx = rx.indexIn( wcStr, idx ) ) != -1 )
987 extList.append( rx.cap( 1 ) );
988 idx += rx.matchedLength();
991 if ( !extList.isEmpty() && !extList.contains( SUIT_Tools::extension( aName ) ) )
992 aName += QString( ".%1" ).arg( extList.first() );
994 if ( QFileInfo( aName ).exists() )
996 int aAnswer = SUIT_MessageBox::question( desktop(), tr( "TIT_FILE_SAVEAS" ),
997 tr( "MSG_FILE_EXISTS" ).arg( aName ),
998 SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel, SUIT_MessageBox::Yes );
999 if ( aAnswer == SUIT_MessageBox::Cancel )
1004 else if ( aAnswer == SUIT_MessageBox::No ) // not save to this file
1005 anOldPath = aName; // not to return to the same initial dir at each "while" step
1006 else // overwrite the existing file
1017 /*!\retval QString - return directory name from dialog.*/
1018 QString STD_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1023 return QFileDialog::getExistingDirectory( parent, caption, initial );
1028 \param desk - new desktop
1030 void STD_Application::setDesktop( SUIT_Desktop* desk )
1032 SUIT_Application::setDesktop( desk );
1035 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
1036 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ), Qt::UniqueConnection );
1041 Allow to load preferences before the desktop will be shown.
1043 void STD_Application::loadPreferences()
1048 Allow to save preferences before the application will be closed.
1050 void STD_Application::savePreferences()
1055 Custom activity after study is created
1056 Updates desktop and actions
1058 void STD_Application::studyCreated( SUIT_Study* )
1060 updateDesktopTitle();
1061 updateCommandsStatus();
1065 Custom activity after study is opened
1066 Updates desktop and actions
1068 void STD_Application::studyOpened( SUIT_Study* )
1070 updateDesktopTitle();
1071 updateCommandsStatus();
1075 Custom activity after study is opened
1076 Updates desktop and actions
1078 void STD_Application::studySaved( SUIT_Study* )
1080 updateDesktopTitle();
1081 updateCommandsStatus();
1085 Return index of the view ma
1087 int STD_Application::viewManagerId( const SUIT_ViewManager* theManager) const
1089 return myViewMgrs.indexOf(const_cast<SUIT_ViewManager*>(theManager));
1093 \brief Abort active operations if there are any
1094 \return \c false if some operation cannot be aborted
1096 bool STD_Application::abortAllOperations()
1102 \brief Gets the notification manager. Creates it if not exists.
1103 \return \c notification manager instance
1105 QtxNotify* STD_Application::notifyMgr()
1109 myNotify = new QtxNotify(desktop());
1110 myNotify->setWindow(desktop());
1112 SUIT_ResourceMgr* aResMgr = resourceMgr();
1115 int anim = aResMgr->integerValue("notification", "animation", 0);
1116 myNotify->setAnimationTime(anim);
1118 double size = aResMgr->integerValue("notification", "size", 250);
1119 myNotify->setNotificationSize(size);