Salome HOME
0023105: [CEA 1535] Be able to active stereo in VTK view and to choose which kind...
[modules/gui.git] / src / LightApp / LightApp_FullScreenHelper.cxx
1 // Copyright (C) 2007-2015  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 #include "LightApp_FullScreenHelper.h"
44 #include "LightApp_Application.h"
45
46
47 /*!
48  * Constructor
49  */
50 LightApp_FullScreenHelper::LightApp_FullScreenHelper() 
51 {
52   myStatusBarVisibility = false;
53 }
54
55 /*!
56  * Destructor
57  */
58 LightApp_FullScreenHelper::~LightApp_FullScreenHelper()
59 {
60   
61 }
62
63
64 /*!
65  * Switch application to the full screen mode.
66  */
67 void LightApp_FullScreenHelper::switchToFullScreen() {
68   
69   SUIT_Session* session = SUIT_Session::session();
70   if(!session)
71     return;
72   
73   LightApp_Application* app = dynamic_cast<LightApp_Application*>( session->activeApplication() );
74
75   if(!app)
76     return;
77   
78   SUIT_Desktop* desktop = app->desktop();
79
80   if(!desktop)
81     return;
82   
83   STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop );
84
85   QtxWorkstack* wgStack = desk->workstack();
86   wgStack->showActiveTabBar(false);
87   myWindowsList.clear();
88   bool isHidding = false;
89   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
90   if ( resMgr )
91     isHidding = resMgr->booleanValue( "OCCViewer", "automatic_hiding", true );
92   //Hide all toolbars and inactive window
93   QList<SUIT_ViewWindow*> aWindowList = desk->windows();
94   SUIT_ViewWindow* anActiveWindow = desk->activeWindow();
95   QList<SUIT_ViewWindow*>::const_iterator it = aWindowList.begin();
96   for ( ; it!=aWindowList.end(); it++ ) {
97     QList<QToolBar*> lst = (*it)->findChildren<QToolBar*>();
98     if ( *it ) {
99       myWindowsList.push_back(*it);
100       ( *it )->hide();
101     }
102     if ( isHidding ) {
103       QList<QToolBar*>::const_iterator iter = lst.begin();
104       for ( ; iter!=lst.end(); iter++ ) {
105         (*iter)->hide();
106       }
107     }
108   }
109   if (anActiveWindow)
110     anActiveWindow->show();
111
112   desktop->setWindowState(desktop->windowState() ^ Qt::WindowFullScreen);
113
114   if(desktop->menuBar())
115     desktop->menuBar()->hide();
116
117   if(desktop->statusBar()) {
118     myStatusBarVisibility = desktop->statusBar()->isVisible();
119     desktop->statusBar()->hide();
120     QAction *act = app->action(STD_Application::ViewStatusBarId);
121     if(act)
122       act->setEnabled(false);
123   }
124
125
126   QList<QDockWidget*> aDocWidgets = desktop->findChildren<QDockWidget*>();
127   myDocWidgetMap.clear();
128
129   QWidget* ob = app->objectBrowser();
130   QObject* obParent = (ob && !isHidding)? ob->parent() : 0;
131
132   foreach(QDockWidget* aWidget, aDocWidgets) {
133     if(aWidget && aWidget->parent() == desktop) {
134       if( aWidget->isVisible() && aWidget != obParent ) {
135         aWidget->hide();
136         QAction* act = aWidget->toggleViewAction();
137         bool isActionEnabled = false;
138         if(act) {
139           isActionEnabled = act->isEnabled();
140           if( isActionEnabled ) {
141             act->setEnabled(false);
142           }
143         }
144         
145         myDocWidgetMap.insert(aWidget, isActionEnabled);
146       }
147     }    
148   }
149   
150   QList<QToolBar*> aToolBars = desktop->findChildren<QToolBar*>();
151   myToolBarMap.clear();
152   foreach(QToolBar* aWidget, aToolBars )  {
153     if( aWidget && aWidget->parent() == desktop ) {
154       if( aWidget->isVisible()) {
155         aWidget->hide();
156         QAction* act = aWidget->toggleViewAction();
157         bool isActionEnabled = false;
158         if(act) {
159           isActionEnabled = act->isEnabled();
160           if( isActionEnabled ) {
161             act->setEnabled(false);
162           }
163         }       
164         myToolBarMap.insert(aWidget, isActionEnabled);
165       }
166     }    
167   }  
168 }
169
170 /*!
171  * Switch application to the normal screen mode.
172  */
173 void LightApp_FullScreenHelper::switchToNormalScreen() {
174
175   SUIT_Session* session = SUIT_Session::session();
176   if(!session)
177     return;
178   
179   LightApp_Application* app = dynamic_cast<LightApp_Application*>( session->activeApplication() );
180
181   if(!app)
182     return;
183   
184   SUIT_Desktop* desktop = app->desktop();
185
186   if(!desktop)
187     return;
188   
189   desktop->setWindowState(desktop->windowState() ^ Qt::WindowFullScreen);
190
191   STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop );
192
193   QtxWorkstack* wgStack = desk->workstack();
194   wgStack->showActiveTabBar(true);
195
196   bool isHidding = false;
197   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
198   if ( resMgr )
199     isHidding = resMgr->booleanValue( "OCCViewer", "automatic_hiding", true );
200   //Show all toolbars and windows
201   QList<SUIT_ViewWindow*>::const_iterator itr = myWindowsList.begin();
202   for ( ; itr!=myWindowsList.end(); itr++ ) {
203     QList<QToolBar*> lst = (*itr)->findChildren<QToolBar*>();
204     if (*itr && !(*itr)->isVisible())
205       (*itr)->show();
206     if ( isHidding ) {
207       QList<QToolBar*>::const_iterator iter = lst.begin();
208       for ( ; iter!=lst.end(); iter++ ) {
209         (*iter)->show();
210       }
211     }
212   }
213
214   DocWidgetMap::iterator it = myDocWidgetMap.begin();
215   for( ;it != myDocWidgetMap.end() ; it++ ) {
216     QDockWidget* aWidget = it.key();
217     bool state = it.value();
218     aWidget->show();
219     QAction* act = aWidget->toggleViewAction();
220     if(act && state)
221       act->setEnabled(true);
222   }
223
224   ToolBarMap::iterator it1 = myToolBarMap.begin();
225   for( ;it1 != myToolBarMap.end() ; it1++ ) {
226     QToolBar* aWidget = it1.key();
227     bool state = it1.value();
228     aWidget->show();
229     QAction* act = aWidget->toggleViewAction();
230     if(act && state)
231       act->setEnabled(true);
232   }
233
234   if(desktop->menuBar())
235     desktop->menuBar()->show();
236
237   if(desktop->statusBar() && myStatusBarVisibility) {
238     desktop->statusBar()->show();
239     QAction *act = app->action(STD_Application::ViewStatusBarId);
240     if(act)
241       act->setEnabled(true);
242   }
243   
244 }