1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: LightApp_FullScreenHelper.h
24 // Created: 04/10/2011 18:44:25 PM
32 #include <QtxWorkstack.h>
34 #include <STD_Application.h>
35 #include <STD_TabDesktop.h>
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>
43 #ifndef DISABLE_OCCVIEWER
44 #include <OCCViewer_ViewFrame.h>
47 #include "LightApp_FullScreenHelper.h"
48 #include "LightApp_Application.h"
54 LightApp_FullScreenHelper::LightApp_FullScreenHelper()
56 myStatusBarVisibility = false;
62 LightApp_FullScreenHelper::~LightApp_FullScreenHelper()
69 * Switch application to the full screen mode.
71 void LightApp_FullScreenHelper::switchToFullScreen() {
73 SUIT_Session* session = SUIT_Session::session();
77 LightApp_Application* app = dynamic_cast<LightApp_Application*>( session->activeApplication() );
82 SUIT_Desktop* desktop = app->desktop();
87 STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop );
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();
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 ) {
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);
111 if ( anActiveOCCWindow )
116 if ( aList.count() > 0 ) {
117 myFrameHideMap.insert(aKey, aList);
122 toolbarVisible(*it, false);
125 QtxWorkstack* wgStack = desk->workstack();
126 wgStack->splittersVisible(anActiveWindow, false);
128 desktop->setWindowState(desktop->windowState() ^ Qt::WindowFullScreen);
130 if(desktop->menuBar())
131 desktop->menuBar()->hide();
133 if(desktop->statusBar()) {
134 myStatusBarVisibility = desktop->statusBar()->isVisible();
135 desktop->statusBar()->hide();
136 QAction *act = app->action(STD_Application::ViewStatusBarId);
138 act->setEnabled(false);
142 QList<QDockWidget*> aDocWidgets = desktop->findChildren<QDockWidget*>();
143 myDocWidgetMap.clear();
145 bool isHidding = false;
146 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
148 isHidding = resMgr->booleanValue( "OCCViewer", "automatic_hiding", true );
150 QWidget* ob = app->objectBrowser();
151 QObject* obParent = (ob && !isHidding)? ob->parent() : 0;
153 foreach(QDockWidget* aWidget, aDocWidgets) {
154 if(aWidget && aWidget->parent() == desktop) {
155 if( aWidget->isVisible() && aWidget != obParent ) {
157 QAction* act = aWidget->toggleViewAction();
158 bool isActionEnabled = false;
160 isActionEnabled = act->isEnabled();
161 if( isActionEnabled ) {
162 act->setEnabled(false);
166 myDocWidgetMap.insert(aWidget, isActionEnabled);
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()) {
177 QAction* act = aWidget->toggleViewAction();
178 bool isActionEnabled = false;
180 isActionEnabled = act->isEnabled();
181 if( isActionEnabled ) {
182 act->setEnabled(false);
185 myToolBarMap.insert(aWidget, isActionEnabled);
192 * Switch application to the normal screen mode.
194 void LightApp_FullScreenHelper::switchToNormalScreen() {
196 SUIT_Session* session = SUIT_Session::session();
200 LightApp_Application* app = dynamic_cast<LightApp_Application*>( session->activeApplication() );
205 SUIT_Desktop* desktop = app->desktop();
210 desktop->setWindowState(desktop->windowState() ^ Qt::WindowFullScreen);
212 STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop );
213 SUIT_ViewWindow* anActiveWindow = desk->activeWindow();
215 //Show all toolbars and windows
216 QList<SUIT_ViewWindow*>::const_iterator itr = myWindowsList.begin();
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);
233 toolbarVisible( *itr, true );
236 QtxWorkstack* wgStack = desk->workstack();
237 wgStack->splittersVisible(anActiveWindow, true);
239 DocWidgetMap::iterator it = myDocWidgetMap.begin();
240 for( ;it != myDocWidgetMap.end() ; it++ ) {
241 QDockWidget* aWidget = it.key();
242 bool state = it.value();
244 QAction* act = aWidget->toggleViewAction();
246 act->setEnabled(true);
249 ToolBarMap::iterator it1 = myToolBarMap.begin();
250 for( ;it1 != myToolBarMap.end() ; it1++ ) {
251 QToolBar* aWidget = it1.key();
252 bool state = it1.value();
254 QAction* act = aWidget->toggleViewAction();
256 act->setEnabled(true);
259 if(desktop->menuBar())
260 desktop->menuBar()->show();
262 if(desktop->statusBar() && myStatusBarVisibility) {
263 desktop->statusBar()->show();
264 QAction *act = app->action(STD_Application::ViewStatusBarId);
266 act->setEnabled(true);
271 * Show/Hide toolbars on current view.
273 void LightApp_FullScreenHelper::toolbarVisible(SUIT_ViewWindow* view, bool toolbar_visible)
275 bool isHidding = false;
276 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
278 isHidding = resMgr->booleanValue( "OCCViewer", "automatic_hiding", true );
279 QList<QToolBar*> lst = view->findChildren<QToolBar*>();
281 QList<QToolBar*>::const_iterator iter = lst.begin();
282 for ( ; iter!=lst.end(); iter++ ) {
284 (*iter)->setVisible(toolbar_visible);