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