From: adv Date: Fri, 23 Mar 2012 12:58:47 +0000 (+0000) Subject: Restore windows state by default and from preferences file. X-Git-Tag: CTH_1_7_3~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FV5_1_0_CTH_V14;p=modules%2Fgui.git Restore windows state by default and from preferences file. --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index f53fa4f3a..dce1076b2 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -585,6 +585,7 @@ void LightApp_Application::createActions() // New window int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 ); int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 ); + int restoreWinMenu = createMenu( tr( "MEN_DESK_RESTORE" ), windowMenu, -1, 0 ); createAction( CloseId, tr( "TOT_CLOSE" ), QIcon(), tr( "MEN_DESK_CLOSE" ), tr( "PRP_CLOSE" ), Qt::SHIFT+Qt::Key_C, desk, false, this, SLOT( onCloseWindow() ) ); @@ -617,6 +618,17 @@ void LightApp_Application::createActions() createActionForViewer( NewGraphicsViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_R ); #endif + createAction( RestoreDefaultId, tr( "TOT_RESTORE_DEFAULT" ), QIcon(), + tr( "MEN_DESK_RESTORE_DEFAULT" ), tr( "PRP_RESTORE_DEFAULT" ), + 0, desk, false, this, SLOT( onRestoreDefault() ) ); + + createAction( RestoreFromPrefsId, tr( "TOT_RESTORE_FROM_PREFERENCES" ), QIcon(), + tr( "MEN_DESK_RESTORE_FROM_PREFERENCES" ), tr( "PRP_RESTORE_FROM_PREFERENCES" ), + 0, desk, false, this, SLOT( onRestoreFromPreferences() ) ); + + createMenu( RestoreDefaultId, restoreWinMenu, -1 ); + createMenu( RestoreFromPrefsId, restoreWinMenu, -1 ); + createAction( RenameId, tr( "TOT_RENAME" ), QIcon(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ), Qt::SHIFT+Qt::Key_R, desk, false, this, SLOT( onRenameWindow() ) ); createMenu( RenameId, windowMenu, -1 ); @@ -853,6 +865,14 @@ void LightApp_Application::updateCommandsStatus() if( a ) a->setEnabled( activeStudy() ); #endif + + a = action( RestoreDefaultId ); + if( a ) + a->setEnabled( activeStudy() ); + + a = action( RestoreFromPrefsId ); + if( a ) + a->setEnabled( activeStudy() ); } /*! @@ -2700,13 +2720,13 @@ void LightApp_Application::updateViewManagers() /*! Loads windows geometry */ -void LightApp_Application::loadDockWindowsState() +void LightApp_Application::loadDockWindowsState( const bool theIsForced ) { if ( !desktop() ) return; bool store = resourceMgr()->booleanValue( "Study", "store_positions", true ); - if( !store ) + if ( !theIsForced && !store ) return; QString modName; @@ -3049,6 +3069,76 @@ void LightApp_Application::onGroupAllWindow() wgStack->stack(); } +/*! + Restore default state of application windows +*/ +void LightApp_Application::onRestoreDefault() +{ + if ( !activeStudy() || !desktop() ) + return; + + QMap winMap; + bool restored = false; + + if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) ) + { + ((LightApp_Module*)activeModule())->windows( winMap ); + restored = ((LightApp_Module*)activeModule())->defaultWindowsState(); + } + + if ( !restored ) + { + if( winMap.isEmpty() ) + defaultWindows( winMap ); + + QMap::const_iterator winMapIt = winMap.constBegin(); + for ( ; winMapIt != winMap.constEnd(); ++winMapIt ) + { + QWidget* win = dockWindow( winMapIt.key() ); + QDockWidget* dock = ::qobject_cast( win ); + if ( !dock ) + dock = windowDock( win ); + + if ( dock ) + { + if ( !dock->isVisible() ) + dock->setVisible( true ); + + if ( dock->isFloating() ) + dock->setFloating( false ); + + desktop()->addDockWidget( (Qt::DockWidgetArea)winMapIt.value(), dock ); + } + } + + QList tbList = qFindChildren( desktop() ); + for ( QList::iterator tit = tbList.begin(); tit != tbList.end(); ++tit ) + { + QToolBar* tb = *tit; + + QObject* po = Qtx::findParent( tb, "QMainWindow" ); + if ( po != desktop() ) + continue; + + if ( !tb->isVisible() ) + tb->setVisible( true ); + + desktop()->addToolBar( Qt::TopToolBarArea, tb ); + } + } +} + +/*! + Restore application windows state from preferences file +*/ +void LightApp_Application::onRestoreFromPreferences() +{ + if ( !activeStudy() || !desktop() ) + return; + + loadDockWindowsState( true ); +} + /*! \return if the library of module exists \param moduleTitle - title of module diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 3fe5d6ced..3815ec437 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -76,6 +76,7 @@ public: enum { RenameId = CAM_Application::UserID, CloseId, CloseAllId, GroupAllId, + RestoreDefaultId, RestoreFromPrefsId, PreferencesId, MRUId, ModulesListId, NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId, NewGraphicsViewId, UserID }; @@ -217,13 +218,15 @@ private slots: void onCloseWindow(); void onCloseAllWindow(); void onGroupAllWindow(); + void onRestoreDefault(); + void onRestoreFromPreferences(); protected: void updateWindows(); void updateViewManagers(); void updateModuleActions(); - void loadDockWindowsState(); + void loadDockWindowsState( const bool theIsForced = false ); void saveDockWindowsState(); virtual void studyOpened( SUIT_Study* ); diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 332e4a70a..c9ce91928 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -124,6 +124,12 @@ void LightApp_Module::windows( QMap& ) const { } +/*!NOT IMPLEMENTED*/ +bool LightApp_Module::defaultWindowsState() +{ + return false; +} + /*!NOT IMPLEMENTED*/ void LightApp_Module::viewManagers( QStringList& ) const { diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h index 95206ec46..b97547243 100644 --- a/src/LightApp/LightApp_Module.h +++ b/src/LightApp/LightApp_Module.h @@ -93,6 +93,9 @@ public: virtual QString updateDesktopTitle( const QString& ); // Custom update desktop title + virtual bool defaultWindowsState(); + // Custom restore the default windows state + public slots: virtual bool activateModule( SUIT_Study* ); virtual bool deactivateModule( SUIT_Study* ); diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index 29985e9ea..6cdfcf194 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -533,6 +533,34 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITASPRP_GROUP_ALL Group all windows + + MEN_DESK_RESTORE + Restore windows &state + + + TOT_RESTORE_DEFAULT + By Default + + + MEN_DESK_RESTORE_DEFAULT + &By Default + + + PRP_RESTORE_DEFAULT + Restore windows state by default + + + TOT_RESTORE_FROM_PREFERENCES + From Preferences + + + MEN_DESK_RESTORE_FROM_PREFERENCES + &From Preferences + + + PRP_RESTORE_FROM_PREFERENCES + Restore windows state from preferences file + ERR_DOC_NOT_EXISTS Can not open %1. diff --git a/src/LightApp/resources/LightApp_msg_fr.ts b/src/LightApp/resources/LightApp_msg_fr.ts index b88a546b7..e167be16e 100755 --- a/src/LightApp/resources/LightApp_msg_fr.ts +++ b/src/LightApp/resources/LightApp_msg_fr.ts @@ -533,6 +533,34 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITASPRP_GROUP_ALL Grouper toutes les fenêtres + + MEN_DESK_RESTORE + Redimensionner les fenêtres + + + TOT_RESTORE_DEFAULT + Par défaut + + + MEN_DESK_RESTORE_DEFAULT + &Défaut + + + PRP_RESTORE_DEFAULT + Redimensionner les fenêtres par défaut. + + + TOT_RESTORE_FROM_PREFERENCES + Selon les préférences + + + MEN_DESK_RESTORE_FROM_PREFERENCES + &Préférences + + + PRP_RESTORE_FROM_PREFERENCES + Redimensionner les fenêtres selon le fichier de préférences. + ERR_DOC_NOT_EXISTS Impossible d'ouvrir %1.