Back to index

salome-gui  6.5.0
QtxWorkspace.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File:      QtxWorkspace.cxx
00021 // Author:    Sergey TELKOV
00022 //
00023 #include "QtxWorkspace.h"
00024 
00025 #include <QWidgetList>
00026 
00040 QtxWorkspace::QtxWorkspace( QWidget* parent )
00041 : QWorkspace( parent )
00042 {
00043 }
00044 
00048 QtxWorkspace::~QtxWorkspace()
00049 {
00050 }
00051 
00055 void QtxWorkspace::tileVertical()
00056 {
00057   QWidgetList winList = windowList();
00058   if ( winList.isEmpty() )
00059     return;
00060   
00061   int count = 0;
00062   for ( QWidgetList::const_iterator itr = winList.begin(); itr != winList.end(); ++itr )
00063     if ( !( (*itr)->windowState() & Qt::WindowMinimized ) )
00064       count++;
00065 
00066   if ( !count )
00067     return;
00068 
00069   if ( activeWindow() && ( activeWindow()->windowState() & Qt::WindowMaximized ) )
00070     activeWindow()->showNormal();
00071 
00072   int y = 0;
00073   int heightForEach = height() / count;
00074   for ( QWidgetList::iterator it = winList.begin(); it != winList.end(); ++it )
00075   {
00076     QWidget* win = *it;
00077     if ( win->windowState() & Qt::WindowMinimized )
00078       continue;
00079     
00080     if ( win->windowState() & Qt::WindowMaximized )
00081     {
00082       win->hide();
00083       win->showNormal();
00084     }
00085     
00086 //    QApplication::sendPostedEvents( 0, QEvent::ShowNormal );
00087 
00088     int prefH = win->minimumHeight() + win->parentWidget()->baseSize().height();
00089     int actualH = qMax( heightForEach, prefH );
00090 
00091     win->parentWidget()->setGeometry( 0, y, width(), actualH );
00092     y += actualH;
00093   }
00094 }
00095 
00099 void QtxWorkspace::tileHorizontal()
00100 {
00101   QWidgetList winList = windowList();
00102   if ( winList.isEmpty() )
00103     return;
00104 
00105   int count = 0;
00106   for ( QWidgetList::const_iterator itr = winList.begin(); itr != winList.end(); ++itr )
00107     if ( !( (*itr)->windowState() & Qt::WindowMinimized ) )
00108       count++;
00109 
00110   if ( !count )
00111     return;
00112 
00113   if ( activeWindow() && activeWindow()->windowState() & Qt::WindowMaximized )
00114     activeWindow()->showNormal();
00115   
00116   int x = 0;
00117   int widthForEach = width() / count;
00118   for ( QWidgetList::iterator it = winList.begin(); it != winList.end(); ++it )
00119   {
00120     QWidget* win = *it;
00121     if ( win->windowState() & Qt::WindowMinimized )
00122       continue;
00123     
00124     if ( win->windowState() & Qt::WindowMaximized )
00125     {
00126       win->hide();
00127       win->showNormal();
00128     }
00129 
00130 //    QApplication::sendPostedEvents( 0, QEvent::ShowNormal );
00131 
00132     int prefW = win->minimumWidth();
00133     int actualW = qMax( widthForEach, prefW );
00134     
00135     win->parentWidget()->setGeometry( x, 0, actualW, height() );
00136     x += actualW;
00137   }
00138 }