]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Restore windows state by default and from preferences file. V5_1_0_CTH_V14
authoradv <adv@opencascade.com>
Fri, 23 Mar 2012 12:58:47 +0000 (12:58 +0000)
committeradv <adv@opencascade.com>
Fri, 23 Mar 2012 12:58:47 +0000 (12:58 +0000)
src/LightApp/LightApp_Application.cxx
src/LightApp/LightApp_Application.h
src/LightApp/LightApp_Module.cxx
src/LightApp/LightApp_Module.h
src/LightApp/resources/LightApp_msg_en.ts
src/LightApp/resources/LightApp_msg_fr.ts

index f53fa4f3a197ab668d655de95d752c62836733bb..dce1076b2f82e59b64a2a624d0e84bbe82ddedb2 100644 (file)
@@ -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<int, int> 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<int, int>::const_iterator winMapIt = winMap.constBegin();
+    for ( ; winMapIt != winMap.constEnd(); ++winMapIt )
+    {
+      QWidget* win = dockWindow( winMapIt.key() );
+      QDockWidget* dock = ::qobject_cast<QDockWidget*>( 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<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
+    for ( QList<QToolBar*>::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
index 3fe5d6ced2b3e51fec03fb9964b5260edc466dd7..3815ec437f7c19795e74241289f982f311972525 100644 (file)
@@ -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* );
index 332e4a70ace82ecee7d0d4b2e13484c962724d74..c9ce919288d75b9bd1720751c7cf9d7d2d1ce744 100644 (file)
@@ -124,6 +124,12 @@ void LightApp_Module::windows( QMap<int, int>& ) const
 {
 }
 
+/*!NOT IMPLEMENTED*/
+bool LightApp_Module::defaultWindowsState()
+{
+  return false;
+}
+
 /*!NOT IMPLEMENTED*/
 void LightApp_Module::viewManagers( QStringList& ) const
 {
index 95206ec468176a51f54e1176dfa13d8f00760974..b9754724354ae542529ad6861cb838fcc82e6550 100644 (file)
@@ -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* );
index 29985e9eab619ce3f2682d0cdd2c6c39fa17bf28..6cdfcf1942e39e1f5764b204233612210d179b9e 100644 (file)
@@ -533,6 +533,34 @@ CEA/DEN, CEDRAT, EDF R&amp;D, LEG, PRINCIPIA R&amp;D, BUREAU VERITAS</translatio
         <source>PRP_GROUP_ALL</source>
         <translation>Group all windows</translation>
     </message>
+    <message>
+        <source>MEN_DESK_RESTORE</source>
+        <translation>Restore windows &amp;state</translation>
+    </message>
+    <message>
+        <source>TOT_RESTORE_DEFAULT</source>
+        <translation>By Default</translation>
+    </message>
+    <message>
+        <source>MEN_DESK_RESTORE_DEFAULT</source>
+        <translation>&amp;By Default</translation>
+    </message>
+    <message>
+        <source>PRP_RESTORE_DEFAULT</source>
+        <translation>Restore windows state by default</translation>
+    </message>
+    <message>
+        <source>TOT_RESTORE_FROM_PREFERENCES</source>
+        <translation>From Preferences</translation>
+    </message>
+    <message>
+        <source>MEN_DESK_RESTORE_FROM_PREFERENCES</source>
+        <translation>&amp;From Preferences</translation>
+    </message>
+    <message>
+        <source>PRP_RESTORE_FROM_PREFERENCES</source>
+        <translation>Restore windows state from preferences file</translation>
+    </message>
     <message>
         <source>ERR_DOC_NOT_EXISTS</source>
         <translation>Can not open %1.
index b88a546b772ea7edc3f37437a2b0db926d34d725..e167be16e99fa377ec17c709725ae3ceab18c2b9 100755 (executable)
@@ -533,6 +533,34 @@ CEA/DEN, CEDRAT, EDF R&amp;D, LEG, PRINCIPIA R&amp;D, BUREAU VERITAS</translatio
         <source>PRP_GROUP_ALL</source>
         <translation type="unfinished">Grouper toutes les fenêtres</translation>
     </message>
+    <message>
+        <source>MEN_DESK_RESTORE</source>
+        <translation>Redimensionner les fenêtres</translation>
+    </message>
+    <message>
+        <source>TOT_RESTORE_DEFAULT</source>
+        <translation>Par défaut</translation>
+    </message>
+    <message>
+        <source>MEN_DESK_RESTORE_DEFAULT</source>
+        <translation>&amp;Défaut</translation>
+    </message>
+    <message>
+        <source>PRP_RESTORE_DEFAULT</source>
+        <translation>Redimensionner les fenêtres par défaut.</translation>
+    </message>
+    <message>
+        <source>TOT_RESTORE_FROM_PREFERENCES</source>
+        <translation>Selon les préférences</translation>
+    </message>
+    <message>
+        <source>MEN_DESK_RESTORE_FROM_PREFERENCES</source>
+        <translation>&amp;Préférences</translation>
+    </message>
+    <message>
+        <source>PRP_RESTORE_FROM_PREFERENCES</source>
+        <translation> Redimensionner les fenêtres selon le fichier de préférences.</translation>
+    </message>
     <message>
         <source>ERR_DOC_NOT_EXISTS</source>
         <translation type="unfinished">Impossible d&apos;ouvrir %1.