Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/gui.git] / src / LightApp / LightApp_FullScreenHelper.cxx
1 // Copyright (C) 2007-2012  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.
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
31 #include <PyConsole_Console.h>
32
33 #include <STD_Application.h>
34
35 #include <SUIT_Session.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_DataBrowser.h>
38
39 #include "LightApp_FullScreenHelper.h"
40 #include "LightApp_Application.h"
41
42
43 /*!
44  * Constructor
45  */
46 LightApp_FullScreenHelper::LightApp_FullScreenHelper() 
47 {
48   myStatusBarVisibility = false;
49 }
50
51 /*!
52  * Destructor
53  */
54 LightApp_FullScreenHelper::~LightApp_FullScreenHelper()
55 {
56   
57 }
58
59
60 /*!
61  * Switch application to the full screen mode.
62  */
63 void LightApp_FullScreenHelper::switchToFullScreen() {
64   
65   SUIT_Session* session = SUIT_Session::session();
66   if(!session)
67     return;
68   
69   LightApp_Application* app = dynamic_cast<LightApp_Application*>( session->activeApplication() );
70
71   if(!app)
72     return;
73   
74   SUIT_Desktop* desktop = app->desktop();
75
76   if(!desktop)
77     return;
78   
79   desktop->setWindowState(desktop->windowState() ^ Qt::WindowFullScreen);
80
81   if(desktop->menuBar())
82     desktop->menuBar()->hide();
83
84   if(desktop->statusBar()) {
85     myStatusBarVisibility = desktop->statusBar()->isVisible();
86     desktop->statusBar()->hide();
87     QAction *act = app->action(STD_Application::ViewStatusBarId);
88     if(act)
89       act->setEnabled(false);
90   }
91
92
93   QList<QDockWidget*> aDocWidgets = desktop->findChildren<QDockWidget*>();
94   myDocWidgetMap.clear();
95
96   QWidget* ob = app->objectBrowser();
97   QObject* obParent = ob ? ob->parent() : 0;
98
99   foreach(QDockWidget* aWidget, aDocWidgets) {
100     if(aWidget && aWidget->parent() == desktop) {
101       if( aWidget->isVisible() && aWidget != obParent ) {
102         aWidget->hide();
103         QAction* act = aWidget->toggleViewAction();
104         bool isActionEnabled = false;
105         if(act) {
106           isActionEnabled = act->isEnabled();
107           if( isActionEnabled ) {
108             act->setEnabled(false);
109           }
110         }
111         
112         myDocWidgetMap.insert(aWidget, isActionEnabled);
113       }
114     }    
115   }
116   
117   QList<QToolBar*> aToolBars = desktop->findChildren<QToolBar*>();
118   myToolBarMap.clear();
119   foreach(QToolBar* aWidget, aToolBars )  {
120     if( aWidget && aWidget->parent() == desktop ) {
121       if( aWidget->isVisible()) {
122         aWidget->hide();
123         QAction* act = aWidget->toggleViewAction();
124         bool isActionEnabled = false;
125         if(act) {
126           isActionEnabled = act->isEnabled();
127           if( isActionEnabled ) {
128             act->setEnabled(false);
129           }
130         }       
131         myToolBarMap.insert(aWidget, isActionEnabled);
132       }
133     }    
134   }  
135 }
136
137 /*!
138  * Switch application to the normal screen mode.
139  */
140 void LightApp_FullScreenHelper::switchToNormalScreen() {
141
142   SUIT_Session* session = SUIT_Session::session();
143   if(!session)
144     return;
145   
146   LightApp_Application* app = dynamic_cast<LightApp_Application*>( session->activeApplication() );
147
148   if(!app)
149     return;
150   
151   SUIT_Desktop* desktop = app->desktop();
152
153   if(!desktop)
154     return;
155   
156   desktop->setWindowState(desktop->windowState() ^ Qt::WindowFullScreen);
157
158
159   DocWidgetMap::iterator it = myDocWidgetMap.begin();
160   for( ;it != myDocWidgetMap.end() ; it++ ) {
161     QDockWidget* aWidget = it.key();
162     bool state = it.value();
163     aWidget->show();
164     QAction* act = aWidget->toggleViewAction();
165     if(act && state)
166       act->setEnabled(true);
167   }
168
169   ToolBarMap::iterator it1 = myToolBarMap.begin();
170   for( ;it1 != myToolBarMap.end() ; it1++ ) {
171     QToolBar* aWidget = it1.key();
172     bool state = it1.value();
173     aWidget->show();
174     QAction* act = aWidget->toggleViewAction();
175     if(act && state)
176       act->setEnabled(true);
177   }
178
179   if(desktop->menuBar())
180     desktop->menuBar()->show();
181
182   if(desktop->statusBar() && myStatusBarVisibility) {
183     desktop->statusBar()->show();
184     QAction *act = app->action(STD_Application::ViewStatusBarId);
185     if(act)
186       act->setEnabled(true);
187   }
188   
189 }