Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Qtx / QtxWorkspace.cxx
1 //  Copyright (C) 2007-2008  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 // File:      QtxWorkspace.cxx
23 // Author:    Sergey TELKOV
24 //
25 #include "QtxWorkspace.h"
26
27 #include <QWidgetList>
28
29 /*!
30   \class QtxWorkspace
31   \brief A workspace widget which can be used in the MDI application
32          as top-level widget in the application main window.
33
34   Provides methods to tile child windows in horizontal or vertical
35   direction.
36 */
37
38 /*!
39   \brief Constructor.
40   \param parent parent widget
41 */
42 QtxWorkspace::QtxWorkspace( QWidget* parent )
43 : QWorkspace( parent )
44 {
45 }
46
47 /*!
48   \brief Destructor.
49 */
50 QtxWorkspace::~QtxWorkspace()
51 {
52 }
53
54 /*!
55   \brief Tiles child windows vertically.
56 */
57 void QtxWorkspace::tileVertical()
58 {
59   QWidgetList winList = windowList();
60   if ( winList.isEmpty() )
61     return;
62   
63   int count = 0;
64   for ( QWidgetList::const_iterator itr = winList.begin(); itr != winList.end(); ++itr )
65     if ( !( (*itr)->windowState() & Qt::WindowMinimized ) )
66       count++;
67
68   if ( !count )
69     return;
70
71   if ( activeWindow() && ( activeWindow()->windowState() & Qt::WindowMaximized ) )
72     activeWindow()->showNormal();
73
74   int y = 0;
75   int heightForEach = height() / count;
76   for ( QWidgetList::iterator it = winList.begin(); it != winList.end(); ++it )
77   {
78     QWidget* win = *it;
79     if ( win->windowState() & Qt::WindowMinimized )
80       continue;
81     
82     if ( win->windowState() & Qt::WindowMaximized )
83     {
84       win->hide();
85       win->showNormal();
86     }
87     
88 //    QApplication::sendPostedEvents( 0, QEvent::ShowNormal );
89
90     int prefH = win->minimumHeight() + win->parentWidget()->baseSize().height();
91     int actualH = qMax( heightForEach, prefH );
92
93     win->parentWidget()->setGeometry( 0, y, width(), actualH );
94     y += actualH;
95   }
96 }
97
98 /*!
99   \brief Tiles child windows horizontally.
100 */
101 void QtxWorkspace::tileHorizontal()
102 {
103   QWidgetList winList = windowList();
104   if ( winList.isEmpty() )
105     return;
106
107   int count = 0;
108   for ( QWidgetList::const_iterator itr = winList.begin(); itr != winList.end(); ++itr )
109     if ( !( (*itr)->windowState() & Qt::WindowMinimized ) )
110       count++;
111
112   if ( !count )
113     return;
114
115   if ( activeWindow() && activeWindow()->windowState() & Qt::WindowMaximized )
116     activeWindow()->showNormal();
117   
118   int x = 0;
119   int widthForEach = width() / count;
120   for ( QWidgetList::iterator it = winList.begin(); it != winList.end(); ++it )
121   {
122     QWidget* win = *it;
123     if ( win->windowState() & Qt::WindowMinimized )
124       continue;
125     
126     if ( win->windowState() & Qt::WindowMaximized )
127     {
128       win->hide();
129       win->showNormal();
130     }
131
132 //    QApplication::sendPostedEvents( 0, QEvent::ShowNormal );
133
134     int prefW = win->minimumWidth();
135     int actualW = qMax( widthForEach, prefW );
136     
137     win->parentWidget()->setGeometry( x, 0, actualW, height() );
138     x += actualW;
139   }
140 }