Salome HOME
updated copyright message
[modules/gui.git] / src / LightApp / LightApp_FullScreenHelper.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:      LightApp_FullScreenHelper.h
24 // Created:   04/10/2011 18:44:25 PM
25 // Author:    OCC team
26 //
27 #include <QAction>
28 #include <QMenuBar>
29 #include <QStatusBar>
30 #include <QToolBar>
31
32 #include <QtxWorkstack.h>
33
34 #include <STD_Application.h>
35 #include <STD_TabDesktop.h>
36
37 #include <SUIT_Session.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_DataBrowser.h>
40 #include <SUIT_ViewWindow.h>
41 #include <SUIT_ResourceMgr.h>
42
43 #ifndef DISABLE_OCCVIEWER
44   #include <OCCViewer_ViewFrame.h>
45 #endif
46
47 #include "LightApp_FullScreenHelper.h"
48 #include "LightApp_Application.h"
49
50
51 /*!
52  * Constructor
53  */
54 LightApp_FullScreenHelper::LightApp_FullScreenHelper() 
55 {
56   myStatusBarVisibility = false;
57 }
58
59 /*!
60  * Destructor
61  */
62 LightApp_FullScreenHelper::~LightApp_FullScreenHelper()
63 {
64   
65 }
66
67
68 /*!
69  * Switch application to the full screen mode.
70  */
71 void LightApp_FullScreenHelper::switchToFullScreen() {
72   
73   SUIT_Session* session = SUIT_Session::session();
74   if(!session)
75     return;
76   
77   LightApp_Application* app = dynamic_cast<LightApp_Application*>( session->activeApplication() );
78
79   if(!app)
80     return;
81   
82   SUIT_Desktop* desktop = app->desktop();
83
84   if(!desktop)
85     return;
86   
87   STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop );
88
89   myWindowsList.clear();
90   myFrameHideMap.clear();
91   //Hide all toolbars and inactive window
92   QList<SUIT_ViewWindow*> aWindowList = desk->windows();
93   SUIT_ViewWindow* anActiveWindow = desk->activeWindow();
94   QList<SUIT_ViewWindow*>::const_iterator it = aWindowList.begin();
95   int aKey = 0;
96   for ( ; it != aWindowList.end(); it++ ) {
97     myWindowsList.push_back(*it);
98   #ifndef DISABLE_OCCVIEWER
99     OCCViewer_ViewFrame* anActiveOCCFrame = dynamic_cast<OCCViewer_ViewFrame*>( *it );
100     if ( anActiveOCCFrame ) {
101       QList<int> aList;
102       if ( (*it) == anActiveWindow ) {
103         OCCViewer_ViewWindow* anActiveOCCWindow = anActiveOCCFrame->getActiveView();
104         for (int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
105           OCCViewer_ViewWindow* aCurrentOCCWindow = anActiveOCCFrame->getView(i);
106           if ( aCurrentOCCWindow && aCurrentOCCWindow->isVisible() ) {
107             if ( aCurrentOCCWindow != anActiveOCCWindow ) {
108               aCurrentOCCWindow->hide();
109               toolbarVisible(aCurrentOCCWindow, false);
110             }
111             if ( anActiveOCCWindow )
112               aList.append(i);
113           }
114         }
115       }
116       if ( aList.count() > 0 ) {
117         myFrameHideMap.insert(aKey, aList);
118         aKey++;
119       }
120     }
121   #endif
122     toolbarVisible(*it, false);
123   }
124
125   QtxWorkstack* wgStack = desk->workstack();
126   wgStack->splittersVisible(anActiveWindow, false);
127
128   desktop->setWindowState(desktop->windowState() ^ Qt::WindowFullScreen);
129
130   if(desktop->menuBar())
131     desktop->menuBar()->hide();
132
133   if(desktop->statusBar()) {
134     myStatusBarVisibility = desktop->statusBar()->isVisible();
135     desktop->statusBar()->hide();
136     QAction *act = app->action(STD_Application::ViewStatusBarId);
137     if(act)
138       act->setEnabled(false);
139   }
140
141
142   QList<QDockWidget*> aDocWidgets = desktop->findChildren<QDockWidget*>();
143   myDocWidgetMap.clear();
144
145   bool isHidding = false;
146   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
147     if ( resMgr )
148       isHidding = resMgr->booleanValue( "OCCViewer", "automatic_hiding", true );
149
150   QWidget* ob = app->objectBrowser();
151   QObject* obParent = (ob && !isHidding)? ob->parent() : 0;
152
153   foreach(QDockWidget* aWidget, aDocWidgets) {
154     if(aWidget && aWidget->parent() == desktop) {
155       if( aWidget->isVisible() && aWidget != obParent ) {
156         aWidget->hide();
157         QAction* act = aWidget->toggleViewAction();
158         bool isActionEnabled = false;
159         if(act) {
160           isActionEnabled = act->isEnabled();
161           if( isActionEnabled ) {
162             act->setEnabled(false);
163           }
164         }
165         
166         myDocWidgetMap.insert(aWidget, isActionEnabled);
167       }
168     }    
169   }
170
171   QList<QToolBar*> aToolBars = desktop->findChildren<QToolBar*>();
172   myToolBarMap.clear();
173   foreach(QToolBar* aWidget, aToolBars )  {
174     if( aWidget && aWidget->parent() == desktop ) {
175       if( aWidget->isVisible()) {
176         aWidget->hide();
177         QAction* act = aWidget->toggleViewAction();
178         bool isActionEnabled = false;
179         if(act) {
180           isActionEnabled = act->isEnabled();
181           if( isActionEnabled ) {
182             act->setEnabled(false);
183           }
184         }       
185         myToolBarMap.insert(aWidget, isActionEnabled);
186       }
187     }    
188   }
189 }
190
191 /*!
192  * Switch application to the normal screen mode.
193  */
194 void LightApp_FullScreenHelper::switchToNormalScreen() {
195
196   SUIT_Session* session = SUIT_Session::session();
197   if(!session)
198     return;
199   
200   LightApp_Application* app = dynamic_cast<LightApp_Application*>( session->activeApplication() );
201
202   if(!app)
203     return;
204   
205   SUIT_Desktop* desktop = app->desktop();
206
207   if(!desktop)
208     return;
209   
210   desktop->setWindowState(desktop->windowState() ^ Qt::WindowFullScreen);
211
212   STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop );
213   SUIT_ViewWindow* anActiveWindow = desk->activeWindow();
214
215   //Show all toolbars and windows
216   QList<SUIT_ViewWindow*>::const_iterator itr = myWindowsList.begin();
217   int aKey = 0;
218   for ( ; itr != myWindowsList.end(); itr++ ) {
219   #ifndef DISABLE_OCCVIEWER
220     OCCViewer_ViewFrame* anActiveOCCFrame = dynamic_cast<OCCViewer_ViewFrame*>( *itr );
221     if ( anActiveOCCFrame ) {
222       if ( (*itr) == anActiveWindow ) {
223         QList<int>::const_iterator it = myFrameHideMap[aKey].begin();
224         for (; it != myFrameHideMap[aKey].end(); it++) {
225           OCCViewer_ViewWindow* aCurrentOCCWindow = anActiveOCCFrame->getView(*it);
226           aCurrentOCCWindow->show();
227           toolbarVisible( aCurrentOCCWindow, true);
228         }
229         aKey++;
230       }
231     }
232   #endif
233     toolbarVisible( *itr, true );
234   }
235
236   QtxWorkstack* wgStack = desk->workstack();
237   wgStack->splittersVisible(anActiveWindow, true);
238
239   DocWidgetMap::iterator it = myDocWidgetMap.begin();
240   for( ;it != myDocWidgetMap.end() ; it++ ) {
241     QDockWidget* aWidget = it.key();
242     bool state = it.value();
243     aWidget->show();
244     QAction* act = aWidget->toggleViewAction();
245     if(act && state)
246       act->setEnabled(true);
247   }
248
249   ToolBarMap::iterator it1 = myToolBarMap.begin();
250   for( ;it1 != myToolBarMap.end() ; it1++ ) {
251     QToolBar* aWidget = it1.key();
252     bool state = it1.value();
253     aWidget->show();
254     QAction* act = aWidget->toggleViewAction();
255     if(act && state)
256       act->setEnabled(true);
257   }
258
259   if(desktop->menuBar())
260     desktop->menuBar()->show();
261
262   if(desktop->statusBar() && myStatusBarVisibility) {
263     desktop->statusBar()->show();
264     QAction *act = app->action(STD_Application::ViewStatusBarId);
265     if(act)
266       act->setEnabled(true);
267   }
268 }
269
270 /*!
271  * Show/Hide toolbars on current view.
272  */
273 void LightApp_FullScreenHelper::toolbarVisible(SUIT_ViewWindow* view, bool toolbar_visible)
274 {
275   bool isHidding = false;
276   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
277   if ( resMgr )
278     isHidding = resMgr->booleanValue( "OCCViewer", "automatic_hiding", true );
279   QList<QToolBar*> lst = view->findChildren<QToolBar*>();
280   if ( isHidding ) {
281     QList<QToolBar*>::const_iterator iter = lst.begin();
282     for ( ; iter!=lst.end(); iter++ ) {
283       if ( *iter ) {
284         (*iter)->setVisible(toolbar_visible);
285       }
286     }
287   }
288 }