X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSTD%2FSTD_Application.cxx;h=681e7bc070ae5a3070e9887f4eea7027479e41da;hb=1e121ed2fda87a3fbf0c4a9b9ff04983bbf8f8da;hp=0c5aa43968e6c255a154bf706bbc53b5d8542c37;hpb=7e4548707fb159c877d7c15a909fd4d14667ff82;p=modules%2Fgui.git diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 0c5aa4396..681e7bc07 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -2,6 +2,8 @@ #include "STD_MDIDesktop.h" +#include "STD_CloseDlg.h" + #include #include #include @@ -22,11 +24,15 @@ #include #include +#include + +/*!Create and return new instance of STD_Application*/ extern "C" STD_EXPORT SUIT_Application* createApplication() { return new STD_Application(); } +/*!Constructor.*/ STD_Application::STD_Application() : SUIT_Application(), myEditEnabled( true ), @@ -40,15 +46,18 @@ myActiveViewMgr( 0 ) setDesktop( desk ); } +/*!Destructor.*/ STD_Application::~STD_Application() { } +/*! \retval QString "StdApplication"*/ QString STD_Application::applicationName() const { return QString( "StdApplication" ); } +/*!Start STD_Application*/ void STD_Application::start() { createActions(); @@ -60,6 +69,7 @@ void STD_Application::start() SUIT_Application::start(); } +/*!Event on closing desktop*/ void STD_Application::onDesktopClosing( SUIT_Desktop*, QCloseEvent* e ) { if ( !isPossibleToClose() ) @@ -81,6 +91,7 @@ void STD_Application::onDesktopClosing( SUIT_Desktop*, QCloseEvent* e ) closeApplication(); } +/*!Create actions, menus and tools*/ void STD_Application::createActions() { SUIT_Desktop* desk = desktop(); @@ -118,11 +129,6 @@ void STD_Application::createActions() tr( "MEN_DESK_FILE_SAVEAS" ), tr( "PRP_DESK_FILE_SAVEAS" ), 0, desk, false, this, SLOT( onSaveAsDoc() ) ); - createAction( EditCutId, tr( "TOT_DESK_EDIT_CUT" ), - resMgr->loadPixmap( "STD", tr( "ICON_EDIT_CUT" ) ), - tr( "MEN_DESK_EDIT_CUT" ), tr( "PRP_DESK_EDIT_CUT" ), - CTRL+Key_X, desk, false, this, SLOT( onCut() ) ); - createAction( EditCopyId, tr( "TOT_DESK_EDIT_COPY" ), resMgr->loadPixmap( "STD", tr( "ICON_EDIT_COPY" ) ), tr( "MEN_DESK_EDIT_COPY" ), tr( "PRP_DESK_EDIT_COPY" ), @@ -146,6 +152,13 @@ void STD_Application::createActions() tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ), 0, desk, false, this, SLOT( onHelpAbout() ) ); + //SRN: BugID IPAL9021, add an action "Load" + createAction( FileLoadId, tr( "TOT_DESK_FILE_LOAD" ), + resMgr->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ), + tr( "MEN_DESK_FILE_LOAD" ), tr( "PRP_DESK_FILE_LOAD" ), + CTRL+Key_L, desk, false, this, SLOT( onLoadDoc() ) ); + //SRN: BugID IPAL9021: End + QtxDockAction* da = new QtxDockAction( tr( "TOT_DOCK_WINDOWS" ), tr( "MEN_DOCK_WINDOWS" ), desk ); registerAction( ViewWindowsId, da ); da->setAutoPlace( false ); @@ -161,6 +174,7 @@ void STD_Application::createActions() createMenu( FileNewId, fileMenu, 0 ); createMenu( FileOpenId, fileMenu, 0 ); + createMenu( FileLoadId, fileMenu, 0 ); //SRN: BugID IPAL9021, add a menu item "Load" createMenu( FileCloseId, fileMenu, 0 ); createMenu( separator(), fileMenu, -1, 0 ); createMenu( FileSaveId, fileMenu, 0 ); @@ -170,7 +184,6 @@ void STD_Application::createActions() createMenu( separator(), fileMenu ); createMenu( FileExitId, fileMenu ); - createMenu( EditCutId, editMenu ); createMenu( EditCopyId, editMenu ); createMenu( EditPasteId, editMenu ); createMenu( separator(), editMenu ); @@ -193,14 +206,11 @@ void STD_Application::createActions() createTool( FileSaveId, stdTBar ); createTool( FileCloseId, stdTBar ); createTool( separator(), stdTBar ); - createTool( EditCutId, stdTBar ); createTool( EditCopyId, stdTBar ); createTool( EditPasteId, stdTBar ); } -/*! - Opens new application -*/ +/*!Opens new application*/ void STD_Application::onNewDoc() { if ( !activeStudy() ) @@ -222,6 +232,7 @@ void STD_Application::onNewDoc() } } +/*!Put file name from file dialog to onOpenDoc(const QString&) function*/ void STD_Application::onOpenDoc() { // It is preferrable to use OS-specific file dialog box here !!! @@ -232,16 +243,14 @@ void STD_Application::onOpenDoc() onOpenDoc( aName ); } +/*! \retval true, if document was opened successful, else false.*/ bool STD_Application::onOpenDoc( const QString& aName ) { bool res = true; if ( !activeStudy() ) { // if no study - open in current desktop - createEmptyStudy(); - res = activeStudy()->openDocument( aName ); - updateDesktopTitle(); - updateCommandsStatus(); + res = useFile( aName ); } else { @@ -268,14 +277,56 @@ bool STD_Application::onOpenDoc( const QString& aName ) return res; } +/*! called on loading the existent study */ +void STD_Application::onLoadDoc() +{ +} + +/*! \retval true, if document was loaded successful, else false.*/ +bool STD_Application::onLoadDoc( const QString& aName ) +{ + bool res = true; + if ( !activeStudy() ) + { + // if no study - load in current desktop + res = useStudy( aName ); + } + else + { + // if study exists - load in new desktop. Check: is the same file is loaded? + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList aAppList = aSession->applications(); + bool isAlreadyOpen = false; + SUIT_Application* aApp = 0; + for ( QPtrListIterator it( aAppList ); it.current() && !isAlreadyOpen; ++it ) + { + aApp = it.current(); + if ( aApp->activeStudy()->studyName() == aName ) + isAlreadyOpen = true; + } + if ( !isAlreadyOpen ) + { + aApp = startApplication( 0, 0 ); + if ( aApp ) + res = aApp->useStudy( aName ); + } + else + aApp->desktop()->setActiveWindow(); + } + return res; +} + +/*!Virtual function. Not implemented here.*/ void STD_Application::beforeCloseDoc( SUIT_Study* ) { } +/*!Virtual function. Not implemented here.*/ void STD_Application::afterCloseDoc() { } +/*!Close document, if it's possible.*/ void STD_Application::onCloseDoc() { if ( !isPossibleToClose() ) @@ -286,7 +337,7 @@ void STD_Application::onCloseDoc() beforeCloseDoc( study ); if ( study ) - study->closeDocument(); + study->closeDocument(myClosePermanently); clearViewManagers(); @@ -314,8 +365,12 @@ void STD_Application::onCloseDoc() closeApplication(); } +/*!Check the application on closing. + * \retval true if possible, else false + */ bool STD_Application::isPossibleToClose() { + myClosePermanently = true; //SRN: BugID: IPAL9021 if ( activeStudy() ) { activeStudy()->abortAllOperations(); @@ -323,28 +378,33 @@ bool STD_Application::isPossibleToClose() { QString sName = activeStudy()->studyName().stripWhiteSpace(); QString msg = sName.isEmpty() ? tr( "INF_DOC_MODIFIED" ) : tr ( "INF_DOCUMENT_MODIFIED" ).arg( sName ); - int aAnswer = SUIT_MessageBox::warn3( desktop(), tr( "TOT_DESK_FILE_CLOSE" ), msg, - tr( "BUT_YES" ), tr( "BUT_NO" ), tr( "BUT_CANCEL" ), 1, 2, 3, 1 ); - switch ( aAnswer ) + + //SRN: BugID: IPAL9021: Begin + STD_CloseDlg dlg(desktop()); + switch( dlg.exec() ) { case 1: - if ( !activeStudy()->isSaved() ) - if ( !onSaveAsDoc() ) - return false; - else + if ( activeStudy()->isSaved() ) onSaveDoc(); + else if ( !onSaveAsDoc() ) + return false; break; case 2: break; case 3: + myClosePermanently = false; + break; + case 4: default: return false; } + //SRN: BugID: IPAL9021: End } } return true; } +/*!Save document if all ok, else error message.*/ void STD_Application::onSaveDoc() { if ( !activeStudy() ) @@ -365,6 +425,7 @@ void STD_Application::onSaveDoc() onSaveAsDoc(); } +/*! \retval TRUE, if doument saved successful, else FALSE.*/ bool STD_Application::onSaveAsDoc() { SUIT_Study* study = activeStudy(); @@ -383,23 +444,23 @@ bool STD_Application::onSaveAsDoc() return isOk; } +/*!Closing session.*/ void STD_Application::onExit() { SUIT_Session::session()->closeSession(); } -void STD_Application::onCut() -{ -} - +/*!Virtual slot. Not implemented here.*/ void STD_Application::onCopy() { } +/*!Virtual slot. Not implemented here.*/ void STD_Application::onPaste() { } +/*!Sets \a theEnable for menu manager and for tool manager.*/ void STD_Application::setEditEnabled( bool theEnable ) { myEditEnabled = theEnable; @@ -407,13 +468,14 @@ void STD_Application::setEditEnabled( bool theEnable ) QtxActionMenuMgr* mMgr = desktop()->menuMgr(); QtxActionToolMgr* tMgr = desktop()->toolMgr(); - for ( int i = EditCutId; i <= EditPasteId; i++ ) + for ( int i = EditCopyId; i <= EditPasteId; i++ ) { mMgr->setShown( i, myEditEnabled ); tMgr->setShown( i, myEditEnabled ); } } +/*!\retval true, if document opened successful, else false.*/ bool STD_Application::useFile(const QString& theFileName) { bool res = SUIT_Application::useFile(theFileName); @@ -422,6 +484,7 @@ bool STD_Application::useFile(const QString& theFileName) return res; } +/*!Update desktop title.*/ void STD_Application::updateDesktopTitle() { QString aTitle = applicationName(); @@ -439,6 +502,7 @@ void STD_Application::updateDesktopTitle() desktop()->setCaption( aTitle ); } +/*!Update commands status.*/ void STD_Application::updateCommandsStatus() { bool aHasStudy = activeStudy() != 0; @@ -456,6 +520,7 @@ void STD_Application::updateCommandsStatus() action( NewWindowId )->setEnabled( aHasStudy ); } +/*!\retval SUIT_ViewManager by viewer manager type name.*/ SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const { SUIT_ViewManager* vm = 0; @@ -467,6 +532,9 @@ SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const return vm; } +/*! \param vmType - input view manager type name + * \param lst - output list of view managers with types \a vmType. + */ void STD_Application::viewManagers( const QString& vmType, ViewManagerList& lst ) const { for ( QPtrListIterator it( myViewMgrs ); it.current(); ++it ) @@ -474,12 +542,14 @@ void STD_Application::viewManagers( const QString& vmType, ViewManagerList& lst lst.append( it.current() ); } +/*!\param lst - output list of all view managers.*/ void STD_Application::viewManagers( ViewManagerList& lst ) const { for ( QPtrListIterator it( myViewMgrs ); it.current(); ++it ) lst.append( it.current() ); } +/*!\retval ViewManagerList - const list of all view managers.*/ ViewManagerList STD_Application::viewManagers() const { ViewManagerList lst; @@ -487,11 +557,13 @@ ViewManagerList STD_Application::viewManagers() const return lst; } +/*!\retval SUIT_ViewManager - return pointer to active view manager.*/ SUIT_ViewManager* STD_Application::activeViewManager() const { return myActiveViewMgr; } +/*!Add view manager to view managers list, if it not already there.*/ void STD_Application::addViewManager( SUIT_ViewManager* vm ) { if ( !vm ) @@ -512,6 +584,7 @@ void STD_Application::addViewManager( SUIT_ViewManager* vm ) */ } +/*!Remove view manager from view managers list.*/ void STD_Application::removeViewManager( SUIT_ViewManager* vm ) { if ( !vm ) @@ -529,6 +602,7 @@ void STD_Application::removeViewManager( SUIT_ViewManager* vm ) myActiveViewMgr = 0; } +/*!Remove all view managers from view managers list.*/ void STD_Application::clearViewManagers() { ViewManagerList lst; @@ -538,16 +612,19 @@ void STD_Application::clearViewManagers() removeViewManager( it.current() ); } +/*!\retval TRUE, if view manager \a vm, already in view manager list (\a myViewMgrs).*/ bool STD_Application::containsViewManager( SUIT_ViewManager* vm ) const { return myViewMgrs.contains( vm ) > 0; } +/*!Private slot, sets active manager to \vm, if \vm in view managers list.*/ void STD_Application::onViewManagerActivated( SUIT_ViewManager* vm ) { setActiveViewManager( vm ); } +/*!Sets status bar show, if \on = true, else status bar hide.*/ void STD_Application::onViewStatusBar( bool on ) { if ( on ) @@ -556,11 +633,15 @@ void STD_Application::onViewStatusBar( bool on ) desktop()->statusBar()->hide(); } +/*!Call SUIT_MessageBox::info1(...) with about information.*/ void STD_Application::onHelpAbout() { SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" ); } +/*!Create empty study. \n + * Create new view manager and adding it to view managers list. + */ void STD_Application::createEmptyStudy() { SUIT_Application::createEmptyStudy(); @@ -570,6 +651,7 @@ void STD_Application::createEmptyStudy() addViewManager( vm ); } +/*!Sets active manager to \vm, if \vm in view managers list.*/ void STD_Application::setActiveViewManager( SUIT_ViewManager* vm ) { if ( !containsViewManager( vm ) ) @@ -579,6 +661,7 @@ void STD_Application::setActiveViewManager( SUIT_ViewManager* vm ) emit viewManagerActivated( vm ); } +/*!Public slot. */ void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextMenuEvent* e ) { QtxPopupMenu* popup = new QtxPopupMenu(); @@ -598,15 +681,15 @@ void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextM delete popup; } +/*!\retval QString - return file name from dialog.*/ QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters, const QString& caption, QWidget* parent ) { if ( !parent ) parent = desktop(); - QStringList fls = QStringList::split( ";", filters, false ); if ( open ) { - return QFileDialog::getOpenFileName( initial, fls.join( ";;" ), parent, 0, caption ); + return QFileDialog::getOpenFileName( initial, filters, parent, 0, caption ); } else { @@ -618,7 +701,7 @@ QString STD_Application::getFileName( bool open, const QString& initial, const Q while ( !isOk ) { // It is preferrable to use OS-specific file dialog box here !!! - aName = QFileDialog::getSaveFileName( anOldPath, fls.join( ";;" ), parent, + aName = QFileDialog::getSaveFileName( anOldPath, filters, parent, 0, caption, &aUsedFilter); if ( aName.isNull() ) @@ -659,3 +742,22 @@ QString STD_Application::getFileName( bool open, const QString& initial, const Q return aName; } } + +/*!\retval QString - return directory name from dialog.*/ +QString STD_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent ) +{ + if ( !parent ) + parent = desktop(); + return QFileDialog::getExistingDirectory( initial, parent, 0, caption, true ); +} + +void STD_Application::setDesktop( SUIT_Desktop* desk ) +{ + SUIT_Desktop* prev = desktop(); + + SUIT_Application::setDesktop( desk ); + + if ( prev != desk && desk ) + connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ), + this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) ); +}