Salome HOME
Implementation of the "0021709: [CEA 583] Toolbar preferences" issue.
[modules/paravis.git] / src / PVGUI / PVGUI_Module_widgets.cxx
1 // PARAVIS : ParaView wrapper SALOME module
2 //
3 // Copyright (C) 2010-2013  CEA/DEN, EDF R&D
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 // File   : PVGUI_Module_MenuActions.cxx
22 // Author : Margarita KARPUNINA
23 //
24
25 #include "PVGUI_Module.h"
26
27 #include <QtxActionToolMgr.h>
28 #include <LightApp_Application.h>
29 #include <SalomeApp_Application.h>
30 #include <SUIT_Desktop.h>
31
32 #include <QApplication>
33 #include <QAction>
34 #include <QDockWidget>
35 #include <QToolBar>
36 #include <QStatusBar>
37 #include <QShortcut>
38 #include <QScrollArea>
39 #include <QVBoxLayout>
40 #include <QShowEvent>
41 #include <QToolButton>
42
43 #include <pqAnimationViewWidget.h> 
44 #include <pqAnimationWidget.h> 
45
46 #include <pqApplicationCore.h>
47 #include <pqComparativeVisPanel.h>
48 #include <pqPipelineBrowserWidget.h>
49 //#include <pqProxyTabWidget.h>
50 #include <pqProxyInformationWidget.h>
51 #include <pqSettings.h>
52 #include <pqDataInformationWidget.h>
53 #include <pqPVAnimationWidget.h>
54 #include <pqSelectionInspectorWidget.h>
55 #include <pqProgressWidget.h>
56 #include <pqProgressManager.h>
57
58 #include <pqAlwaysConnectedBehavior.h>
59 #include <pqApplicationCore.h>
60 #include <pqAutoLoadPluginXMLBehavior.h>
61 #include <pqCommandLineOptionsBehavior.h>
62 #include <pqCrashRecoveryBehavior.h>
63 #include <pqDataTimeStepBehavior.h>
64 #include <pqDefaultViewBehavior.h>
65 #include <pqDeleteBehavior.h>
66 #include <pqPersistentMainWindowStateBehavior.h>
67 #include <pqPluginActionGroupBehavior.h>
68 #include <pqPluginDockWidgetsBehavior.h>
69 #include <pqPluginManager.h>
70 #include <pqPVNewSourceBehavior.h>
71 #include <pqSpreadSheetVisibilityBehavior.h>
72 #include <pqStandardViewModules.h>
73 #include <pqUndoRedoBehavior.h>
74 #include <pqViewFrameActionsBehavior.h>
75 #include <pqParaViewMenuBuilders.h>
76 #include <pqCollaborationPanel.h>
77 #include <pqMemoryInspectorPanel.h>
78 #include <pqPropertiesPanel.h>
79
80 class ResizeHelper : public pqPVAnimationWidget
81 {
82   // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG:
83   // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
84   // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
85   // THIS BUG IS NATURALLY FIXED BY ADDING 
86   //      this->updateGeometries();
87   // TO THE
88   //     void pqAnimationWidget::resizeEvent(QResizeEvent* e);
89   // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
90   // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
91
92 public:
93   ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
94 protected:
95   void resizeEvent(QResizeEvent* e)
96   {
97     pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
98     if ( w ) { 
99       QShowEvent e;
100       QApplication::sendEvent( w, &e );
101     }
102     pqPVAnimationWidget::resizeEvent( e );
103   }
104 };
105
106 /*!
107   \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
108   ParaView pqMainWIndowCore class is fully responsible for these dock widgets' contents.
109 */
110 void PVGUI_Module::setupDockWidgets()
111 {
112   SUIT_Desktop* desk = application()->desktop();
113  
114   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
115   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
116
117   // Pipeline
118   QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
119   pipelineBrowserDock->setObjectName("pipelineBrowserDock");
120   pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
121   desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
122   pqPipelineBrowserWidget* browser = new pqPipelineBrowserWidget(pipelineBrowserDock);
123   pqParaViewMenuBuilders::buildPipelineBrowserContextMenu(*browser);
124   pipelineBrowserDock->setWidget(browser);
125   myDockWidgets[pipelineBrowserDock] = true;
126
127   // Properties dock
128   QDockWidget* propertiesDock = new QDockWidget(tr( "TTL_OBJECT_INSPECTOR" ), desk);
129   propertiesDock->setObjectName("propertiesDock");
130   pqPropertiesPanel* propertiesPanel = new pqPropertiesPanel();
131   propertiesPanel->setObjectName("propertiesPanel");
132   propertiesDock->setWidget(propertiesPanel);
133   desk->addDockWidget(Qt::LeftDockWidgetArea, propertiesDock);
134   connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ),  this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
135   myDockWidgets[propertiesDock] = true;
136
137   // information dock
138   QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
139   informationDock->setObjectName("informationDock");
140
141   QWidget* informationWidgetFrame = new QWidget(informationDock);
142   informationWidgetFrame->setObjectName("informationWidgetFrame");
143   
144   QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
145   verticalLayout_2->setSpacing(0);
146   verticalLayout_2->setContentsMargins(0, 0, 0, 0);
147
148   QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
149   informationScrollArea->setObjectName("informationScrollArea") ;
150   informationScrollArea->setWidgetResizable(true);
151
152   pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
153   informationWidget->setObjectName("informationWidget");
154   informationWidget->setGeometry(QRect(0, 0, 77, 214));
155   informationScrollArea->setWidget(informationWidget);
156
157   verticalLayout_2->addWidget(informationScrollArea);
158   informationDock->setWidget(informationWidgetFrame);
159
160   desk->addDockWidget(Qt::LeftDockWidgetArea, informationDock);
161   myDockWidgets[informationDock] = true;
162
163   // put 'Properties' and 'Information' widgets into tabs
164   desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
165   desk->tabifyDockWidget(propertiesDock, informationDock);
166   propertiesDock->raise();
167
168   // Statistic View
169   QDockWidget* statisticsViewDock  = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
170   statisticsViewDock->setObjectName("statisticsViewDock");
171   statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
172                                       Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
173   desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
174   pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
175   statisticsViewDock->setWidget(aStatWidget);
176   myDockWidgets[statisticsViewDock] = false; // hidden by default
177
178   //Animation view
179   QDockWidget* animationViewDock     = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
180   animationViewDock->setObjectName("animationViewDock");
181   desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
182   pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget
183   animationViewDock->setWidget(animation_panel);
184   myDockWidgets[animationViewDock] = false; // hidden by default
185
186   desk->tabifyDockWidget(animationViewDock,  statisticsViewDock);
187
188   // Selection view
189   QDockWidget* selectionInspectorDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
190   selectionInspectorDock->setObjectName("selectionInspectorDock");
191   selectionInspectorDock->setAllowedAreas( Qt::AllDockWidgetAreas );
192   desk->addDockWidget( Qt::LeftDockWidgetArea, selectionInspectorDock );
193   pqSelectionInspectorPanel* aSelInspector = new pqSelectionInspectorWidget(selectionInspectorDock);
194   selectionInspectorDock->setWidget(aSelInspector);
195   myDockWidgets[selectionInspectorDock] = false; // hidden by default
196
197   // Comparative View
198   QDockWidget* comparativePanelDock  = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
199   comparativePanelDock->setObjectName("comparativePanelDock");
200   desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
201   pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
202   comparativePanelDock->setWidget(cv_panel);
203   myDockWidgets[comparativePanelDock] = false; // hidden by default
204
205   // Collaboration view
206   QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
207   collaborationPanelDock->setObjectName("collaborationPanelDock");
208   pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
209   collaborationPanel->setObjectName("collaborationPanel");
210   collaborationPanelDock->setWidget(collaborationPanel);
211   desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
212   myDockWidgets[collaborationPanelDock] = false; // hidden by default
213   
214   // Memory inspector dock
215   QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
216   memoryInspectorDock->setObjectName("memoryInspectorDock");
217   pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
218   dockWidgetContents->setObjectName("dockWidgetContents");
219   memoryInspectorDock->setWidget(dockWidgetContents);
220   desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
221   myDockWidgets[memoryInspectorDock] = false; // hidden by default
222
223   // Setup the statusbar ...
224   pqProgressManager* progress_manager =
225     pqApplicationCore::instance()->getProgressManager();
226
227   // Progress bar/button management
228   pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
229   progress_manager->addNonBlockableObject(aProgress);
230   progress_manager->addNonBlockableObject(aProgress->getAbortButton());
231   
232   QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
233                     aProgress,        SLOT(enableProgress(bool)));
234
235   QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
236                     aProgress,        SLOT(setProgress(const QString&, int)));
237
238   QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
239                     aProgress,        SLOT(enableAbort(bool)));
240
241   QObject::connect( aProgress,        SIGNAL(abortPressed()),
242                     progress_manager, SLOT(triggerAbort()));
243
244   desk->statusBar()->addPermanentWidget(aProgress);
245   aProgress->setEnabled(true);
246
247   // Set up the dock window corners to give the vertical docks more room.
248   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
249   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
250   
251   // Setup the default dock configuration ...
252   statisticsViewDock->hide();
253   comparativePanelDock->hide();
254   animationViewDock->hide();
255   selectionInspectorDock->hide();
256   collaborationPanelDock->hide();
257   memoryInspectorDock->hide();
258 }
259
260 /*!
261   \brief Save states of dockable ParaView widgets.
262 */
263 void PVGUI_Module::saveDockWidgetsState()
264 {
265   SUIT_Desktop* desk = application()->desktop();
266
267   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
268   // ... the following code is commented...
269   // Save the state of the window ...
270   // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
271   //
272   //for (int i = 0; i < myDockWidgets.size(); ++i)
273   //  myDockWidgets.at(i)->setParent(0);
274   // ... and replaced - manually hide dock windows
275
276   // store dock widgets visibility state and hide'em all
277   QMapIterator<QWidget*, bool> it1( myDockWidgets );
278   while( it1.hasNext() ) {
279     it1.next();
280     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
281     myDockWidgets[dw] = dw->isVisible();
282     dw->setVisible( false );
283     dw->toggleViewAction()->setVisible( false );
284   }
285   // store toolbar breaks state and remove all tollbar breaks 
286   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
287   while( it2.hasNext() ) {
288     it2.next();
289     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
290     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
291     if ( myToolbarBreaks[tb] )
292       desk->removeToolBarBreak( tb );
293   }
294   // store toolbars visibility state and hide'em all
295   QMapIterator<QWidget*, bool> it3( myToolbars );
296   while( it3.hasNext() ) {
297     it3.next();
298     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
299     myToolbars[tb] = tb->isVisible();
300     tb->setVisible( false );
301     tb->toggleViewAction()->setVisible( false );
302   }
303 }
304
305 /*!
306   \brief Restore states of dockable ParaView widgets.
307 */
308 void PVGUI_Module::restoreDockWidgetsState()
309 {
310   SUIT_Desktop* desk = application()->desktop();
311
312   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
313   // ... the following code is commented...
314   //for (int i = 0; i < myDockWidgets.size(); ++i)
315   //  myDockWidgets.at(i)->setParent(desk);
316   //
317   // Restore the state of the window ...
318   //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
319   // ... and replaced - manually hide dock windows
320
321   // restore dock widgets visibility state
322   QMapIterator<QWidget*, bool> it1( myDockWidgets );
323   while( it1.hasNext() ) {
324     it1.next();
325     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
326     dw->setVisible( it1.value() );
327     dw->toggleViewAction()->setVisible( true );
328   }
329   // restore toolbar breaks state
330   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
331   while( it2.hasNext() ) {
332     it2.next();
333     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
334     if ( myToolbarBreaks[tb] )
335       desk->insertToolBarBreak( tb );
336   }
337   // restore toolbar visibility state
338   QMapIterator<QWidget*, bool> it3( myToolbars );
339   while( it3.hasNext() ) {
340     it3.next();
341     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
342     tb->setVisible( it3.value() );
343     tb->toggleViewAction()->setVisible( true );
344   }
345 }
346
347
348
349 /*!
350   \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
351 */
352 void PVGUI_Module::storeCommonWindowsState() {  
353   //rnv: Make behaviour of the dockable windows and toolbars coherent with others
354   //     modules: if 'Save position of the windows' or 'Save position of the toolbars' 
355   //     in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
356   //     are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
357   //     Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
358   //     configuration file.
359   //
360   //     But in contrast to others modules ParaVis module default settings hide some dockable
361   //     windows, so to restore it at the moment of the ParaVis de-activation we call 
362   //     restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call 
363   //     this method.
364
365   SalomeApp_Application* anApp = getApp();
366   if(!anApp)
367     return;
368
369   int begin = SalomeApp_Application::WT_ObjectBrowser;
370   int end = SalomeApp_Application::WT_NoteBook;
371   for( int i = begin; i <= end; i++ ) {
372     QWidget* wg = anApp->getWindow(i);
373     if(wg) {
374       QDockWidget* dock = 0;
375       QWidget* w = wg->parentWidget();
376       while ( w && !dock ) {
377         dock = ::qobject_cast<QDockWidget*>( w );
378         w = w->parentWidget();
379       }
380       if(dock){
381         if(!myCommonMap.contains(i)){
382           myCommonMap.insert(i,dock->isVisible());
383         } else {
384           myCommonMap[i] = dock->isVisible();
385         }
386       }
387     }
388   }
389 }
390
391 /*!
392   \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
393 */
394 void PVGUI_Module::restoreCommonWindowsState() {
395   SalomeApp_Application* anApp = getApp();
396   if(!anApp)
397     return;
398   DockWindowMap::const_iterator it = myCommonMap.begin();
399   for( ;it != myCommonMap.end(); it++ ) {
400     QWidget* wg = anApp->getWindow(it.key());
401     if(wg) {
402       QDockWidget* dock = 0;
403       QWidget* w = wg->parentWidget();
404       while ( w && !dock ) {
405         dock = ::qobject_cast<QDockWidget*>( w );
406         w = w->parentWidget();
407       }
408       if(dock) {
409         dock->setVisible(it.value());
410       }
411     }
412   }
413 }